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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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