Stopping objects from auto-serializing

This is a discussion on Stopping objects from auto-serializing within the PHP General forums, part of the PHP Programming Forums category; Hi, I'm trying to set up my PHP app at my host, but am stumbling over the PHP configuration ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-31-2007
David Christopher Zentgraf
 
Posts: n/a
Default Stopping objects from auto-serializing

Hi,

I'm trying to set up my PHP app at my host, but am stumbling over the
PHP configuration there. register_globals is enabled, which seems to
auto-serialize my objects into $_SESSION, which in some cases
overwrites variables in there. I'm not sure if register_globals is
where the auto-serialization comes from, but it seems to be closely
related at least and I'm not in my best form today...

I tried putting "php_flag register_globals off" into an .htaccess
file, but that throws an Apache misconfiguration error.
Using set_ini() doesn't seem to do anything either.

Any advise on how to turn serialization off without dabbling with the
configuration file?

Chrs,
Dav
Reply With Quote
  #2 (permalink)  
Old 10-31-2007
Larry Garfield
 
Posts: n/a
Default Re: [PHP] Stopping objects from auto-serializing

Try:

php_value register_globals Off

That should not have any impact on the $_SESSION array, but turning register
globals off anyway is a good thing.

On Tuesday 30 October 2007, David Christopher Zentgraf wrote:
> Hi,
>
> I'm trying to set up my PHP app at my host, but am stumbling over the
> PHP configuration there. register_globals is enabled, which seems to
> auto-serialize my objects into $_SESSION, which in some cases
> overwrites variables in there. I'm not sure if register_globals is
> where the auto-serialization comes from, but it seems to be closely
> related at least and I'm not in my best form today...
>
> I tried putting "php_flag register_globals off" into an .htaccess
> file, but that throws an Apache misconfiguration error.
> Using set_ini() doesn't seem to do anything either.
>
> Any advise on how to turn serialization off without dabbling with the
> configuration file?
>
> Chrs,
> Dav



--
Larry Garfield AIM: LOLG42
larry@garfieldtech.com ICQ: 6817012

"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson
Reply With Quote
  #3 (permalink)  
Old 10-31-2007
David Christopher Zentgraf
 
Posts: n/a
Default Re: [PHP] Stopping objects from auto-serializing

On 31 Oct 2007, at 13:50, Larry Garfield wrote:

> Try:
>
> php_value register_globals Off


Same Apache misconfiguration error. Even though the host actually
requires me to enable PHP processing via an "AddHandler" .htaccess
directive, php_flag/value directives are throwing an error. Weird.

> ...but turning register globals off anyway is a good thing.


Indeed.
Reply With Quote
  #4 (permalink)  
Old 10-31-2007
Jochem Maas
 
Posts: n/a
Default Re: [PHP] Stopping objects from auto-serializing

David Christopher Zentgraf wrote:
> Hi,
>
> I'm trying to set up my PHP app at my host, but am stumbling over the
> PHP configuration there. register_globals is enabled, which seems to
> auto-serialize my objects into $_SESSION, which in some cases overwrites
> variables in there. I'm not sure if register_globals is where the
> auto-serialization comes from, but it seems to be closely related at
> least and I'm not in my best form today...
>
> I tried putting "php_flag register_globals off" into an .htaccess file,
> but that throws an Apache misconfiguration error.
> Using set_ini() doesn't seem to do anything either.


aside from this error (my guess is your not allowed to override it) I can't
see the problem of serialization .. don't put the object in $_SESSION?

also try:

php_admin register_globals 0


>
> Any advise on how to turn serialization off without dabbling with the
> configuration file?


why, what are you doing? show us the code?

>
> Chrs,
> Dav
>

Reply With Quote
  #5 (permalink)  
Old 10-31-2007
David Christopher Zentgraf
 
Posts: n/a
Default Re: [PHP] Stopping objects from auto-serializing

On 31 Oct 2007, at 15:32, Jochem Maas wrote:

> aside from this error (my guess is your not allowed to override it)
> I can't
> see the problem of serialization .. don't put the object in $_SESSION?

....
> what are you doing? show us the code?


I'm not putting the object in $_SESSION, but PHP apparently does on
this specific configuration.
I'm saving an array of ids in $_SESSION["basket"], and on some pages I
have an object called $basket.
Somehow this $basket gets saved into $_SESSION["basket"], where it
simply does not belong because it makes my code barf.

Seems I'll have to rename my variables, but aside from this specific
fix, I don't want any unneeded variables floating around my $_SESSION
and I certainly don't want them to be globally_registered.
Reply With Quote
  #6 (permalink)  
Old 10-31-2007
Jochem Maas
 
Posts: n/a
Default Re: [PHP] Stopping objects from auto-serializing

David Christopher Zentgraf wrote:
> On 31 Oct 2007, at 15:32, Jochem Maas wrote:
>
>> aside from this error (my guess is your not allowed to override it) I
>> can't
>> see the problem of serialization .. don't put the object in $_SESSION?

> ...
>> what are you doing? show us the code?

>
> I'm not putting the object in $_SESSION, but PHP apparently does on this
> specific configuration.
> I'm saving an array of ids in $_SESSION["basket"], and on some pages I
> have an object called $basket.
> Somehow this $basket gets saved into $_SESSION["basket"], where it
> simply does not belong because it makes my code barf.
>
> Seems I'll have to rename my variables, but aside from this specific
> fix, I don't want any unneeded variables floating around my $_SESSION
> and I certainly don't want them to be globally_registered.


are you using session_register()? (dont)
also are you setting the value in $_SESSION by reference?

e.g. $_SESSION['foo'] =& $bar; $bar = new Foo;

>

Reply With Quote
  #7 (permalink)  
Old 10-31-2007
David Christopher Zentgraf
 
Posts: n/a
Default Re: [PHP] Stopping objects from auto-serializing


On 31 Oct 2007, at 16:16, Jochem Maas wrote:

> are you using session_register()? (dont)
> also are you setting the value in $_SESSION by reference?


No and no. The only time I'm writing to $_SESSION["basket"] is by
setting $_SESSION["basket"][] = "foo", I'm never touching the actual
$_SESSION["basket"] variable as such, but which is exactly what's
happening.
Reply With Quote
  #8 (permalink)  
Old 10-31-2007
David Christopher Zentgraf
 
Posts: n/a
Default Re: [PHP] Stopping objects from auto-serializing

After some more playing around and a lot of print_r($SESSION)'s:

This specific PHP configuration seems to replace every entry in
$_SESSION if a variable with the same name is used in the main script
with that variable.

I.e.
session_start() // $_SESSION["foo"] is now "bar"
$foo = "12345";
$var = "xxxx";

function test() {
$foo = "67890";
}
test();

After execution finished $_SESSION["foo"] is now "12345", but there's
no $_SESSION["var"].
What's going on here?

On 31 Oct 2007, at 16:25, David Christopher Zentgraf wrote:

>
> On 31 Oct 2007, at 16:16, Jochem Maas wrote:
>
>> are you using session_register()? (dont)
>> also are you setting the value in $_SESSION by reference?

>
> No and no. The only time I'm writing to $_SESSION["basket"] is by
> setting $_SESSION["basket"][] = "foo", I'm never touching the actual
> $_SESSION["basket"] variable as such, but which is exactly what's
> happening.
>

Reply With Quote
  #9 (permalink)  
Old 10-31-2007
hochprior
 
Posts: n/a
Default Re: Stopping objects from auto-serializing

David Christopher Zentgraf wrote:
> Hi,
>
> I'm trying to set up my PHP app at my host, but am stumbling over the
> PHP configuration there. register_globals is enabled, which seems to
> auto-serialize my objects into $_SESSION, which in some cases
> overwrites variables in there. I'm not sure if register_globals is
> where the auto-serialization comes from, but it seems to be closely
> related at least and I'm not in my best form today...
>
> I tried putting "php_flag register_globals off" into an .htaccess
> file, but that throws an Apache misconfiguration error.
> Using set_ini() doesn't seem to do anything either.
>
> Any advise on how to turn serialization off without dabbling with the
> configuration file?


I got the following in my main .htaccess (and it works just fine...):
php_flag register_globals 0

--
Kind regards,
hochprior
Reply With Quote
  #10 (permalink)  
Old 10-31-2007
David Christopher Zentgraf
 
Posts: n/a
Default Re: [PHP] Re: Stopping objects from auto-serializing

On 31 Oct 2007, at 17:23, hochprior wrote:

> I got the following in my main .htaccess (and it works just fine...):
> php_flag register_globals 0


Well apparently I'm not allowed to override register_globals.

Looking at the problem a little closer, it also doesn't seem like
register_globals is the culprit. Browsing through the PHP bug reports
a bit brought my attention to --enable-track-vars, which is enabled in
my case. It sounds a little more like it has something to do with my
problem, but I can't seem to find any documentation on this flag...
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:59 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0