Jump to content

Time Access


wwedude

Recommended Posts

once you distinguish a 'user', you can just log in a database when they visit a page, and then restrict them from doing so again for specific amount of time....that is the easy part

 

the hard part is distinguishing a 'user'. if you have a login/pass set up already, you are good to go. but if it's just anonymous users, there is no full proof way. you can log their IP, but that can be spoofed. you can use a cookie, but those can be disabled/manipulated.

 

...hope that helps

Link to comment
https://forums.phpfreaks.com/topic/121739-time-access/#findComment-628021
Share on other sites

The following methods do work (and downfalls explained):

 

1.) IP Logging

2.) Cookies

3.) Sessions

 

1.) An IP can be changed by many methods (such as proxies) and it also can be random based on their choice of web browser (such as AOL for instance).

2.) Cookies can be disabled, deleted, and possibly manipulated (for those skilled in cookie manipulation)

3.) Sessions time-out when the browser closes (unless you otherwise define it, but then it becomes almost identical to a cookie)

Link to comment
https://forums.phpfreaks.com/topic/121739-time-access/#findComment-628028
Share on other sites

once you distinguish a 'user', you can just log in a database when they visit a page, and then restrict them from doing so again for specific amount of time....that is the easy part

 

the hard part is distinguishing a 'user'. if you have a login/pass set up already, you are good to go. but if it's just anonymous users, there is no full proof way. you can log their IP, but that can be spoofed. you can use a cookie, but those can be disabled/manipulated.

 

...hope that helps

 

I do have a user system, and I will be requiring login to access this page. So what I would do, is access the database, see when they last visited, and seeing if that is less than x amount.?

Link to comment
https://forums.phpfreaks.com/topic/121739-time-access/#findComment-628030
Share on other sites

so yeah, just add a column to your users table (or create a new table that you can do a JOIN with). make the column an INT or a DATETIME type. The following code assumes it's an INT type and should be put at the top of that page.

 

<?php
  //Put the code that confirms the person is logged in here
  //Assuming the user's unique identifier is $userid

  //Select the value from the lastVisit field and store it into $lastVisit
  list($lastVisit) = mysql_fetch_array(mysql_query("SELECT `lastVisit` FROM `users` WHERE `userid` = '{$userid}' LIMIT 1"));

  //Check the time
  $diff = 60 * 60 * 24; //1 day in seconds
  if($lastVisit && time() - $lastVisit < $diff){
    print "Denied";
    exit;
  }

  //Update table
  mysql_query("UPDATE `users` SET `lastVisit` = '".time()"' WHERE `userid` = '{$userid}' LIMIT 1");

  //Continue with page
?>

Link to comment
https://forums.phpfreaks.com/topic/121739-time-access/#findComment-628091
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.