Re: magic_quotes_gpc? Session variables
| From: | tedd | Date: | Mon, 12 Jun 2006 12:45:45 +0000 |
| Subject: | Re: magic_quotes_gpc? Session variables | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-237807@lists.php.net to get a copy of this message | ||
At 8:08 AM -0400 6/12/06, Mk wrote:
>Hey gang,
>
> I was having the weirdest problems when I decided to update the code for my site(written in
> PHP) last modified over a year ago. The code ran fine under my home development system, but on the
> hosting machine(1and1.com), my code would break. Horribly.
>
> I narrowed the problem to this - If I have a variable in $_SESSION(for example,
> 'username') and in my page, I declare a variable (for example
> '$username="guest"'), I've effectively accessed and overwritten the session
> variable. It's been over a year, but I believe this is due to magic_quotes_gpc flag being 1
> or something - I checked with my host's phpinfo page and it is set to 1.
>
> My question is(before I send my host an e-mail to ask them to turn it off for my site) is,
> magic_quotes_gpc IS the culprit, right? I mean the whole behavior of if you declare a variable :
>
> $_SESSION['username'] = "Mark"
>
> then you can just write $username instead of $_SESSION["username"] to access the
> session variable is because of magic_quotes_gpc?
>
>Thanks in advance,
>Mk
Mk:
I believe that "magic_quotes_gpc" doesn't have anything to do with your problem.
If you want, you can read about "magic_quotes_gpc" here:
http://us3.php.net/magic_quotes
Back to your problem -- place this at the start of your code:
<?php session_start();
$_SESSION['username'];
After that, you can do:
$_SESSION["username"] = "Mark";
echo($username);
And it should work -- at least it works for me.
If you want to turn magic_quotes_gpc OFF, try placing a ".htaccess" file in your root with
the following statement.
php_value magic_quotes_gpc 0
I don't know under what conditions one is allowed to do this, but this is what I do with my
servers.
hth's
tedd
--
------------------------------------------------------------------------------------
http://sperling.com http://ancientstones.com http://earthstones.com