0

this is my login code

<!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">
<?php
session_start();
$year = time() + 31536000;
if(isset($_POST['remember'])) {
setcookie('remember_me', $_POST['email'], $year);
setcookie('remember_me2', $_POST['pass'], $year);
}
elseif(!isset($_POST['remember'])) {
    if(isset($_COOKIE['remember_me'])) {
        $past = time() - 100;
        setcookie(remember_me, gone, $past);
    }
}
?>

<head>
<link rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css" media="screen"><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="js/jquery-1.7.1.min.js"></script>
<script src="js/jquery.validationEngine.js"></script>
<script src="js/jquery.validationEngine-en.js"></script>
<script>
$(document).ready(function(){
$("#login-form").validationEngine();
});
</script>
<title>Untitled Document</title>
</head>
<body>
<h3>Enter your Personal information</h3>
<form action="main.php" method="post" id="login-form">
<div>
    <input type="text" name="email" class="validate[required] text-input"  placeholder="Email" value="<?php
echo isset($_COOKIE['remember_me']); ?>">
  </div>
  <div>
    <input type="text" name="pass" class="validate[required] text-input" placeholder="Password" value="<?php echo isset($_COOKIE['remeber_me2']) ?>">
  </div>
   <div>
    Remember Me: <input type="checkbox" name="remember" value="1" <?php if(isset($_COOKIE['remember_me'])) {
        echo 'checked="checked"';
    }
    else {
        echo '';
    }
    ?> >
  </div> 
    <div>
    <button type="submit" name="login">Log in</button>
  </div> 
  <div>
    <a href="register.php">Signup</a>
  </div> 
  </form>
</body>
</html>

and this is my sesstion code

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php

include "connection.php";
$result = mysql_query("SELECT * FROM new WHERE Email='" . $_POST['email'] . "' and Password = '". $_POST['pass']."'");
$row  = mysql_fetch_array($result);
if(is_array($row)){
$_SESSION["ID"] = $row['ID'];
$_SESSION["Email"] = $row['Email'];
$_SESSION["Title"] = $row['Title'];
    }
     else {
            echo "Invalid details!";
            }
if(isset($_SESSION["ID"])){
echo"welcome</br>".  $_SESSION["Title"];
echo"</br><a href='logout.php'>Log out</a>";
}

?>
</body>
</html>

what wrong with it dont know?

2
Contributors
1
Reply
12
Views
3 Years
Discussion Span
Last Post by pritaeas
0

http://php.net/manual/en/function.setcookie.php

"setcookie() defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including <html> and <head> tags as well as any whitespace."

This question has already been answered. 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.