Jump to content

pass session through pages


Recommended Posts

Hello.  Basically I've created a login script.  Works great.  It sends users to different locations depending on what type of user they are.  Now I have also created a Members account.  Upon logging in this user should go to the members area.  That all works fine!


In the login script i stored a few session variable like username, access_level and so on.  Now in the members area I am trying to make the page echo the name of the current user.  I have been stairing at my code too long and can no longer see why nothing is echo'ing.  Any ideas. I thought that the session_start() would continue the session in the next page and throughout the site until the person logs off and runs the session_destroy()!  Is this not correct.  First ill post the login script

<?php include('database.php');

if(isset($_POST['submit3'])) {

$email = stripslashes($_POST['email3']);
$password = stripslashes($_POST['password3']);
$email = mysql_real_escape_string($_POST['email3']);   
$password = md5($password);    

$CheckUser = "SELECT * FROM Members WHERE email='".$email."' AND password='".$password."'";
$userDetails2 = mysql_query($CheckUser);	
$userInfo = mysql_fetch_array($userDetails2);
$count = mysql_num_rows($userDetails2);	

		 if($count != 0) {
		 	$_SESSION['username'] = $userInfo['username'];
			$_SESSION['usertype'] = $userInfo['usertype'];
			$_SESSION['access_level']= $userInfo['access_level'];

			if($userInfo['usertype']== 'Member')	
				header('Location: members/index.php');
			else if($userInfo['usertype'] == 'Owner') {
				header('Location: owner/index.php');
			else if($userInfo['usertype'] == 'Corporation') {
				header('Location: corporation/index.php');
			else if($userInfo['usertype'] == 'Administrator') {
				header('Location: owner/admin/index.php');
			else if($userInfo['usertype'] ==  'Staff') {
				header('Location: owner/staff/index.php');


		else {
			$message = "incorrect login details";


now ill post the members page

<?php include('../database.php');



<link href="stylz.css" rel="stylesheet" type="text/css" />
<link href="reset.css" rel="stylesheet" type="text/css" />
<div id="wrapper">


<?php include('../title.php');?>
<?php include('../nav.php');?>

<div id="test"></div>

<?php include('../footer.php');?>

Link to comment
Share on other sites

AdRock beat me to it  :P


I think you have the idea of sessions right, but just to clarify one thing..sessions variables will be available to any page that has session_start() on it, not just any page after. I think thats what you meant, but the way it was worded was a little iffy

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

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

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.