Once a day page

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.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Jul 31st, 2007, 12:51
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jul 31st, 2007, 13:58
Reputable Member
Join Date: Apr 2007
Location: Scotland
Age: 17
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
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...

PHP: Select all

<?php

if(isset($_COOKIE['foo'])) { //check if cookie is set
 
echo('You may not view this content!'); //if not echo error messge
} else { //check if it's not set
 
echo('You may view this content only once.'); //echo message
 
setcookie('foo''bar'time() + (60 60 24)); //set the cookie. (see below)
}

?>
The setcookie function sets a cookie obviously. The first part is the cookie name. (Picked up through $_COOKIE['name']; )
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jul 31st, 2007, 14:40
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jul 31st, 2007, 14:51
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Once a day page

Yeah, you could log IPs in a database.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Jul 31st, 2007, 15:09
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Jul 31st, 2007, 16:59
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Jul 31st, 2007, 18:06
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
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....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Jul 31st, 2007, 18:14
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Once a day page

hmm cronjob?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Aug 1st, 2007, 06:25
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
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:

PHP: Select all

<?php
$view_time
=60*60*24// time in seconds that a viewer is not allowed to view the page again (24 hours)
$ip=getenv(REMOTE_ADDR); // get IP address
$current_timestamp=time(); // get current timestamp
$query=mysql_query("SELECT * FROM ip_log WHERE ip = '".$ip."' 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 {
    echo(
"Enjoy the content"); // OK
}
?>
I hope I'm understanding the question. Good Luck!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Aug 1st, 2007, 10:20
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Aug 1st, 2007, 10:22
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Once a day page

you know in :
PHP: Select all

else {
    echo(
"Enjoy the content"); // OK

should there be a code that also adds ip/username and timestamp to the database?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Aug 1st, 2007, 10:28
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old Aug 1st, 2007, 10:44
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old Aug 1st, 2007, 10:54
Reputable Member
Join Date: Apr 2007
Location: Scotland
Age: 17
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Once a day page

That's almost it. You forgot the Database name in your update statement though.

PHP: Select all

 $query2 "update log set timestamp = ".$current_timestamp." where username = ".$username."; 

That should work now. Just remember when making the database don't make the "timestamp" field a timestamp use something like varchar instead. MySQL times and PHP times are completely different so it would mess things right up.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #15  
Old Aug 1st, 2007, 12:56
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Once a day page

thanks
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
php, time

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT. The time now is 21:19.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved