More session woes...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gxpark
Forum Commoner
Posts: 33
Joined: Fri Jun 21, 2002 4:01 pm
Location: Mexico City

More session woes...

Post by gxpark »

Hi again,

After finally being able to store variables in a session, now I can't seem to be able to delete them!

Right after I use the session_unregister or session_unset functions, the variable does get deleted from the session (or so it seems), but if I reload a page, the variable re-appears.

Do I need to do something special besides _unregister or _unset?

Thanks in advance!

- Ivan V.
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Re: More session woes...

Post by protokol »

gxpark wrote:but if I reload a page, the variable re-appears.
Well, this would mean that somewhere on the page you are also giving the $_SESSION variable a value. So look for a line where you would be giving the variable a value and that's why it's setting it again.

--
protokol
gxpark
Forum Commoner
Posts: 33
Joined: Fri Jun 21, 2002 4:01 pm
Location: Mexico City

Post by gxpark »

I don't think that's the problem since setting the $_SESSION array elements directly does not work (that's what I was doing in the first place, now I know better).

Anyway, thanks for the interest :)
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

gxpark wrote:I don't think that's the problem since setting the $_SESSION array elements directly does not work
Well, in newer versions of PHP you can do that. You can just say:

Code: Select all

$_SESSIONї'varname'] = $somevalue;
and it WILL work.

Are you using session_register() to initialize the session variable in that same script???
gxpark
Forum Commoner
Posts: 33
Joined: Fri Jun 21, 2002 4:01 pm
Location: Mexico City

Post by gxpark »

I'm using the newest version of PHP, and setting the $_SESSION array directly does not work for me. It does store the value for as long as the script is running, but not between pages (in the same session).

And yes, I'm using the session_register function.
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

ok, well first of all, you need to use session_start() at the top of each script that will be using the session variables

also, if you are using the newest version of PHP, then session_register() is not needed and you can simply assign the $_SESSION['varname'] a value
gxpark
Forum Commoner
Posts: 33
Joined: Fri Jun 21, 2002 4:01 pm
Location: Mexico City

Post by gxpark »

I'm using session_start, and my session data is indeed being saved. As for your other comment, well, then there must be something wrong with my installation because what you suggest does not work.
gxpark
Forum Commoner
Posts: 33
Joined: Fri Jun 21, 2002 4:01 pm
Location: Mexico City

Post by gxpark »

Dumb ass... I found the bug. I was saving the session variable in other part of the program, similar to registering it again...

Ahh, life is good after a good bug hunt.
Post Reply