session lost....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zinc
Forum Newbie
Posts: 15
Joined: Fri Feb 10, 2006 1:02 am

session lost....

Post by zinc »

everything works well when i develope the codes under fedora core 4..using php 5.1.1 apache 2.2.0

but when i migrate to a window 2003 server, php 5.1.2, all the session variables are lost when the browser is redirected from the login verification to the main page...

the codes are as follows

Code: Select all

session_start();
session_register('session');
I included this at the top of the main page so that i can use the stored session variables.

Code: Select all

$session['id']=session_id();
$session['userid']=$rec['name'];
$session['loginID']=$loginID;
$session['password']=$password;
session_write_close();
This is how i assigned the session variables.

After verifying the user is a valid user, i redirect him using javascript

Code: Select all

print "<script>self.location='../myinbox/myinbox.php'</script>";
At the top of the inbox page, i checked if one of the session variables is NULL. If its NULL, i will redirect him to the login page.
In this case, i'm using the session variable to check. But after logging in, the session variables should be set after the user had logged in. But in this case, all the session variables are lost. I had searched many sites for similair problems but none really gave a valid answer.
Thx for the help.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

First, I think you need to declare $session before registering it. Second, the prefered way is to use the superglobal $_SESSION instead which is automatically registered. You can use it in exactly the same way as your $session var without all the potential global/register vars problems.
(#10850)
zinc
Forum Newbie
Posts: 15
Joined: Fri Feb 10, 2006 1:02 am

Post by zinc »

sorry, i don't quite understand your first point.

As for the second point that you mentioned, i did try using

$_Session['loginID'] = $loginID

but it still doesn't work.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

session_register is not a prefered way of assigning session vars anymore. That functionality has been replaced with the assignment of the vars into the $_SESSION superglobal array. After calling session_start() you can just assign session vars by throwing them into the $_SESSION global.

Code: Select all

<?php
session_start();

if (isset($POST['username']))
{
    $_SESSION['user'] = $_POST['username'];
}
?>
zinc
Forum Newbie
Posts: 15
Joined: Fri Feb 10, 2006 1:02 am

Post by zinc »

i tried using $_Session but it still doesn't work....

has it got to do with the php.ini configuration file??
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

It's not $_Session, it is $_SESSION. Variable names in PHP are case sensitive.
(#10850)
zinc
Forum Newbie
Posts: 15
Joined: Fri Feb 10, 2006 1:02 am

Post by zinc »

my mistake.

miss out on the uppercase.

By the way, why is it that the old codes work on LINUX but it doesn't work on WINDOW???
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Different php.ini configuration probably.

Mac
Post Reply