This is a discussion on "Once a day page" within the PHP Forum section. This forum, and the thread "Once a day page are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Once a day page
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
||||
|
Once a day page
I was wondering if anyone knows of a script that will be shown to a user,
then they are taken away from it and cannot visit it again for a certain amount of time (12 hours, a day, a week etc.) The problem i see, is that if i store it in a session or something and the user logs out, when they log back in shouldn't they be able to see the page again?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
|
|
|||
|
Re: Once a day page
Try setting a cookie. That stays on their hard drive for as long as you tell it to, so unless they delete it you can keep the person from viewing the content as long as you want.
try something like this...
The second part is it's value or what it contains. (Accessed through $_COOKIE['name']['value']; ) The third part is how long it's set. In this case I have used the functuion time() which is now, plus 60 x 60 x 24 which equals one day. You can change that to however long you want. Hope that all makes sense. Blake |
|
||||
|
Re: Once a day page
I will settle for that unless there's a foolproof way.
so that if they delete the cookie it stills works. is there a way i can set it on the server, like a value on a mysql database that resets every 24 hours?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
||||
|
Re: Once a day page
Yeah, you could log IPs in a database.
Last Blog Entry: 10 Reasons Why My Laptop Is Better Than Your Girlfriend (Dec 15th, 2007)
|
|
||||
|
Re: Once a day page
say i have a mysql table:
-------------------- |username |timedpage| --------------------- |alex | 1 | --------------------- is there a way to check the if the user has a value of 1 for the timedpage column, then reset it to 0 after 24 hours? if that makes sense
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
||||
|
Re: Once a day page
i don't know if this will work:
have a column that starts off as todays date, if when they go to this page, it adds one day to the date in the database, on the page it checks if the user's value is equal to the todays date, if the date is correct they can see the page, if the date is for tomorrow they can't. then the next day comes and it will be the right date and they can see it. make sense?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
||||
|
Re: Once a day page
Yup, it does.
But what if the user doesn't visit the page for a few days and then comes back....
Last Blog Entry: 10 Reasons Why My Laptop Is Better Than Your Girlfriend (Dec 15th, 2007)
|
|
||||
|
Re: Once a day page
hmm cronjob?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
||||
|
Re: Once a day page
NOOOO... it does not need to be that complicated.
You have a database that looks, for example like this: id | ip | timestamp. Then, when someone views the page, you get their IP and check your database for that IP. If it is not there, you add their IP and the current timestamp. If it is there, you use the timestamp to check if the user is allowed to view the page. Here's some pseudo-code. Haven't tested it but something like this should do the trick:
Last Blog Entry: 10 Reasons Why My Laptop Is Better Than Your Girlfriend (Dec 15th, 2007)
|
|
||||
|
Re: Once a day page
i'm going to use that to try and change it to users instead of an IP thanks
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
||||
|
Re: Once a day page
you know in :
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
||||
|
Re: Once a day page
Yup, you're right. Sorry, I forgot that. You could also delete all the entries that are older than the 'ban' time because they are no longer needed.
Last Blog Entry: 10 Reasons Why My Laptop Is Better Than Your Girlfriend (Dec 15th, 2007)
|
|
||||
|
Re: Once a day page
So would the full code be:
<?php $view_time=60*60*24; // time in seconds that a viewer is not allowed to view the page again (24 hours) $username = $_SESSION['loggedin'] $current_timestamp=time(); // get current timestamp $query=mysql_query("SELECT * FROM log WHERE username = '".$username."' AND timestamp > '".($current_timestamp-$view_time)."'"); if(mysql_num_rows($query) > 0) { // check if any ip was found echo("You are not allowed to view this page"); // not OK } else { $query2 = "update set timestamp = ".$current_timestamp." where username = ".$username."; $updatelog = mysql_query($query2) or die(mysql_error()); echo("Enjoy the content"); // OK } ?>
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
|||
|
Re: Once a day page
That's almost it. You forgot the Database name in your update statement though.
|
|
||||
|
Re: Once a day page
thanks
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
![]() |
| Tags |
| php, time |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Best way to prevent access to page B except via page A? | Donny Bahama | PHP Forum | 1 | Apr 3rd, 2008 02:15 |
| Green bar of colour at bottom of page gets bigger the more page is extended | pixelgirl | Web Page Design | 1 | Apr 1st, 2008 01:27 |
| internal navigation, Linking from one page to a specific div in another page. | Oak | Web Page Design | 5 | Feb 8th, 2008 22:54 |
| Linking an outside page back to previous framed page | MJustison | Starting Out | 1 | Oct 18th, 2007 17:49 |
| A gap appears beween the Page Title and the Body Content of the page. | sovereign6 | Web Page Design | 6 | Dec 18th, 2006 19:14 |