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 Link to comment https://forums.phpfreaks.com/topic/61726-solved-setting-a-permanant-cookie/ 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 Link to comment https://forums.phpfreaks.com/topic/61726-solved-setting-a-permanant-cookie/#findComment-307284 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 Link to comment https://forums.phpfreaks.com/topic/61726-solved-setting-a-permanant-cookie/#findComment-307338 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. Link to comment https://forums.phpfreaks.com/topic/61726-solved-setting-a-permanant-cookie/#findComment-307350 Share on other sites More sharing options...
graham23s Posted July 25, 2007 Author Share Posted July 25, 2007 got it cheers charlie:) Graham Link to comment https://forums.phpfreaks.com/topic/61726-solved-setting-a-permanant-cookie/#findComment-307385 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. Link to comment https://forums.phpfreaks.com/topic/61726-solved-setting-a-permanant-cookie/#findComment-307395 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.