graham23s Posted July 25, 2007 Share Posted July 25, 2007 Hi Guys, what im trying to do here is set a permanant cookie (which contains a time stamp) on 1 of my pages so i can track the users last visit, i have included a seperate file on this page called timestamp.php my question is how would i go about setting this cookie in the timestamp.php i set my main one using: <?php include("includes/db_connection.php"); include("includes/constants.php"); $username = trim(strtolower(mysql_real_escape_string($_POST['username']))); $password = trim(strtolower(mysql_real_escape_string($_POST['password']))); if (empty($username) || empty($password)) { echo "Please fill in both fields."; exit; } ## check the user is in the database ############################################### $login_query = "SELECT username,password FROM `membership` WHERE `username`='$username' AND `password`='$password'"; $login_result = mysql_query($login_query) or die (mysql_error()); $is_greater_than_1 = mysql_num_rows($login_result); // was there a user found?...####################################################### if($is_greater_than_1 != 1) { echo "Sorry username and password combination not found."; exit; } else { ## User is logged in so Let's give him a cookie. ################################### setcookie ("member",$username,time()+1957240,"/"); ## a variable to hold the cookie ################################################### $member = $username; ## If cookie failed set a session...################################################ $_SESSION['member'] = 'member'; ## Update Login timer...############################################################ $timer_query = "UPDATE `membership` SET `login`=now() WHERE `username`='$username' AND `password`='$password'"; $timer_result = mysql_query($timer_query) or die (mysql_error()); if ($timer_result) { header("Location:my_account.php"); } } ?> would i just do: setcookie ("member",$username,time()+1957240,"/"); that type of code alone nothing else? also how would i make it do a timestamp at all? thanks for any help guys Graham Quote Link to comment Share on other sites More sharing options...
soycharliente Posted July 25, 2007 Share Posted July 25, 2007 http://wiki.w4py.org/setting-permanent-cookies.html Quote Link to comment Share on other sites More sharing options...
graham23s Posted July 25, 2007 Author Share Posted July 25, 2007 Hi Mate, by doin a bit more digging it's probably best just to set a cookie that expires way in the future instead, but i'm not sure exactly when to set this, should i do it in my original login_check.php form and redirect the header to the page? cheers Graham Quote Link to comment Share on other sites More sharing options...
soycharliente Posted July 25, 2007 Share Posted July 25, 2007 You can do it on whatever page you want. It all depends on when you're going to need to access whatever information that the cookie holds. If you set it on page 2 but need it one page 1, then you've got a problem. Quote Link to comment Share on other sites More sharing options...
graham23s Posted July 25, 2007 Author Share Posted July 25, 2007 got it cheers charlie:) Graham Quote Link to comment Share on other sites More sharing options...
maxudaskin Posted July 25, 2007 Share Posted July 25, 2007 setcookie ("member",$username,time()+60*60*24*36500,"/"); That will last longer than the website or your client's computer. Let alone your client him/herself. 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.