Hopefully, someone can point out what's wrong or what I'm missing. My husband's webhost upgraded to PHP5, and now everything's a mess. I'm having problems with variables not being registered. But I've been trying different things and things just seem weird. (Note: things were coded a long time ago, when I was a newbie, with register globals on -- the webhost turned that to off awhile ago, so we were setting it to on through php.ini file -- I know it shouldn't be on;there just hasn't been time rewrite things...) Anyway, as a simple test, I tried this: I have page1.php with this, say, this for example: ===================== <?php session_start(); $myname = "John"; session_register('myname'); ?> <a href="page2.php">Go to page 2</a> ===================== And this on page2.php: ===================== <?php session_start(); print "My name is: $myname"; print "<br> but using $*_SESSION['myname'], I get: ".$_SESSION['myname']; ?> ===================== The output on page2 (when coming from page1) is: My name is: but using $*_SESSION['myname'], I get: John I'm not crazy, right -- shouldn't I at least be getting a value when printing $myname? Is there something wrong on my side or was something missed when PHP5 was compiled by my webhost? This should be so simple... register a variable and then use it throughout... Thanks in advance...
I'm not familiar with the * in $*_SESSION['myname'], is that a typo or another function im not aware of? Also, you should escape it out of the print with ".." too, shouldn't you? In regards to my name, isnt there a register global settings that prevents/allows that? this may be your new setting.
Hi Luke, No, I was just using $*_SESSION with an asterisk, so that it would print out. If you look at the code, I'm using $_SESSION['myname'] to print out the myname variable. Yup, register_globals is set to off and has been for awhile. We worked around that by putting a register_globals on in a php.ini file; this worked fine until now. Unless things have changed in a major way, there's nothing wrong with: print "hello world $some variable"; Thanks! ================ To ALL: I put the exact same test code on another server, and had no problems with printing $myname. Would this have anything to do with session save path? It's currently set to "/" Thanks...
Still sounds like a register globals thing to me. Have you checked your error logs? Is there a reason you don't want to use $_SESSION['myname']? It is a much better way of doing it than putting register_globals On.
I agree that it's a much better/more secure way (again, I wrote the code while a newbie...) -- it's just that I'll have to do a lot of rewriting... I didn't check the error logs, because it's not really an error thing. (Although I did just check now and... nothing...) I may have a workaround; I'll have to test it. After the workaround, I'll have to work on rewriting things, so that it works with register_globals off... I'm self-taught when it comes to PHP, so I'm sure there's bad coding practices in there... Thanks!
Hmm. I figured it would throw a warning if it couldn't find that variable. It should work the way I was seeing it. I completely understand the re-coding nightmare. Im self-taught myself, and just recently started taking some classes so that I can fill in some gaps. I learned a lot of stuff that I had been doing was not the best way of doing it, and now Im working on re-writing a lot.
@nico_swd: did so; nothing happened. @jestep: At least I'm not alone! I did find a workaround... And then I'll spend some time doing some reading and re-coding... Thanks all!
Use the backslash character to escape symbols: "... \$_SESSION ..." session_register() requires register_globals to operate. It is also deprecated. Assign values directly to the $_SESSION[] superglobal array instead, and read from that. With regards to manually setting register_globals to ON, I suspect your host has not enabled this facility in the new php.ini. If you want to catch bad coding, use the strict standards setting: error_reporting(E_ALL ^ E_STRICT); PHP:
Thanks, penagate! I was looking for that sort of confirmation! (And, yes, we can no longer manually set register_globals to ON.) Thanks again, to everyone...