Jump to content

$_SESSION and $_POST values not passed across forms


asmii

Recommended Posts

Hi,

 

I am using PHP4 and facing an issue regarding session control.

 

I have a login page login.htm which after taking required details e.g username and password, submits it to submit.php which has the following lines to control a session.

 

//submit.php
session_start();

$uid = isset($_POST['uid']) ? $_POST['uid'] : $_SESSION['uid'];
$pwd = isset($_POST['pwd']) ? $_POST['pwd'] : $_SESSION['pwd'];

$_SESSION['lastaccess']= mktime(); 

 

After matching it with DB, it redirects to index.htm using header("Location:index.htm");

 

Now, Index.htm includes a php file called accesscontrol.php which has the following code :

 

//accesscontrol.php
session_start();
//header("Cache-control: private");
$newtime=mktime();

$tdiff = $newtime - $_SESSION['lastaccess'];
//echo $tdiff;
if ($tdiff > 900)
{
session_unset();
// Finally, destroy the session.
session_destroy();
exit;
}
else
{
$_SESSION['lastaccess']= mktime();
} 

 

The problem is accesscontrol.php can't access $_SESSION['lastaccess'] which leads to further issues.

 

On accesscontrol.php, $_POST variables are also not accessible.

 

 

$uid = isset($_POST['uid']) ? $_POST['uid'] : $_SESSION['uid'];
$pwd = isset($_POST['pwd']) ? $_POST['pwd'] : $_SESSION['pwd'];

 

 

When I checked $uid and $pwd, these are not set.

 

Please help.

 

Thanks in advance.

 

It didn't help much.

 

The actual problem happens in the following.

 

$newtime=mktime();

$tdiff = $newtime - $_SESSION['lastaccess'];

if ($tdiff > 900)
{
header("Location:login.htm");
session_unset();
session_destroy();
exit;
}
else
{
$_SESSION['lastaccess']= mktime();
}

 

accesscontrol.php doesn't find the variable $_SESSION['lastaccess'] which is set in submit.php and thus "if" part is executed rather than "else"

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.