limitphp Posted November 3, 2008 Share Posted November 3, 2008 I set a cookie with this: setcookie("nwo",$tempID, time()+3600*24*365); When I check if the cookie is set with this: if (isset($_COOKIE['nwo'])) { } how do i check the expirationDate? thanks, php 5.2.6 Link to comment https://forums.phpfreaks.com/topic/131196-solved-how-to-check-expired-cookie/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 3, 2008 Share Posted November 3, 2008 You cannot. The browser only sends the cookie name and value to the web server. What are you trying to accomplish? Link to comment https://forums.phpfreaks.com/topic/131196-solved-how-to-check-expired-cookie/#findComment-681159 Share on other sites More sharing options...
limitphp Posted November 3, 2008 Author Share Posted November 3, 2008 You cannot. The browser only sends the cookie name and value to the web server. What are you trying to accomplish? I'm trying to create a login system where users can select "remember me" and come back to the site without logging in. So, I set a tempID in the cookie and then put that tempID in a table along with their userID. Here's my code so far for if ($mode==1){ $query = "SELECT * FROM user WHERE username = '$username' AND password = '$password'"; $result = mysql_query($query); $data = mysql_fetch_assoc($result); $userID = $data['userID']; $username = $data['username']; $fname = $data['fname']; if ($data<>""){ $loginExist=1; $tempID = md5(uniqid(rand(),true)); setcookie("nwo",$tempID, time()+3600*24*365); mysql_query("INSERT INTO tempTable (tempID, userID, expirationDate) VALUES ('$tempID', '$userID', 'time()+3600*24*365')"); }else{ $loginExist=0; } } if (isset($_COOKIE['nwo'])) { } So, if the cookie is set, then that means it must not be expired? Link to comment https://forums.phpfreaks.com/topic/131196-solved-how-to-check-expired-cookie/#findComment-681164 Share on other sites More sharing options...
revraz Posted November 3, 2008 Share Posted November 3, 2008 Yes if the cookie is present, it's valid. Once it expires, it is removed. Link to comment https://forums.phpfreaks.com/topic/131196-solved-how-to-check-expired-cookie/#findComment-681170 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.