I need to create a cookie once the user has logged in. In the cookie i want to just have the $user once the user has logged in. Please Help. Which Script do i put in the cookie? and how? could you please give me an example?
Login.php:
Code: Select all
<?php
if (isset($_POST['submit'])) { // check to see if the forum has been submitted
// where is tasys 'submit', use the name of the submit button on the form
include('connect.php');
// get form input
// check to make sure it's all there
// escape input values for greater safety
$user = empty($_POST['user']) ? die ("ERROR: Enter a Username") : mysql_escape_string($_POST['user']);
$pass = empty($_POST['pass']) ? die ("ERROR: Enter a Password") : mysql_escape_string($_POST['pass']);
$sql="SELECT * FROM users WHERE user='$user' and pass='$pass'";
$result=mysql_query($sql);
// Mysql_num_row is counting table ro
$count=mysql_num_rows($result);
// If result matched $user and $pass, table row must be 1 row
if($count==1){
// Register $user, $pass and redirect to file "login_success.php" and make cookie that saves the $user variable
//will add redirect script soon.
}
else {
echo "Wrong Username or Password";
}
}
?>
<html>
<head>
</head>
<body>
<?php
if (!isset($_POST['submit'])) {
// form not submitted
?>
<form action="<?=$_SERVER['../../Documents%20and%20Settings/Drezard/My%20Documents/My%20Received%20Files/PHP_SELF']?>" method="post">
Username: <input type="text" name="user">
Password: <input type="text" name="pass">
<input type="submit" name="submit">
</form>
<?php
}
?>
</body>
</html>login_success.php:
Code: Select all
<?php
//create a cookie with $user from login.php
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
echo " congratz you are logged in.";
if (isset($_COOKIE["user"])) {
echo "hi " $user;
}
else {
echo "You are not logged in!<br />";
}
?>
</body>
</html>