Jump to content

[help] cookies keep getting reset


dapidmini

Recommended Posts

I have a login.php that has a usual login form with a username and password textbox and a login button that redirects to index.php. when I login and go to the index.php, the welcome sign is on but after I click on a link that points to index.php itself, the "welcome, <myname>" sign is replaced with "sign in" again (the cookie disappears) even though I put a checking on top of the index.php page..

 

here's my code in index.php:

<?php
if ($_COOKIE['activeuser'] != '#') {
} else {
setcookie('activeuser','#',time()+60*100);
}
include('connect.php'); //this code connects to my database
if (isset($_POST['bLogin'])) {
$sql = 'SELECT * FROM user WHERE username = "'.$_POST['tfUsername'].'"';
$sql .= ' AND password = "'.$_POST['tfPassword'].'"';
$result = mysql_query($sql,$con);
if($result) {
	$row = mysql_fetch_array($result);
	$_COOKIE['activeuser'] = $row['name'];
} else {
	echo 'query error';
}
}
if ($_COOKIE['useraktif'] != '#') {
echo '<div id="welcome">Welcome, ' . $_COOKIE['activeuser'];
echo '<br/><a href="logout.php">Logout</a></div>';
} else {
echo '<div class="signIn"><a href="login.php">sign in</a></div>';
echo '<div class="signIn"><a href="#">Register</a></div>';
}

Link to comment
https://forums.phpfreaks.com/topic/223797-help-cookies-keep-getting-reset/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.