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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.