Jump to content

Isset function not working.


zfred09

Recommended Posts

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]
Link to comment
https://forums.phpfreaks.com/topic/35702-isset-function-not-working/
Share on other sites

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 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 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!)
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.