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
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.
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

[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!)
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.