By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,216 Members | 1,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,216 IT Pros & Developers. It's quick & easy.

session var

P: n/a
Hi, all

this is a follow-up post to my previous post called Login Redirect.

I created two files called test.php and test1.php containing the following
contents (copied from a php textbook)

test.php
--------

<?
session_start();
session_register("sess_var");
$sess_var = "Hello World!";
echo "the content of \$sess_var is $sess_var<br>";

?>

<a href = "test1.php">Next Page</a>
test1.php
---------

<?
session_start();
echo "the content of \$sess_var is $sess_var<br>";
?>

<a href="test2.php">Next Page</a>
-------

test.php works.. it prints out the value of sess_var correctly. However,
when I click on the link Next Page (which takes me to test1.php). It outputs
the following

the content of $sess_var is
Next Page

why is that? I copied exactly as in the book..... Obviously php is
working...

==James==
Jul 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Sun, 17 Aug 2003 16:45:53 +1200, James Jiao wrote:
Hi, all

this is a follow-up post to my previous post called Login Redirect.

I created two files called test.php and test1.php containing the following
contents (copied from a php textbook)

test.php
--------

<?
session_start();
session_register("sess_var");
$sess_var = "Hello World!";
echo "the content of \$sess_var is $sess_var<br>";

?>

<a href = "test1.php">Next Page</a>
test1.php
---------

<?
session_start();
echo "the content of \$sess_var is $sess_var<br>";
?>

<a href="test2.php">Next Page</a>
-------

test.php works.. it prints out the value of sess_var correctly. However,
when I click on the link Next Page (which takes me to test1.php). It outputs
the following

the content of $sess_var is
Next Page

why is that? I copied exactly as in the book..... Obviously php is
working...

==James==

Looks like register_globals is disabled. Try this:

test.php
--------
<?
session_start();
$sess_var = "Hello World!";
$_SESSION["sess_var"] = $sess_var;

echo "the content of \$sess_var is $sess_var<br>";

?>

<a href = "test1.php">Next Page</a>
test1.php
------
<?
session_start();

$sess_var = $_SESSION["sess_var"];
echo "the content of \$sess_var is $sess_var<br>";
?>

<a href="test2.php">Next Page</a>
Jul 16 '05 #2

P: n/a
Ah, don't worry, I managed to find the problem :). The code in test1.php
should look like this:

<?
session_start();

if (session_is_registered("sess_var")) {
$sess_var = $_SESSION['sess_var'];
echo "the content of \$sess_var is $sess_var<br>";
}

?>

<a href="test2.php">Next Page</a>

-----

$sess_var not displayed before was because the directive register_globals
was not turned on. Since it poses security risks to turn this on, I used
$_SESSION['sess_var'] to gain access to the variable. :)

==James==

"James Jiao" <ja*******@paradise.net.nz> wrote in message
news:7M*********************@news02.tsnz.net...
Hi, all

this is a follow-up post to my previous post called Login Redirect.

I created two files called test.php and test1.php containing the following
contents (copied from a php textbook)

test.php
--------

<?
session_start();
session_register("sess_var");
$sess_var = "Hello World!";
echo "the content of \$sess_var is $sess_var<br>";

?>

<a href = "test1.php">Next Page</a>
test1.php
---------

<?
session_start();
echo "the content of \$sess_var is $sess_var<br>";
?>

<a href="test2.php">Next Page</a>
-------

test.php works.. it prints out the value of sess_var correctly. However,
when I click on the link Next Page (which takes me to test1.php). It outputs the following

the content of $sess_var is
Next Page

why is that? I copied exactly as in the book..... Obviously php is
working...

==James==

Jul 16 '05 #3

P: n/a
Cheers!! I found it out myself.. but hey thanks heaps!!

==James==
"mondo" <mo***@x.com> wrote in message
news:pa****************************@x.com...
On Sun, 17 Aug 2003 16:45:53 +1200, James Jiao wrote:
Hi, all

this is a follow-up post to my previous post called Login Redirect.

I created two files called test.php and test1.php containing the following contents (copied from a php textbook)

test.php
--------

<?
session_start();
session_register("sess_var");
$sess_var = "Hello World!";
echo "the content of \$sess_var is $sess_var<br>";

?>

<a href = "test1.php">Next Page</a>
test1.php
---------

<?
session_start();
echo "the content of \$sess_var is $sess_var<br>";
?>

<a href="test2.php">Next Page</a>
-------

test.php works.. it prints out the value of sess_var correctly. However,
when I click on the link Next Page (which takes me to test1.php). It outputs the following

the content of $sess_var is
Next Page

why is that? I copied exactly as in the book..... Obviously php is
working...

==James==

Looks like register_globals is disabled. Try this:

test.php
--------
<?
session_start();
$sess_var = "Hello World!";
$_SESSION["sess_var"] = $sess_var;

echo "the content of \$sess_var is $sess_var<br>";

?>

<a href = "test1.php">Next Page</a>
test1.php
------
<?
session_start();

$sess_var = $_SESSION["sess_var"];
echo "the content of \$sess_var is $sess_var<br>";
?>

<a href="test2.php">Next Page</a>

Jul 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.