Remember me function by login?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Remember me function by login?

Post by mudkicker »

Hi there,

how can we do this "remember me" function by logging the user?

i used to make it with cookies but i couldn't. any ideas?
i give you my codes, too. something is wrong but what?
LOG.PHP

Code: Select all

<?php
session_start();
if (!isset($_POST[user]) || !isset($_POST[pass]) || empty($_POST[user]) || empty($_POST[pass]))
{
header("Location: oops.php?action=errorlogin");
}
else
{
include("db.php");
$db = new Db;
	$query = mysql_query("SELECT * FROM uyeler WHERE kulad='$_POST[user]' AND kulsif='$_POST[pass]'");
	$row = mysql_fetch_array($query);
	$num = mysql_num_rows($query);
	if ($num > 0)
	{
	session_register("ad");
	$ad = $row["ad"];
		if(isset($hatirla)) // Here: when we checked remember me, $hatirla is set.
		{
		setcookie ("loginhatirlat","logged",time()+86400);
		setcookie ("loginadi",$ad,time()+86400);
		}
	header("Location: index.php");
	}
	else
	{
	header("Location: oops.php?action=errorlogin");
	}
$db->Close();
}

?>
LOGOUT.PHP

Code: Select all

<?php
if($HTTP_COOKIE_VARS[loginhatirlat]="logged")
{
setcookie ("loginhatirlat","notlogged",time()+86400);
?>
Sistemden ba&#351;ar&#305;l&#305; bir &#351;ekilde ç&#305;kt&#305;n&#305;z. Anasayfaya dönmek için <a href="index.php" class="baslik">t&#305;klay&#305;n</a>.<br>
Pencereyi kapatmak için <a href="javascript:window.close();" class="baslik">t&#305;klay&#305;n</a>.
<?
}
if(session_is_registered("ad"))
{
setcookie ("loginhatirlat","notlogged",time()+86400);
session_unset();
session_destroy();
?>
Sistemden ba&#351;ar&#305;l&#305; bir &#351;ekilde ç&#305;kt&#305;n&#305;z. Anasayfaya dönmek için <a href="index.php" class="baslik">t&#305;klay&#305;n</a>.<br>
Pencereyi kapatmak için <a href="javascript:window.close();" class="baslik">t&#305;klay&#305;n</a>.
<?
}
else
{
header( "Location : index.php" );
}

?>
murph
Forum Commoner
Posts: 29
Joined: Fri Oct 03, 2003 1:28 pm
Location: washington

Post by murph »

Your code needs to be indented, its hard to read for me. basically what you need to do is when the user logs in, set a cookie. Set a cookie with the value of logged in, and if he / she selected the remember me option. Then on the login page just check to see if the remember me cookie is set, if so then populate the input fields with the value of the cookie. Should work like a dream.
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

I DID IT! yeaaaah :) whoooouohhhhheaaaa hurraaay!
now it works like cream ;)
check it out => http://www.teskere.com/mudkicker
Post Reply