Jump to content

Sessions?


stublackett

Recommended Posts

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

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.