gamemaster
02-02-2005, 06:26 AM
Greetings. I have a script that records user's time () within a field in a table let's say called $old_time. I want a snipet of code that simply checks if 24 hours has past . Can someone help me with this? Thanks.
![]() | View Full Version : Snipet Check 24 Hours - PHP gamemaster 02-02-2005, 06:26 AM Greetings. I have a script that records user's time () within a field in a table let's say called $old_time. I want a snipet of code that simply checks if 24 hours has past . Can someone help me with this? Thanks. Jason.NXH 02-02-2005, 06:33 AM Hmm, you would have to convert the user time string into a UNIX timestamp (if it's not already displayed as one). You would then have to make a new string (e.g: $new_time) which records the latest time they have visited. After this, you would probably have to make an equation such as:$time_difference = $new_time - $old_time;Which should give you the difference in seconds. Then you would need an IF function such as:if ($time_difference >= "86400") { echo "whatever"; }I have never actually seen a script that grabs the time from the user, only the server. If you could paste the script or the command which grabs the user time, I could probably add the things for you gamemaster 02-02-2005, 06:40 AM if (whatever) { $curtime = time(); $DB->query("UPDATE field with $curtime); } The above places the time stamp in field. This code is supposed to check the 24 hours, but does not work: $last_time_from_database = (call to field) $old_date=date("z",$last_time_from_database); $new_date=date("z"); if($new_date != $old_date){ Thanks for your help Jason.NXH 02-02-2005, 07:10 AM I will put together a quick script, but just one quick question: - What is this script meant to do, is it meant to just tell you how many times they have visited in the last 24 hours? or something else? gamemaster 02-02-2005, 07:32 AM The script checks when last they were on a certain page. If 24 hours have not passed since their last visit then it will not let them have access to certain code on that page. Jason.NXH 02-02-2005, 07:38 AM Ok, well I will just quickly piece together a small script of my own Jason.NXH 02-02-2005, 07:46 AM Hmm, actually harder than I thought. It's not hard to write but it is when you don't know anything about what your writing it for :P I can give it a shot if you like, but it will be alot different from yours and probably won't make any sense to you gamemaster 02-02-2005, 08:46 AM It's not hard to write but it is when you don't know anything about what your writing it for Huh? As I said before... The script checks when last they were on a certain page. If 24 hours have not passed since their last visit It is nothing technical - you visit a page the current time is placed in a field. When you come back to the page (whenever that is) it checks to see if 24 hours have passed - that's it. gamemaster 02-03-2005, 10:01 AM No experts out there that can simply tell me the code needed to check if 24 hours have passed? ;) Dan L 02-03-2005, 08:51 PM <?php if((time() - $_COOKIE['time']) >= 86400) { die('Your session has expired.'); } else { setcookie('time',time()); } ?> Easy enough. gamemaster 02-03-2005, 09:53 PM Thanks for the cookie idea, that may come in handy for something else. I was able to solve this issue by using date("z"); instead of time(): Dan L 02-03-2005, 09:58 PM Using date("z"); would be inaccurate. As far as I know, it only records the day, which means if you log in at 11:59, in one minute your session has expired. gamemaster 02-03-2005, 10:01 PM I rather that as nowadays most users know how to clear cookies. Dan L 02-03-2005, 10:20 PM Yes, but where are you storing your date() information? A database? Also, why would a user want to clear their cookies? The cookie sets the last time that they accessed a page on your site. If the cookie is old, or does not exist, then the user is viewed as "logged in." gamemaster 02-03-2005, 10:24 PM Yes in the DB. Why clear cookies - easy - to cheat. Dan L 02-03-2005, 10:32 PM But clearing the cookies would log them out. How is that cheating? If you have a database, I'd just hire someone to do it for you, since it's impossible for someone to give you working code without even seeing the script. gamemaster 02-03-2005, 10:37 PM Thanks for all your tips, I have it already taken care of and it works good for me. innova 02-04-2005, 11:14 AM Just a tip.. You shouldnt come in here and get all testy when people trying to help you provide tips you dont agree with. If you wanted to use date("z") so bad, just write the script yourself. Sheesh. gamemaster 02-04-2005, 11:05 PM Innova what the heck are you talking about? Seems like you are the one that is 'testy' as you have become judge and juror or moderator - lol *shaking head*. It is amazing how sensitive people get in a discussion they are not even part of... please. Anyway, the point is DanX, is trying to convince me to use something for which I am trying to explain to him I do not need for my purposes - I did mention that his code is great for something else - you will note - I never did diclose exactly what the code is to be used for and therefore and external onlooker cannot know better than me what will work and what will not. |