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? Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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! Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted May 1, 2007 Share Posted May 1, 2007 And if I turn cookies off? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted May 1, 2007 Share Posted May 1, 2007 ok... how about using $_SESSION instead? Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.