stublackett Posted March 13, 2008 Share Posted March 13, 2008 Hi, I've got a login script, Which asks for Username & Password The script then pairs the "Userlevel" and re-directs to the relevant page for Userlevel, Which is set 1-3 I've just made one of the pages, But I'm convinced the session is not being sent to the page I've tried the print_r($_SESSION); and its showing me the Array but theres nothing in the array It says Array ( [username] => [password] => [userlevel] => ) Which is obviously not showing anything from the session This is the login script <?php include("dbtables.php"); // Connect to server and select databse. mysql_connect($hostname, $db_user, $db_password)or die("cannot connect"); mysql_select_db($dbname)or die("cannot select DB"); // username and password sent from signup form $username=stripslashes($_POST['username']); $password= ($_POST['password']); $sql="SELECT * FROM $db_table2 WHERE username='" . mysql_real_escape_string($username) . "' and password='" . mysql_real_escape_string($password) . "'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $username and $password, table row must be 1 row if($count==1){ //Register Username and Password $_SESSION['username'] = $username; $_SESSION['password'] = $password; $a=mysql_fetch_array($result); $u = $a['userlevel']; $userID = $a['UserID']; $_SESSION['userlevel'] = $u; if ($u == 1) header("location:student.php"); //If login is correct and UserLevel is 1 direct to Students' Page if ($u == 2) header("location:teacher.php"); //If login is correct and UserLevel is 2 direct to Teachers' Page if ($u == 3) header("location:superuser.php"); //If login is correct and UserLevel is 3 direct to SuperUsers' Page exit(); } else { $errormessage = "Invalid Username or Password"; } ?> I'm trying out the teacher.php page first, This is where I'm getting the Array of NULL values from The Teacher.php page is only coded as follows : <?php session_start(); $username = $_SESSION['username']; $userlevel = $_SESSION['userlevel']; print_r($_SESSION); ?> As I say that $_SESSION is just not cascading to other pages, Why not?? Link to comment https://forums.phpfreaks.com/topic/95946-sessions/ Share on other sites More sharing options...
PHP Monkeh Posted March 13, 2008 Share Posted March 13, 2008 You haven't started the session on the login page. Put session_start() on the very first line. Link to comment https://forums.phpfreaks.com/topic/95946-sessions/#findComment-491175 Share on other sites More sharing options...
stublackett Posted March 13, 2008 Author Share Posted March 13, 2008 Hah! Bit of a newbie mistake there Thanks for that Link to comment https://forums.phpfreaks.com/topic/95946-sessions/#findComment-491354 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.