chinclub Posted May 1, 2007 Share Posted May 1, 2007 Is there a way I can restrict how many times a person can visit a page? Maybe with cookies or something? Link to comment https://forums.phpfreaks.com/topic/49529-solved-is-there-a-code-for-restricted-of-visits/ Share on other sites More sharing options...
paul2463 Posted May 1, 2007 Share Posted May 1, 2007 are you using a database??? do they log in??? if so have a column in the login table called 'visited' which is incremented every login check on each log in if it reaches a certain number direct them somewhere else Link to comment https://forums.phpfreaks.com/topic/49529-solved-is-there-a-code-for-restricted-of-visits/#findComment-242757 Share on other sites More sharing options...
clown[NOR] Posted May 1, 2007 Share Posted May 1, 2007 yes... set a cookie .. then every time he loads the page get the info from the cookie and then add 1 every time the person loads the page <?php if (!isset($_COOKIE['count'])) { $count = 1; } else { $count = $_COOKIE['count']; } $count = $count+1; if ($count > 5) { header("Location: newlocation"); } setcookie("count", $count, time()+3600); // <-- Cookie expires after 1 hour ?> think that should do the job Link to comment https://forums.phpfreaks.com/topic/49529-solved-is-there-a-code-for-restricted-of-visits/#findComment-242761 Share on other sites More sharing options...
chinclub Posted May 1, 2007 Author Share Posted May 1, 2007 Awesome!! That cookie code did the trick!! THANKS! Link to comment https://forums.phpfreaks.com/topic/49529-solved-is-there-a-code-for-restricted-of-visits/#findComment-242788 Share on other sites More sharing options...
roopurt18 Posted May 1, 2007 Share Posted May 1, 2007 And if I turn cookies off? Link to comment https://forums.phpfreaks.com/topic/49529-solved-is-there-a-code-for-restricted-of-visits/#findComment-242789 Share on other sites More sharing options...
Koobi Posted May 1, 2007 Share Posted May 1, 2007 cookies would work but they can be spoofed and as roopurt18 mentions, you can turn cookies off as well. if your users log in, your best bet would be to have a little column in this users table which contains the number of visits he's had to this page. increase the count in this table row for that customer on each visit and keep track via that table. if your users don't login, then i guess cookies would work best for you. but i think someone else might be able to answer this part better, hopefully as i'm not 100% sure of the best method for such a thing when the user is not logged in. Link to comment https://forums.phpfreaks.com/topic/49529-solved-is-there-a-code-for-restricted-of-visits/#findComment-242803 Share on other sites More sharing options...
roopurt18 Posted May 1, 2007 Share Posted May 1, 2007 If you don't use a login system where people have to identify themselves, then this is next to impossible. Cookies can be turned off or a user can just use a different computer. You can't do this based off IPs because users are assigned dynamic IPs and a company, library, university, etc. will have many machines mapped to a single outgoing IP. Link to comment https://forums.phpfreaks.com/topic/49529-solved-is-there-a-code-for-restricted-of-visits/#findComment-242824 Share on other sites More sharing options...
clown[NOR] Posted May 1, 2007 Share Posted May 1, 2007 ok... how about using $_SESSION instead? Link to comment https://forums.phpfreaks.com/topic/49529-solved-is-there-a-code-for-restricted-of-visits/#findComment-242827 Share on other sites More sharing options...
Koobi Posted May 1, 2007 Share Posted May 1, 2007 link=topic=138703.msg588249#msg588249 date=1178051805] ok... how about using $_SESSION instead? a session is...a session the moment you end that session by either leaving the site or a page (depending on how you have set it up), that session data is lost forever...unless you store it as a cookie or in the db. this is not PHP's fault, it's because HTTP is a stateless protocol. we wouldn't even need sessions for most things if HTTP wasn't stateless. Link to comment https://forums.phpfreaks.com/topic/49529-solved-is-there-a-code-for-restricted-of-visits/#findComment-242832 Share on other sites More sharing options...
clown[NOR] Posted May 1, 2007 Share Posted May 1, 2007 oh ok.. well then... i just have to agree with that DB would be the safest way to go Link to comment https://forums.phpfreaks.com/topic/49529-solved-is-there-a-code-for-restricted-of-visits/#findComment-242834 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.