iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-31-2009, 06:11 PM
james113's Avatar
WebProWorld Pro
 
Join Date: Jun 2004
Location: Hillsboro, Illinois
Posts: 145
james113 RepRank 2
Default IP address blocking question???

I want to create a poll on my website that can only be viewed by each member of my site one time only. I imagine that the page would have to record the users IP address somehow when viewed, and then initiate a redirect to any user trying to access the page a second time. Does anyone know what kind of coding is required to do this??? Thanks
__________________
James Allen
Reply With Quote
  #2 (permalink)  
Old 06-14-2009, 04:57 AM
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
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Blocking non-US IPs? mrl72 IT Discussion Forum 20 03-30-2009 10:38 PM
IP Blocking whatever Webmaster Resources Discussion Forum 3 06-04-2008 07:07 PM
Keywords in Address Bar? *question* jawn_tech Google Discussion Forum 16 04-01-2008 12:55 PM
Blocking a country IP address does it harm??? Steven1976a Search Engine Optimization Forum 10 01-09-2006 04:36 PM
Pop up blocking Greyhawk The Castle Breakroom (General: Any Topic) 7 01-29-2004 09:43 AM


All times are GMT -4. The time now is 12:47 PM.



Search Engine Optimization by vBSEO 3.3.0