Re: how to get object in pages !!!



yogi wrote:
> Hi,
> I am new to PHP. actually I am using php-java bridge to call some
> functions of java from my php page. The value returned are encapsulated
> in some object and data in that object are fetched from database. What
> I want to do is that when I post my page to same page or other page I
> again need that data (or object). I don't want to hit the database
> again for same values. So how and where to set the object values. I
> think I can set it in request object like in java we do
> (request.setAttribute(String, Object)). I am focibly setting the values
> like $_REQUEST['list']=somelistObject. But I am not getting the data
> after submission of page. same operation with $_SESSION also is not
> working. If somebody knows how to do this, please help.

To share values among scripts you need to use either $_SESSION or
Cookies. If you use sessions make sure you call the function
session_start() before anything is sent to the screen from your script.

Try these two scripts to see if sessions are working:

script1.php
<?
session_start();
$_SESSION['leaving'] = 'script1';
header('location: script2.php');
exit();
?>

script2.php
<?
session_start();
echo 'This is script2<br>The SESSION Super Array contains:';
echo '<pre>';print_r($_SESSION);echo '</pre>';
$left = $_SESSION['leaving'];
echo 'We left ' . $left . ' to come here!';
?>

If you invoke script1.php with a browser, you should see an output on
your screen like this:

This is script2
The SESSION Super Array contains:

Array
(
[leaving] => script1
)

We left script1 to come here!

Ken

.



Relevant Pages

  • Re: Apache vs IIS
    ... Apache/PHP allows you to set session cookies for a whole site, or part of a site if so wanted. ... As I understand to do this in PHP you have to store the values in SESSION cockies then check the SESSION array to see if the value was stored or not. ... But in general ASP.NET is microsoft response to Java. ... Java scripts my self. ...
    (alt.php)
  • Re: [PHP] Persistent Objects
    ... I've been told this is taboo in PHP. ... Coming from Java I'm sure ... implementing form validation, you may want to study up on the strategy ... fetching it from the session each time? ...
    (php.general)
  • Re: Is OOP really appropriate for PHP?
    ... using C++ or Java, all my objects reside in RAM. ... PHP as long as the current thread is being executed. ... session is deferred). ...
    (comp.lang.php)
  • PHP Session Vars & Flash Movie
    ... I have a small application made in flash, that uses a set of PHP scripts ... can only see it if a session has been initialized. ...
    (php.general)
  • Re: [PHP] two php scripts with same $_SESSION variables
    ... folders A and B. When they are run from two different browsers, I am getting the behavior I 'd like to see with two session ids being created and therefore no sharing of $_SESSION variables. ... But when the two apps are opened inside the same browser, the $_SESSION variables are shared and that makes sense because session_idreturns the same value. ... It would be be nice that when the app in A is running and the user starts the app in B, in the same browser widow, the server and php are instructed to realize that this is a brand new session and assign a new session_idwhich would solve my problem. ... How can I make sure that the $_SESSIONis not shared between the two scripts? ...
    (php.general)