Jump to content

session not printing


funbinod

Recommended Posts

on my login page, if error happened, I'm trying to create error session on loginprocess file and I want it to display on login page. but after any error, it prevents logging in but doesn't display the error msg stored on session...

 

here are the both files

// login page<?phpdate_default_timezone_set("Asia/Kathmandu");require_once("mysql.php");echo '<p class="errordiv">';if (isset($_SESSION['error'])) {	unset($_SESSION['formAttempt']);	print "Errors:<br />n";	echo $_SESSION['error'];	unset($_SESSION['error']);} // end ifelse if (isset($_SESSION['timeout'])) {	echo $_SESSION['timeout'];	unset($_SESSION['timeout']);}if (isset($_SESSION['loggedin'])) {	echo $_SESSION['loggedin'];	unset($_SESSION['loggedin']);}echo '</p>';?><h2><u>Please LOGIN to continue</u></h2><br /><br /><form name="login" action="testloginprocess.php?" method="POST"><table style="width:700px; border:1;" align="center">	<tr>		<td style="width:180px;">Username:</td>        <td><input type="text" name="username" id="username" onkeypress="return tabE(this,event)" autocomplete="off" /></td>    </tr>    <tr>    	<td>Password:</td>        <td><input type="password" name="password" id="password" onkeypress="return tabE(this,event)" autocomplete="off" /></td>    </tr>    <tr>    	<td><input type="hidden" value="<?php echo $hash; ?>" name="hash"></td>        <td><input type="submit" name="login" value="LOGIN" id="login" /></td>    </tr></table></form>
// login process file<?phpdate_default_timezone_set("Asia/Kathmandu");require_once("mysql.php");$now = date('Y-m-d H:i:s');//			$_SESSION['formAttempt'] = true;			// check required field			if (!isset($_POST['username']) || $_POST['username'] == "") {				session_start();				$_SESSION['error'] = "Please input <span style='color:#F00;'>username</span>";				die(header("location: testlogin.php?"));			} else if (!isset($_POST['password']) || $_POST['password'] == "") {				session_start();				$_SESSION['error'] = "Please input <span style='color:#F00;'>password</span>";				die(header("location: testlogin.php?"));			}			$username = mysqli_real_escape_string($connect, $_POST['username']);			$password = mysqli_real_escape_string($connect, $_POST['password']);			$sql = "SELECT isloggedin, type FROM user WHERE username='$username'";			$result = mysqli_query($connect, $sql);			$row = mysqli_fetch_assoc($result);			if ($row['isloggedin'] == "Y") {				session_start();				$_session['loggedin'] = '<h1 style="color:#F00;text-align:center;">This user is already logged in!</h1>';				die(header("location: testlogin.php?"));			} else {				$type = $row['type'];				if (count($_SESSION['error']) > 0) {					session_start();				die(header("location: testlogin.php?"));				} else {					$user = new User;					if ($user->authenticate($username,$password)) {						unset($_SESSION['formAttempt']);						$server = ip2long($_SERVER['REMOTE_ADDR']);						mysqli_query($connect, "UPDATE user SET lastlogin='$now', lastActive='$now', isloggedin='Y', loggedinfrom='$server' WHERE cid='$_SESSION[cid]' AND uid='$_SESSION[uid]'") or die("Error: ".mysqli_error($connect));						mysqli_query($connect, "UPDATE clients SET lastlogin='$now' WHERE cid='$_SESSION[cid]'") or die("Error: ".mysqli_error($connect));						die(header("location: chkactivation.php?"));					} else {						session_start();						$_SESSION['error'] = "Problem with your username or password!";				die(header("location: testlogin.php?"));					}				}			}?>

will u please help me to find out the problem.....

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...