Session Variable In php
This simple issue I know, in my program session variable is already working properly but now it show some error. I am starting the session in my config page with session_start(); ob_start();
And then include this page in all pages. But if run the program I receive this error message:
Cannot send session cache limiter - headers already sent
If remove the included config page the session variable is notworking.
session_start();
ob_start();
$dbcont = mysql_connect("localhost","root","");
mysql_select_db("emplist",$dbcont);
if($_POST["subSubmit"]=="Submit") {
$user = $_POST["txtUsername"];
$pass = $_POST["txtPassword"];
if ($user == "user" && $pass == "pass") {
$_SESSION["uaid"] = "ADMIN SECTION";
header("Location:welcome.php");
exit();
}else{
$err = "Login Failed. Check You UserID/Password";
}
}
?>
<html>
<head>
<title>.:: Employee Management ::.</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form1" id="form1" onSubmit="return checklogin();">
USER ID : <input type="text" name="txtUsername" id="txtUsername" onKeyUp="return clearerr();">
PASSWORD : <input type="password" name="txtPassword" id="txtPassword" onKeyUp="return clearerr();">
<开发者_如何转开发input type="submit" class="FormButton" name="subSubmit" id="subSubmit" value="Submit">
<input type="reset" class="FormButton" name="butReset" id="butReset" value="Reset">
</form>
</body>
</html>
This is my main page code. If login is successful then the control will be moved to "Welcome.php" page in that page I just echo the session variable.
move the session_start();
to the very top
You see, The RULE is you cannot have anything before the session_start();
NOT ONE CHARACTER, otherwise, the browser thinks the webpage has already started, so before you start session_start();
YOU CANNOT START THE HEADER. You start the header with any character, this includes white spaces (space bar).
So also choose your browser Accordingly.
Try to delete BOM symbols rom script.
If you haven't already, try putting session_start()
before any output is generated from the script.
精彩评论