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

session variable problem

P: n/a
#register variable
session_register("product1");
session_register("product2");
$product1="Palm pilot";
$product2="Power mac 5";

#print variable from another page
print "Your chosen products are:\n\n";
print "<ul><li>$product1\n<li>$product2\n</ul>\n";

why the above code return

Your chosen products are:
Notice: Undefined variable: product1 in C:\Program Files\Apache
Group\Apache2\htdocs\session\session3.php on line 11

Notice: Undefined variable: product2 in C:\Program Files\Apache
Group\Apache2\htdocs\session\session3.php on line 11
Jul 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
sky2070 schrieb:
#register variable
session_register("product1");
session_register("product2");
$product1="Palm pilot";
$product2="Power mac 5";

#print variable from another page
print "Your chosen products are:\n\n";
print "<ul><li>$product1\n<li>$product2\n</ul>\n";

why the above code return

Your chosen products are:
Notice: Undefined variable: product1 in C:\Program Files\Apache
Group\Apache2\htdocs\session\session3.php on line 11

Notice: Undefined variable: product2 in C:\Program Files\Apache
Group\Apache2\htdocs\session\session3.php on line 11


check your setting for register_globals!

HTH!
rainer

Jul 16 '05 #2

P: n/a
sk***********@hotmail.com (sky2070) schrieb:
#register variable
session_register("product1");
session_register("product2");
$product1="Palm pilot";
$product2="Power mac 5";

#print variable from another page
print "Your chosen products are:\n\n";
print "<ul><li>$product1\n<li>$product2\n</ul>\n";

why the above code return

Your chosen products are:
Notice: Undefined variable: product1 in C:\Program Files\Apache
Group\Apache2\htdocs\session\session3.php on line 11

Notice: Undefined variable: product2 in C:\Program Files\Apache
Group\Apache2\htdocs\session\session3.php on line 11


Seems simple. In your php.ini register_globals is not set "On". On the
other hand, you can't expect that this value is always "On". On newer
versions of PHP (> 4.0.x) you should use

#register variable
$_SESSION["product1"]="Palm pilot";
$_SESSION["product2"]="Power mac 5";

#print variable from another page
print "Your chosen products are:\n\n";
print
"<ul><li>$_SESSION['product1']\n<li>$_SESSION['product2']\n</ul>\n";

Matthias
Jul 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.