0

Hi All,

How you can help me with something.

when a user logs in and is successful, i want the value of the user "type" to be stored in a session, which is then passed to the "login successful" page where i intend to use a switch statement to determine where they are to be forwarded to.

I know im almost there, but cant see my problem

This is the "checklogin.php" code, and the code after is the "login successful

$sql="SELECT user_type, user_email, user_password FROM tbl_user WHERE user_email='$user_email' and user_password='$user_password'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
$user_type = $result['user_type'];
// If result matched $email and $mypassword, table row must be 1 row

if($count==1){
// Register $email, $mypassword and redirect to file "login_success.php"
session_register("user_email");
session_register("user_password");
session_register($user_type);
header("location:login_success.php");

}
else {
	echo"there was a problem";


//header( "location:index.php");
}
?>

success.php

<?

// Check if session is not registered , redirect back to main page.
// Put this code in first line of web page.
session_start();
if(!session_is_registered(user_email)) {
header("location:index.php");
} else {
	echo "This worked";
	echo "you are a ";
	echo $_SESSION[$user_type];
}
?>
4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by maba001
0

from looking at this i know its passing through the session content of "user_email" so something is working

0

session_start is required in all of the PHP scripts that are supposed to work with user data. So

session_name('Something_unique');
session_start();

should go into all of the scripts and it has to be at a position where HTTP header data can still be sent. So it should come early in your code. Next part: AFAIK session_register is deprecated in the meantime. So I would put:

$_SESSION['utype'] = 'A';  // for user type A - take a numeric scheme if you like

and then do the processing based on that SESSION Variable:

if (isset($_SESSION['utype']) && $_SESSION['utype'] == 'A') {
   header('Location: loggedin.php')
} else {
   header('Location: tryagain.php')
}

something along those lines

Edited by maba001: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.