Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/schedfox/public_html/test/Login.php:2) in /home/schedfox/public_html/test/Login.php on line 2
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/schedfox/public_html/test/Login.php:2) in /home/schedfox/public_html/test/Login.php on line 2
any idea why I am getting this error, any help is highly appreciated.
Below is my code.
Code: Select all
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<script language="Javascript">
function LoginAction()
{
document.form1.action = "Login.php?action=loginuser";
//alert ("hi");
document.form1.submit();
}
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
$connection = pg_connect("hostaddr=FOOBAR port=5432 dbname=FOOBAR user=FOOBAR password=FOOBAR");
if (!$connection) {
echo("Connection Failed.");
exit;
}
$action = trim($_GET['action']);
?>
<form id="form1" name="form1" method="post">
<p>
<label>UserName
<input type="text" name="UserName" id="UserName" />
</label>
</p>
<p>
<label>Password
<input type="password" name="Password" id="Password" />
</label>
</p>
<p>
<label>Submit
<input type="submit" name="Submit" id="Submit" value="Submit" onClick="LoginAction()" />
</label>
</p>
<?php
if($action=="loginuser"){
$user = $_POST['UserName'];
$pass = $_POST['Password'];
$encPassword = md5($pass);
$query = "select user_password from control_db.user where user_login = '". $user . "' ";
$query_user = "select user_login from control_db.user where user_login = '". $user . "' ";
$result_user = pg_query($query_user);
$i =0;
while($myrow_user = pg_fetch_assoc($result_user))
{
$i++;
}
if($i== 0){
echo "username does not exist";
}
else{
$result = pg_query($query);
while($myrow = pg_fetch_assoc($result)) {
$storedPassword = $myrow['user_password'];
if($storedPassword == $encPassword){
echo "correct username and password";
$_SESSION['user_login'] = $_POST['UserName'];
Header("Location: MainPage.php");
}
else {
echo "Wrong password";
}
}
}
}
?>
<p> </p>
<p> </p>
</form>
</body>
</html>