Jump to content

[SOLVED] Is there a code for restricted # of visits


chinclub

Recommended Posts

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

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.

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=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.

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.