Not a Member Yet,
Click here to Register
How do you like the new design?
It's cool, great job
[tally: 70%] 70%
It's okay
[tally: 20%] 20%
Its OK but I liked the old layout better
[tally: 0%] 0%
Please bring the old one back
[tally: 10%] 10%

votes: 10

ID: 114
Viewed: 7435
Added: Apr 08, 2002
Version:
Snippet uploaded by: snippet
Written By: snippet
Demo: Sorry, no demo



User Rated at: 0 Stars
Rate This:

Thank you for your vote. Please wait...

It appears you already voted for this snippet

It appears your vote value was empty

A basic cookie script that writes a cookie and deletes a cookie based on the user who logs in or out. It checks against a mysql database to ensure the user actually exist.

<!---Head--->
none

<!---Body--->


 <?
$link = mysql_connect("localhost", "root", "*****");
mysql_select_db("dbname");

IF ($action == "logout"){
// actually deletes teh cookie if one is set.
setcookie("cookie_name", "", time() - 43200);
echo "Cookie has been deleted.";
exit;
}
IF ($action == "login")
{
//check username and password against a mysql database.
$result = mysql_query("SELECT * FROM Users WHERE name='$uname' AND pass='$upassword'");
$check = mysql_num_rows($result);
//if not row was found then write failed
IF (!$check){
echo "Failed to log in, sorry";
exit;
}
else{
//row was found so it writes the cookie and lets the user on.
setcookie ("cookie_name", "$u_name", time() + 43200);

echo "Welcome $u_name, you <br>";
echo "loggen in ok";
//redirects the user to another page once logged in.
echo"<META HTTP-EQUIV="Refresh" Content="1;URL=index.php">";
}
mysql_close($link);
}else{

?>
<html>
<head></head>
<body>
<form action="<?= $PHP_SELF ?>" method="post">
Name<input type=text name=u_name>
Pass<input type=password name=u_password>
<input type=hidden name=action value=login>
<input type=submit value="send">
</form>
<form action="<?= $PHP_SELF ?>" method="post">
<input type=hidden name=action value=logout>
<input type=submit value="Log Out">
</form>
</body>
</html>
<?
}
?>


No Comments to show

Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Replying to a Comment...


Adding your comment. Please wait...

Thanks for adding your comment!. After further review it will be added.

There was a problem adding your comment. Please try again.

Please complete all the fields in the form before sending.

© 2002 - 2017 snippetlibrary.com All Rights Reserved. Conditions