Login and Remember me function sessions and cookie problem?
Posted: Sun Oct 05, 2003 2:41 pm
Hi there, my website is http://www.teskere.com/mudkicker . I wrote a script that some can login with or without "remember me" function. but something is wrong there.. when someone is came for the firsttime user control panel is shown which is not possible if you're not logged... i send you the codes. please help me this is very important for me! thank you very much.
This part of the page code show you if you are logged the user control panel or login form!
THis one is the script which logs you and authenticates you.
And this one is the code to log out...
Have a nice day, i hope someone can find the problem here, thanks!
Code: Select all
<?php
if(session_is_registered("ad") || $HTTP_COOKIE_VARS["loginhatirlat"]="logged") {
?>
<table width="180" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="1" height="1" bgcolor="#0085BC"></td>
<td width="9" height="1" class="baslikmenu"></td>
<td height="1" class="baslikmenu">Merhaba <?php
if(!$HTTP_SESSION_VARS["ad"]) { echo $HTTP_COOKIE_VARS["loginadi"]; } else { echo $HTTP_SESSION_VARS["ad"]; }
?></td>
<td width="1" height="1" bgcolor="#0085BC"></td>
</tr>
<tr>
<td width="1" bgcolor="#0085BC"></td>
<td width="9"> </td>
<td><a href="profil.php" class="normal">Kullanıcı Bilgilerini Değiştir</a> </td>
<td width="1" bgcolor="#0085BC"></td>
</tr>
<tr>
<td bgcolor="#0085BC"></td>
<td width="9"> </td>
<td class="normal"><a href="logout.php" class="normal">Sistemden Çık </a></td>
<td bgcolor="#0085BC"></td>
</tr>
<tr bgcolor="#0085BC">
<td width="1" height="1"></td>
<td width="9" height="1"></td>
<td height="1"></td>
<td width="1" height="1"></td>
</tr>
</table>
<?php
} else {
?><form action="log.php" method="post">
<table width="180" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#0085BC">
<td width="1" height="1"></td>
<td height="1"></td>
<td height="1" colspan="2"></td>
<td width="1" height="1"></td>
</tr>
<tr>
<td width="1" bgcolor="#0085BC"></td>
<td width="9" class="baslikmenu"></td>
<td colspan="2" class="baslikmenu">Login</td>
<td width="1" bgcolor="#0085BC"></td>
</tr>
<tr>
<td bgcolor="#0085BC"></td>
<td width="9" class="normal"></td>
<td width="60" class="normal"><div align="right"><strong>K. Adı:</strong></div></td>
<td width="109" class="normal">
<center>
<input name="user" type="text" class="button" id="user" size="10">
</center></td>
<td bgcolor="#0085BC"></td>
</tr>
<tr>
<td width="1" bgcolor="#0085BC"></td>
<td width="9" class="normal"></td>
<td width="60" class="normal"><div align="right"><strong>Şifre:</strong></div></td>
<td width="109" class="normal">
<center>
<input name="pass" type="password" class="button" id="pass" size="10">
</center></td>
<td width="1" bgcolor="#0085BC"></td>
</tr>
<tr>
<td bgcolor="#0085BC"></td>
<td class="normal"></td>
<td width="60" class="normal">
<div align="right">
<input name="hatirla" type="checkbox" id="hatirla" value="ok">
</div></td>
<td width="109" class="normal">Beni Hatırla! </td>
<td bgcolor="#0085BC"></td>
</tr>
<tr>
<td bgcolor="#0085BC"></td>
<td class="normal"></td>
<td width="60" class="normal"> </td>
<td width="109" class="normal">
<input name="loginsend" type="submit" class="button" id="loginsend" value="Gönder!">
<input name="logsil" type="reset" class="button" value="Sil!">
</td>
<td bgcolor="#0085BC"></td>
</tr>
<tr>
<td width="1" bgcolor="#0085BC"></td>
<td height="1" bgcolor="#0085BC"></td>
<td height="1" colspan="2" bgcolor="#0085BC"></td>
</tr>
</table>
</form>
<?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='".md5($_POST[pass])."'");
$row = mysql_fetch_array($query);
$num = mysql_num_rows($query);
if ($num > 0)
{
session_register("ad");
$ad = $row["ad"];
if(isset($hatirla))
{
setcookie ("loginhatirlat","logged",time()+86400);
setcookie ("loginadi",$ad,time()+86400);
}
header("Location: index.php");
}
else
{
header("Location: oops.php?action=errorlogin");
}
$db->Close();
}
?>Code: Select all
<?php
if($HTTP_COOKIE_VARS["loginhatirlat"]="logged")
{
setcookie ("loginhatirlat","notlogged",time()+86400);
session_destroy();
?>
Sistemden başarılı bir şekilde çıktınız. Anasayfaya dönmek için <a href="index.php" class="baslik">tıklayın</a>.<br>
Pencereyi kapatmak için <a href="javascript:window.close();" class="baslik">tıklayın</a>.
<?php
}
if(session_is_registered("ad"))
{
setcookie ("loginhatirlat","notlogged",time()+86400);
session_unset();
session_destroy();
?>
Sistemden başarılı bir şekilde çıktınız. Anasayfaya dönmek için <a href="index.php" class="baslik">tıklayın</a>.<br>
Pencereyi kapatmak için <a href="javascript:window.close();" class="baslik">tıklayın</a>.
<?php
}
else
{
header( "Location : index.php" );
}
?>Have a nice day, i hope someone can find the problem here, thanks!