Re: how to get object in pages !!!
- From: "Ken Robinson" <kenrbnsn@xxxxxxxxx>
- Date: 28 Jun 2005 16:49:42 -0700
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
.
- Follow-Ups:
- Re: how to get object in pages !!!
- From: yogi
- Re: how to get object in pages !!!
- References:
- how to get object in pages !!!
- From: yogi
- how to get object in pages !!!
- Prev by Date: Re: including png image with HTML content
- Next by Date: Re: URGENT: Prevent default HTTP headers from being sent
- Previous by thread: how to get object in pages !!!
- Next by thread: Re: how to get object in pages !!!
- Index(es):
Relevant Pages
|