470,848 Members | 1,887 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,848 developers. It's quick & easy.

session variable problem

#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
2 5311
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
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.

Similar topics

1 post views Thread by Nick Whitelegg | last post: by
1 post views Thread by Scott Wickham | last post: by
1 post views Thread by farooqazeem | last post: by
5 posts views Thread by Marc Rivait | last post: by
9 posts views Thread by William LaMartin | last post: by
9 posts views Thread by Greg Linwood | last post: by
1 post views Thread by Werner | last post: by
7 posts views Thread by Lucas Tam | last post: by
4 posts views Thread by T Ralya | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.