Jump to content

Recommended Posts

I seem to be loosing variables.

 

Here is my code

 

echo "[".$_SESSION['user']."]<br />";
$user = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `Login` = '".$_SESSION['user']."' AND LIMIT 1 ;"));
echo "[".$_SESSION['user']."]<br />";

 

and here is the output.

Why does php loose the value of $_SESSION['user'] when I try and use it?

 

[Anthony]
[]

Link to comment
https://forums.phpfreaks.com/topic/164773-solved-php-is-loosing-variables/
Share on other sites

Possibly something to do with your PHP version. I have seen before that you can use variables like $user to grab the value of $_REQUEST['user'] automatically. Try this:

 

echo "[".$_SESSION['user']."]<br />";
$query = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `Login` = '".$_SESSION['user']."' AND LIMIT 1 ;"));
echo "[".$_SESSION['user']."]<br />";

Because register_globals are on. Turn them off as quick as possible. They were turned off by default in php4.2 in the year 2002, but a lot of people did not get the message on how dangerous they are.

 

$user, $_POST['user'], $_GET['user'], $_COOKIE['user'], and $_SESSION['user'] are all cross populated when register_globals are on.

Because register_globals are on. Turn them off as quick as possible. They were turned off by default in php4.2 in the year 2002, but a lot of people did not get the message on how dangerous they are.

 

$user, $_POST['user'], $_GET['user'], $_COOKIE['user'], and $_SESSION['user'] are all cross populated when register_globals are on.

 

ok many thanks, is it possible to turn them off without access to php.ini

If you're running PHP as an Apache module you can add this to a .htaccess file:

php_flag register_globals Off

 

Then send an email to your host requesting that they hire competent sysadmins.

 

ok many thanks

ps, its not my host, im helping out someone else on their server.

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.