dapidmini Posted January 8, 2011 Share Posted January 8, 2011 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>'; } Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted January 8, 2011 Share Posted January 8, 2011 use sessions instead of manipulating cookies. Quote Link to comment Share on other sites More sharing options...
dapidmini Posted January 9, 2011 Author Share Posted January 9, 2011 but don't session expires every time I close the browser? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.