Forum Moderators: coopster

Message Too Old, No Replies

Disappearing $_SESSION variable

Problem only arose once web site uploaded

         

sellenger

7:09 am on Aug 6, 2004 (gmt 0)



Hi Guys ,
I had this problem when I uploaded a web site recently. Here's the problem and a solution I patched on. Still don't know why though.

PROBLEM:

<?php
// $_SESSION['cust_id'] has been set to say 6
echo $_SESSION[cust_id];//outputs 6
/*********************************************
The request below is for a few forms that post
the cust_id. In this case is hasn't been posted.
I've always found that a REQUEST just ignores it
if its not posted
***********************************************/
$cust_id=$_REQUEST['cust_id'];
echo $_SESSION[cust_id];//outputs nothing
?>

The REQUEST destroys the $_SESSION[cust_id] variable but only on my web hosts server.

MY SOLUTION

replace $cust_id=$_REQUEST['cust_id'];
with if(isset($_POST['cust_id']))$cust_id =$_POST['cust_id'];

MY QUESTIONS
Why would a REQUEST destroy a $_SESSION variable of the same index name?
Why only once the site is uploaded?

ergophobe

4:31 pm on Aug 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



One server has register_globals on and the other doesn't.

Let's say you have

$myvar = 6;

$_POST['myvar'] = 7;

With register_globals on, $myvar now equals 7, with it off, it still equals 6.

Solution, in your .htaccess file, include a line

php_flag register_globals Off

Then you will have the same behavior on both servers (assuming you are using Apache and not IIS)

Tom