Not a Member Yet,
Click here to Register

ID: 114
Viewed: 11535
Added: Apr 08, 2002
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.



$link = mysql_connect("localhost", "root", "*****");

IF ($action == "logout"){
// actually deletes teh cookie if one is set.
setcookie("cookie_name", "", time() - 43200);
echo "Cookie has been deleted.";
IF ($action == "login")
//check use\r\name 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";
//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">";

<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 action="<?= $PHP_SELF ?>" method="post">
<input type=hidden name=action value=logout>
<input type=submit value="Log Out">

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 - 2024 All Rights Reserved. Conditions
Do NOT follow this link or you will be banned from the site!