By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

Losing session variables value

P: n/a
I have a case where the session values appear to lose their value. I
tracked it down with some print_r inserted. Here are the lines:

print '<br 1: '; print_r($_SESSION);
$adminLevel = $_POST['edit_level_list'];
print '<br 2: '; print_r($_SESSION);

Here is the output:

1: Array ( [adminLevel] =SUPERUSER [clientID] =0 )
2: Array ( [adminLevel] =[clientID] =0 )

There is nothing special about the variable$adminlevel. It is just an
ordinary local variable. Field edit_level_list is a select list.

If I change the name of the variable from $adminLevel to $foo, then the
session variable does not lose its value.

If I then immediately set $adminLevel = $foo, the session variable loses
its value.

What is so special about the name of a local variable?
Aug 21 '08 #1
Share this Question
Share on Google+
8 Replies


P: n/a
sheldonlg wrote:
I have a case where the session values appear to lose their value. I
tracked it down with some print_r inserted. Here are the lines:

print '<br 1: '; print_r($_SESSION);
$adminLevel = $_POST['edit_level_list'];
print '<br 2: '; print_r($_SESSION);

Here is the output:

1: Array ( [adminLevel] =SUPERUSER [clientID] =0 )
2: Array ( [adminLevel] =[clientID] =0 )

There is nothing special about the variable$adminlevel. It is just an
ordinary local variable. Field edit_level_list is a select list.

If I change the name of the variable from $adminLevel to $foo, then the
session variable does not lose its value.

If I then immediately set $adminLevel = $foo, the session variable loses
its value.

What is so special about the name of a local variable?
You probably have register_globals set to on - which is should NOT be.
Turn it off.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Aug 22 '08 #2

P: n/a
sheldonlg wrote:
I have a case where the session values appear to lose their value. I
tracked it down with some print_r inserted. Here are the lines:

print '<br 1: '; print_r($_SESSION);
$adminLevel = $_POST['edit_level_list'];
print '<br 2: '; print_r($_SESSION);

Here is the output:

1: Array ( [adminLevel] =SUPERUSER [clientID] =0 )
2: Array ( [adminLevel] =[clientID] =0 )

There is nothing special about the variable$adminlevel. It is just an
ordinary local variable. Field edit_level_list is a select list.

If I change the name of the variable from $adminLevel to $foo, then the
session variable does not lose its value.

If I then immediately set $adminLevel = $foo, the session variable loses
its value.

What is so special about the name of a local variable?
Can you reproduce the bug by doing something like:

-----%<----- foo.php ----------------------------------------
<?php
$_SESSION=array('adminLevel' ='SUPERUSER', 'clientID' =0);
$_POST['edit_level_list'] = 'foo';
print '<br 1: '; print_r($_SESSION);
$adminLevel = $_POST['edit_level_list'];
print '<br 2: '; print_r($_SESSION);
?>
-----%<----- foo.php ----------------------------------------

$ php foo.php

BTW, what does php -i show as your PHP version. Mine's 5.2.5.

Best regards,

--
Charles
Aug 22 '08 #3

P: n/a
Jerry Stuckle wrote:
sheldonlg wrote:
>I have a case where the session values appear to lose their value. I
tracked it down with some print_r inserted. Here are the lines:

print '<br 1: '; print_r($_SESSION);
$adminLevel = $_POST['edit_level_list'];
print '<br 2: '; print_r($_SESSION);

Here is the output:

1: Array ( [adminLevel] =SUPERUSER [clientID] =0 )
2: Array ( [adminLevel] =[clientID] =0 )

There is nothing special about the variable$adminlevel. It is just an
ordinary local variable. Field edit_level_list is a select list.

If I change the name of the variable from $adminLevel to $foo, then
the session variable does not lose its value.

If I then immediately set $adminLevel = $foo, the session variable
loses its value.

What is so special about the name of a local variable?

You probably have register_globals set to on - which is should NOT be.
Turn it off.
I don't -- unless the hosting company has that by default somehow. I
never do anything with register_globals.
Aug 22 '08 #4

P: n/a

sheldonlg schreef:
Jerry Stuckle wrote:
>sheldonlg wrote:
>>I have a case where the session values appear to lose their value. I
tracked it down with some print_r inserted. Here are the lines:

print '<br 1: '; print_r($_SESSION);
$adminLevel = $_POST['edit_level_list'];
print '<br 2: '; print_r($_SESSION);

Here is the output:

1: Array ( [adminLevel] =SUPERUSER [clientID] =0 )
2: Array ( [adminLevel] =[clientID] =0 )

There is nothing special about the variable$adminlevel. It is just
an ordinary local variable. Field edit_level_list is a select list.

If I change the name of the variable from $adminLevel to $foo, then
the session variable does not lose its value.

If I then immediately set $adminLevel = $foo, the session variable
loses its value.

What is so special about the name of a local variable?

You probably have register_globals set to on - which is should NOT be.
Turn it off.

I don't -- unless the hosting company has that by default somehow. I
never do anything with register_globals.
DOn't guess, check. :-)

Make a file with only:
<?php
phpinfo();
?>

And see what it says.

Regards,
Erwin Moller
--
============================
Erwin Moller
Now dropping all postings from googlegroups.
Why? http://improve-usenet.org/
============================
Aug 22 '08 #5

P: n/a
Erwin Moller wrote:
>
sheldonlg schreef:
>Jerry Stuckle wrote:
>>sheldonlg wrote:
I have a case where the session values appear to lose their value.
I tracked it down with some print_r inserted. Here are the lines:

print '<br 1: '; print_r($_SESSION);
$adminLevel = $_POST['edit_level_list'];
print '<br 2: '; print_r($_SESSION);

Here is the output:

1: Array ( [adminLevel] =SUPERUSER [clientID] =0 )
2: Array ( [adminLevel] =[clientID] =0 )

There is nothing special about the variable$adminlevel. It is just
an ordinary local variable. Field edit_level_list is a select list.

If I change the name of the variable from $adminLevel to $foo, then
the session variable does not lose its value.

If I then immediately set $adminLevel = $foo, the session variable
loses its value.

What is so special about the name of a local variable?
You probably have register_globals set to on - which is should NOT
be. Turn it off.

I don't -- unless the hosting company has that by default somehow. I
never do anything with register_globals.

DOn't guess, check. :-)

Make a file with only:
<?php
phpinfo();
?>

And see what it says.
Did that last night. See my previous reply.
Aug 22 '08 #6

P: n/a

sheldonlg schreef:
Erwin Moller wrote:
>>
sheldonlg schreef:
>>Jerry Stuckle wrote:
sheldonlg wrote:
I have a case where the session values appear to lose their value.
I tracked it down with some print_r inserted. Here are the lines:
>
print '<br 1: '; print_r($_SESSION);
$adminLevel = $_POST['edit_level_list'];
print '<br 2: '; print_r($_SESSION);
>
Here is the output:
>
1: Array ( [adminLevel] =SUPERUSER [clientID] =0 )
2: Array ( [adminLevel] =[clientID] =0 )
>
There is nothing special about the variable$adminlevel. It is just
an ordinary local variable. Field edit_level_list is a select list.
>
If I change the name of the variable from $adminLevel to $foo, then
the session variable does not lose its value.
>
If I then immediately set $adminLevel = $foo, the session variable
loses its value.
>
What is so special about the name of a local variable?
>

You probably have register_globals set to on - which is should NOT
be. Turn it off.
I don't -- unless the hosting company has that by default somehow. I
never do anything with register_globals.

DOn't guess, check. :-)

Make a file with only:
<?php
phpinfo();
?>

And see what it says.

Did that last night. See my previous reply.
Hi,

I don't see any previous reply where you said you did it.
Did you start posting via googlegroups maybe, halfway the thread?
(If so, I have dropped that response, see my sig. Sorry)

Regards,
Erwin Moller

--
============================
Erwin Moller
Now dropping all postings from googlegroups.
Why? http://improve-usenet.org/
============================
Aug 22 '08 #7

P: n/a
Erwin Moller wrote:
>
sheldonlg schreef:
>Erwin Moller wrote:
>>>
sheldonlg schreef:
Jerry Stuckle wrote:
sheldonlg wrote:
>I have a case where the session values appear to lose their
>value. I tracked it down with some print_r inserted. Here are
>the lines:
>>
>print '<br 1: '; print_r($_SESSION);
>$adminLevel = $_POST['edit_level_list'];
>print '<br 2: '; print_r($_SESSION);
>>
>Here is the output:
>>
>1: Array ( [adminLevel] =SUPERUSER [clientID] =0 )
>2: Array ( [adminLevel] =[clientID] =0 )
>>
>There is nothing special about the variable$adminlevel. It is
>just an ordinary local variable. Field edit_level_list is a
>select list.
>>
>If I change the name of the variable from $adminLevel to $foo,
>then the session variable does not lose its value.
>>
>If I then immediately set $adminLevel = $foo, the session variable
>loses its value.
>>
>What is so special about the name of a local variable?
>>
>
You probably have register_globals set to on - which is should NOT
be. Turn it off.
>

I don't -- unless the hosting company has that by default somehow.
I never do anything with register_globals.

DOn't guess, check. :-)

Make a file with only:
<?php
phpinfo();
?>

And see what it says.

Did that last night. See my previous reply.

Hi,

I don't see any previous reply where you said you did it.
Did you start posting via googlegroups maybe, halfway the thread?
(If so, I have dropped that response, see my sig. Sorry)

Regards,
Erwin Moller
You didn't because it got stuck in my emailer outbox for some reason. I
must have had a connection failure and didn't notice it as I left the
computer to go to sleep. Here it is:

====
I just did a phpinfo. It showed that register_globals is, indeed, on.
By default it is set to off as of PHP4.2 and the version I am running is
5.2.6. The hosting company must have turned it on. Unfortunately,
according to the manual:

"Please note that register_globals cannot be set at runtime
(ini_set()). Although, you can use .htaccess if your host allows it as
described above. An example .htaccess entry: php_flag register_globals
off ."

I will have to check to see if I can have a .htaccess file.
====
Aug 22 '08 #8

P: n/a

sheldonlg schreef:
Erwin Moller wrote:
>>
sheldonlg schreef:
>>Erwin Moller wrote:

sheldonlg schreef:
Jerry Stuckle wrote:
>sheldonlg wrote:
>>I have a case where the session values appear to lose their
>>value. I tracked it down with some print_r inserted. Here are
>>the lines:
>>>
>>print '<br 1: '; print_r($_SESSION);
>>$adminLevel = $_POST['edit_level_list'];
>>print '<br 2: '; print_r($_SESSION);
>>>
>>Here is the output:
>>>
>>1: Array ( [adminLevel] =SUPERUSER [clientID] =0 )
>>2: Array ( [adminLevel] =[clientID] =0 )
>>>
>>There is nothing special about the variable$adminlevel. It is
>>just an ordinary local variable. Field edit_level_list is a
>>select list.
>>>
>>If I change the name of the variable from $adminLevel to $foo,
>>then the session variable does not lose its value.
>>>
>>If I then immediately set $adminLevel = $foo, the session
>>variable loses its value.
>>>
>>What is so special about the name of a local variable?
>>>
>>
>You probably have register_globals set to on - which is should NOT
>be. Turn it off.
>>
>
I don't -- unless the hosting company has that by default somehow.
I never do anything with register_globals.

DOn't guess, check. :-)

Make a file with only:
<?php
phpinfo();
?>

And see what it says.

Did that last night. See my previous reply.

Hi,

I don't see any previous reply where you said you did it.
Did you start posting via googlegroups maybe, halfway the thread?
(If so, I have dropped that response, see my sig. Sorry)

Regards,
Erwin Moller
Hi,
You didn't because it got stuck in my emailer outbox for some reason.
Aha, that explains. ;-)

I
must have had a connection failure and didn't notice it as I left the
computer to go to sleep. Here it is:

====
I just did a phpinfo. It showed that register_globals is, indeed, on.
By default it is set to off as of PHP4.2 and the version I am running is
5.2.6. The hosting company must have turned it on. Unfortunately,
according to the manual:

"Please note that register_globals cannot be set at runtime
(ini_set()). Although, you can use .htaccess if your host allows it as
described above. An example .htaccess entry: php_flag register_globals
off ."

I will have to check to see if I can have a .htaccess file.
====
Should work if they allow overwriting php-ini settings via .htaccess,
but they claim they do, so you should be fine.

Good luck.

Regards,
Erwin Moller
--
============================
Erwin Moller
Now dropping all postings from googlegroups.
Why? http://improve-usenet.org/
============================
Aug 22 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.