Hi, Every user (IP) may open the index.php page just once. Can someone give me a good code for it. I know a bit of PHP but this hard for me to find. I know you can bypass this code using a proxy but that is not really a problem. If you use a proxy on my site you can't download large files. Index.php <?php include 'check.php'; ?> <html> CONTENT </html> PHP: Check.php ?? PHP:
The easiest way in my opinion would be to use sessions... they can of course just delete them though, so you may want to store the IPs in a database and check their IP against the database. Check.php would look something like this: <?php session_start(); $ip = $_SERVER['REMOTE_ADDR']; if(isset($_SESSION['ip']) && $ip == $_SESSION['ip']) { die("Error."); } else { $_SESSION['ip'] = $_SERVER['REMOTE_ADDR']; } ?> PHP:
If you were using a database would look something like: // MySQL connection info. $Data = mysql_fetch_assoc( mysql_query("SELECT COUNT(*) FROM visited WHERE ip = '" . $_SERVER['REMOTE_ADDR'] . "'") ); $Amount = (int) $Data['COUNT(*)']; if($Amount > 1) { exit; } PHP: Obviously should be improved on, but you get a rough idea.
Something like this maybe? <?php $ip = $_SERVER['REMOTE_ADDR']; $sql = mysql_query("SELECT * FROM `iplogs` WHERE `ip` = '$ip'"); $num = mysql_num_rows($sql); if($num == "0"){ //PAGE CONTENT GOES HERE mysql_query("INSERT INTO `iplogs` (`ip`) VALUES (`$ip`);"); }else { exit(); } ?> PHP: Might need editing or fixing.
Fixing is not really a problem. I have a lot of problems to find the correct code and to build it 'clean'. Thanks for those replies, it will help me out! How can they delete it?
That's because ThomasTwen was mistaken - $_SESSION and $_COOKIE are not the same The user could, theoretically, force a change of their SID to bypass but you're getting into the realms of unlikely. Just a note that, as the name implies, would allow them one access per session as opposed to one access for all eternity. That would require a database (SQL or text based). Finally, you should use require_once() rather than include(), firstly just as good practise (there are very few situations where a missing file should not throw a fatal error) but especially in this case as, were check.php not to be available for whatever warning, the user could then do whatever they wanted. Hope all that helps you
You would have to use something that the user doesn't have access to SESSIONS or DATABASE are alright for this situation. Cookies aren't as all they have to do is clear their browser and they can revisit the site.