Jump to content

pass session through pages


fife

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');
session_start();

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');
session_start();


?>

<head>

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

WELCOME TO THE MEMBERS AREA <?php $_SESSION['username']; ?>


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


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

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


Link to comment
https://forums.phpfreaks.com/topic/210324-pass-session-through-pages/
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

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.