View Single Post
  #2 (permalink)  
Old 06-14-2009, 04:57 AM
DBLL DBLL is offline
WebProWorld Member
 
Join Date: Jan 2009
Posts: 26
DBLL RepRank 0
Default Re: IP address blocking question???

The first method which comes to my mind, seems more like one of those solutions you throw out in lack of better.

Anyway, can be done by adding an extra feild to the content table in your database, then simply save the ips in this field, as a comma separated list.

If you are using php, something like below would get the job done.
Code:
$Iplist = "xxx.xxx.xxx.xxx,xxx.xxx.xxx.xxx,xxx.xxx.xxx.xxx,xxx.xxx.xxx.xxx";
$TheIPs = explode(',', $Iplist);
echo $TheIPs[0]; // The First Ip
echo $TheIPs[1]; // The Second Ip 
Now you simply need to run them through a loop, and check when the users ip is found in the list. I.e.
Code:
$Iplist = "xxx.xxx.xxx.xxx,xxx.xxx.xxx.xxx,xxx.xxx.xxx.xxx,xxx.xxx.xxx.xxx";
$TheIPs = explode(',', $Iplist);
foreach ($TheIPs as &$TheIPs) {
  if ($TheIPs == $_SERVER["REMOTE_ADDR"]) {
    echo 'You already viewed this once! What are you doing?!';
    exit();
  }
}
Edit
The above however creates an issue, since you would need to use a very large datatype, to make room enough for all your users. Generally this wouldn't be a problem, since you would need a lot of users to reach the limit. But it also creates a performance issue, cursed by looping through the ips, and checking each of them.


I therefor believe it will be more efficient to simply make another table, and save the PostID of the entry in that table, along with the Username of whoever viewed it. The Username should be used as the primery index. Then simply run a select query when the user requests the page, to see if he or she has viewed it before.

That would be done like below.

Code:
$Query = mysql_query("SELECT PostID, UserID FROM Viewed_Enteries WHERE UserID = 'UserName'", $Connection);
  if ($Query != false) {
 echo 'You already viewed this once! What are you doing?!';
 exit();
} else {
 echo 'Welcome!' . $UserID;
   mysql_query("INSERT INTO Viewed_Enteries (PostID, UserID) VALUES (
 '11',
 '$UserID')", $Connection) or die(mysql_error());
}
__________________
The Blood of the Lamb is my Breakfast.

Last edited by DBLL; 06-14-2009 at 05:39 AM.
Reply With Quote