asmii Posted August 7, 2008 Share Posted August 7, 2008 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. Link to comment https://forums.phpfreaks.com/topic/118605-_session-and-_post-values-not-passed-across-forms/ Share on other sites More sharing options...
Xurion Posted August 7, 2008 Share Posted August 7, 2008 You mention that your HTML page includes your PHP file - how? Link to comment https://forums.phpfreaks.com/topic/118605-_session-and-_post-values-not-passed-across-forms/#findComment-610625 Share on other sites More sharing options...
asmii Posted August 7, 2008 Author Share Posted August 7, 2008 I meant that the index.htm file contains the following command : include 'accesscontrol.php'; Link to comment https://forums.phpfreaks.com/topic/118605-_session-and-_post-values-not-passed-across-forms/#findComment-610633 Share on other sites More sharing options...
MasterACE14 Posted August 7, 2008 Share Posted August 7, 2008 you can try using if and else for this part rather then ternary operator. $uid = isset($_POST['uid']) ? $_POST['uid'] : $_SESSION['uid']; $pwd = isset($_POST['pwd']) ? $_POST['pwd'] : $_SESSION['pwd']; Link to comment https://forums.phpfreaks.com/topic/118605-_session-and-_post-values-not-passed-across-forms/#findComment-610635 Share on other sites More sharing options...
asmii Posted August 7, 2008 Author Share Posted August 7, 2008 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" Link to comment https://forums.phpfreaks.com/topic/118605-_session-and-_post-values-not-passed-across-forms/#findComment-610655 Share on other sites More sharing options...
kenrbnsn Posted August 7, 2008 Share Posted August 7, 2008 Unless your webserver is processing HTML file with PHP, putting PHP into a .htm file will not work. Rename your index.htm to index.php Ken Link to comment https://forums.phpfreaks.com/topic/118605-_session-and-_post-values-not-passed-across-forms/#findComment-610699 Share on other sites More sharing options...
asmii Posted August 7, 2008 Author Share Posted August 7, 2008 My webserver is working as expected. I think issue may be somewhere else. Link to comment https://forums.phpfreaks.com/topic/118605-_session-and-_post-values-not-passed-across-forms/#findComment-610722 Share on other sites More sharing options...
kenrbnsn Posted August 7, 2008 Share Posted August 7, 2008 If you create a file named "test_file.htm" which contains: <?php phpinfo(); ?> and invoke it, does anything display? Ken Link to comment https://forums.phpfreaks.com/topic/118605-_session-and-_post-values-not-passed-across-forms/#findComment-610759 Share on other sites More sharing options...
Xurion Posted August 7, 2008 Share Posted August 7, 2008 How does one execute PHP code within a .htm file? Link to comment https://forums.phpfreaks.com/topic/118605-_session-and-_post-values-not-passed-across-forms/#findComment-610834 Share on other sites More sharing options...
asmii Posted August 8, 2008 Author Share Posted August 8, 2008 I upgraded my setup and suddenly everything started working form me I think there was something wrong in my old setup but I still wonder what could be the issue. Thanks. Link to comment https://forums.phpfreaks.com/topic/118605-_session-and-_post-values-not-passed-across-forms/#findComment-611319 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.