zfred09 Posted January 25, 2007 Share Posted January 25, 2007 My goal of this is to say if $var isnt set then set it, but when I goto the page nothing shows up, but then if I refresh the page the string will show up. It's as if when I first load the page it just doesn't read the isset part or something.[code]if(!isset($var)){$_SESSION['var']="23213123";} echo "$var";[/code] Quote Link to comment Share on other sites More sharing options...
zq29 Posted January 25, 2007 Share Posted January 25, 2007 I don't have an answer to your question, but you should [i]really[/i] be scripting with register_globals switched off in your php.ini Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 25, 2007 Share Posted January 25, 2007 if(!isset($var)){$_SESSION['var']="23213123";} echo "$var";When you first load the page var ISN'T set. $_SESSION['var'] is, but $var is not.Change to:if(!isset($var)){ $var = '23213123'; $_SESSION['var']=$var;} echo $var;And it will echo every time.ps: don't put quotes around varables that don't need them. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 25, 2007 Share Posted January 25, 2007 [quote author=SemiApocalyptic link=topic=124024.msg513393#msg513393 date=1169752312]I don't have an answer to your question, but you should [i]really[/i] be scripting with register_globals switched off in your php.ini[/quote]The fact that this isn't working makes it look like globals IS off. Quote Link to comment Share on other sites More sharing options...
craygo Posted January 25, 2007 Share Posted January 25, 2007 I have no answer either I just wanted to comment on Semi's quote, funny shit. Quote Link to comment Share on other sites More sharing options...
zq29 Posted January 25, 2007 Share Posted January 25, 2007 [quote author=jesirose link=topic=124024.msg513398#msg513398 date=1169752530][quote author=SemiApocalyptic link=topic=124024.msg513393#msg513393 date=1169752312]I don't have an answer to your question, but you should [i]really[/i] be scripting with register_globals switched off in your php.ini[/quote]The fact that this isn't working makes it look like globals IS off.[/quote]Why does it work on refresh then? (Sorry if I'm missing something obvious here, been a long day!) Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 25, 2007 Share Posted January 25, 2007 Ah good point. If this is the entire page, you're right, RG is on. If there's more code, perhaps $var = $_SESSION['var']; earlier on?I dunno, either way. You're right it should be off. I think the code I posted will fix the immediate problem. Quote Link to comment Share on other sites More sharing options...
zfred09 Posted January 25, 2007 Author Share Posted January 25, 2007 That is at the very top of the page and isn't defined later on. And what is the benefit of register globals being off? Security? Quote Link to comment Share on other sites More sharing options...
trq Posted January 25, 2007 Share Posted January 25, 2007 Yes, security. Itys also allot easier to keep track of variables when there aren't mysterious globals floating around. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.