Nazirul Posted April 15, 2009 Share Posted April 15, 2009 Hello I am having a problem with session for log in... please take a look at the following code: if ($option == 'student'){ $sql = "SELECT * FROM user WHERE User_ID = '$studentId' AND User_Password ='$pswd'"; $result = mysql_query($sql)or die('Query failed. ' . mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); if (mysql_num_rows($result) == 1) { $_SESSION['User_ID']=1; $_SESSION['User_ID']=$studentId; $_SESSION['clerkId2']=$row['clerkId']; ?> <script language="JavaScript"> location.href='StudentIndex.php'; </script> <?php exit; } else { ?> <script language="JavaScript"> alert("Wrong username and password.");</script> <?php } } from the code, i have assign the session " $_SESSION['User_ID']=1; " in the StudentIndex.php page, i have assigned the following code for identifying the session if($_SESSION['User_ID']!=1) { $restrict = "login.php?error=You Must Login First"; header("Location: $restrict"); exit; } the problem is, even though i have a correct user ID and password,.. i still cant access the StudentIndex.php ... ??? thanks everyone Link to comment https://forums.phpfreaks.com/topic/154243-solved-problem-with-login-session/ Share on other sites More sharing options...
mrMarcus Posted April 15, 2009 Share Posted April 15, 2009 do you have session_start(); at the top of each page? Link to comment https://forums.phpfreaks.com/topic/154243-solved-problem-with-login-session/#findComment-810874 Share on other sites More sharing options...
Nazirul Posted April 15, 2009 Author Share Posted April 15, 2009 yes and it is if(!isset($_SESSION)||($_SESSION['User_ID'])) { session_start(); } Link to comment https://forums.phpfreaks.com/topic/154243-solved-problem-with-login-session/#findComment-810877 Share on other sites More sharing options...
laffin Posted April 15, 2009 Share Posted April 15, 2009 U cant use sessions without invoking session_start first. in that code ur using session variables prior to session_start Link to comment https://forums.phpfreaks.com/topic/154243-solved-problem-with-login-session/#findComment-810902 Share on other sites More sharing options...
limitphp Posted April 15, 2009 Share Posted April 15, 2009 U cant use sessions without invoking session_start first. in that code ur using session variables prior to session_start exactly....I think session_start is like "get php ready for using, deleting or creating new sessions". Link to comment https://forums.phpfreaks.com/topic/154243-solved-problem-with-login-session/#findComment-810905 Share on other sites More sharing options...
laffin Posted April 15, 2009 Share Posted April 15, 2009 yeah, thats how I see it as well. Link to comment https://forums.phpfreaks.com/topic/154243-solved-problem-with-login-session/#findComment-810911 Share on other sites More sharing options...
CloudSex13 Posted April 15, 2009 Share Posted April 15, 2009 $_SESSION['User_ID']=1; $_SESSION['User_ID']=$studentId; Why is there two of the same session variable with different data? Link to comment https://forums.phpfreaks.com/topic/154243-solved-problem-with-login-session/#findComment-810918 Share on other sites More sharing options...
Nazirul Posted April 15, 2009 Author Share Posted April 15, 2009 $_SESSION['User_ID']=1; $_SESSION['User_ID']=$studentId; Why is there two of the same session variable with different data? lol... this is the answer... how can i miss it... duhh thanks CloudSex13 and everyone... Link to comment https://forums.phpfreaks.com/topic/154243-solved-problem-with-login-session/#findComment-810986 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.