I cannot figure out why my session data is not available:
Here is the code for the login:
PHP Code:
<?php session_start(); include 'mysqlconnectionUSERLEVEL2.php'; //check for required fields from the form if ((empty($_POST["username"])) || (empty($_POST["password"]))) { session_destroy(); header("Location: http://www.foobar.net/login/login.html"); } //print "Username & password set"; // print "<p> SET $username</p>"; //create and issue the query $query = "SELECT username, pass, user_level, first_name, last_name FROM users WHERE username = '".$_POST["username"]."' AND pass = SHA1('".$_POST["password"]."')"; #PASSWORD('".$_POST["password"]."')"; $result = mysqli_query($mysqli, $query) or die(mysqli_error($mysqli)); //get the number of rows in the result set; should be 1 if a match if (mysqli_num_rows($result) == 1) { while ($info = mysqli_fetch_array($result)) { $f_name = stripslashes($info['username']); $first_name = stripslashes($info['first_name']); $last_name = stripslashes($info['last_name']); $user_level = stripslashes($info['user_level']); } if ($user_level == "99") { $_SESSION['first_name'] = $first_name; $_SESSION['last_name'] = $last_name; $_SESSION['user_level'] = $user_level; // If headers were already sent for some reason, // the upcoming call to header() will not work... //print $_SESSION['first_name']; header("Location: http://www.foobar.net/sis/index.php"); //ob_end_flush(); } } /* //destroy the session session_destroy(); //redirect back to login form if not authorized header("Location: http://www.foobar.net/login/login.html"); exit;*/ session_write_close(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Login</title> </head> <body> </body> </html>
here is the INDEX.php
Note login.php and index.php are in different folders
/mainfolder/login/login.php
/mainfolder/sis/index.php
here is the index.php
PHP Code:
<?php session_start(); print "NAME"; print $_SESSION['first_name']; if(isset($_SESSION['last_name'])) { if ($_SESSION['user_level'] = "2") include 'mysqlconnectionUSERLEVEL2.php'; // include the database connection for user level if ($_SESSION['user_level'] = "99") include 'mysqlconnectionUSERLEVEL99.php'; // include the database connection for user level 2 print "authorised"; } else { print "UNAUTHORISED"; session_destroy(); header("Location: http://www.ark.net/"); exit(); } print "INDEX"; ?>
The SESSION array is not available in the INDEX.php.. It is blank.
But works fine in Internet explorer
I verified that SESSION is set correctly right before the header call to index.php in Safari, but it is not accessible in index.php.
What am i doing wrong???
|