session problem

hi,

the code below is in the index.php page, which is used for user login:

//get lastvisit
$sql = "SELECT * FROM lastvisit WHERE userid = '$id'";
                   $result_lastvisit = mysql_query($sql) or die("could not execute query lastvisit1");
                   $row_array_lastvisit = mysql_fetch_array($result_lastvisit);
$lastvisit = $row_array_lastvisit['lastvisit'];
//set session var values
$row_array = mysql_fetch_array($result);
$_SESSION['userid'] = $row_array['userid'];
$_SESSION['user_title'] = $row_array['title'];
$_SESSION['user_fname'] = $row_array['firstname'];
$_SESSION['user_lname'] = $row_array['lastname'];
$_SESSION['user_email'] = $row_array['email'];
$_SESSION['lastvisit'] = $lastvisit;
//set lastvisit
$now = date("Y-m-d H:i:s");
$sql = "UPDATE lastvisit SET lastvisit = '$now' WHERE userid = '$id'";
mysql_query($sql) or die("could not update lastvisit2");
echo "<SCRIPT> location.href="user/userhome.php";</SCRIPT>";
?>

the code above read the lastvisit time from mysql, and then save(update) the lastvist to current time(login time).
after that, use is rediredcted to userhome.php, in this page, the lastvisit time will be updated again(actually it will be updated in each page user will visit), as below:

<?php
session_start();
$userid = $_SESSION['userid'];
$user_title = $_SESSION['user_title'];
$user_fname = $_SESSION['user_fname'];
$user_lname = $_SESSION['user_lname'];
$user_email = $_SESSION['user_email'];
$admin = $_SESSION['admin'];
$session_lastvisit = $_SESSION['lastvisit'];
header("Cache-control: private"); // IE 6 Fix. 
echo $session_lastvisit;
include_once("../common/auth.php");
CheckUser();

include_once("../common/config.php");
//set lastvisit
$lastvisit = date("Y-m-d H:i:s");
$sql = "UPDATE lastvisit SET lastvisit = '$lastvisit' WHERE userid = '$userid'";
mysql_query($sql) or die("could not update lastvisit");

when i run the code on Apache with WindowsXP,it works ok, $_SESSION[‘lastvisit’] is set to the time read from mysql when user login. and lastvisit is updated in userhome.php.

however, when i run it on Apache with Linux server, i found that the $_SESSION[‘lastvisit’] is always the current time…which means it will be changed in the userhome.php. each time when i refresh the uesrhome.php, the $_SESSION[‘lastvisit’] will be refreshed to the current time also.

it is strange, cause there is no code to update the $_SESSION[‘lastvisit’], unless on Linux, when i refresh the userhome.php, it will also run the index.php again, is it possible? anyway, anyone knows what is the problem? it is so strange…

thanks a lot…i ve tried to slove it for hours, really thanks…

[Admin edit] You’ll have to type [code ] in manually, its obviously nobbed up…

This is a bit of a shot in the dark, but maybe try and rename the variable?

I’m not 100% sure of the problem (its been a hard day)

Sponsor our Newsletter | Privacy Policy | Terms of Service