Jump to content

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


chinclub

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.