Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: ip storing, then preventing that ip to access the same thing again

  1. #1
    Join Date
    Feb 2007
    Location
    Earth
    Posts
    133
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default ip storing, then preventing that ip to access the same thing again

    simple question

    how do you make a php code so that an ip address is stored in a mysql, then if they go back to that page a different thing comes up?

    (for instance... boxer gave me a good poll script but i dont want anyone voting more than once... so i want it to add the ip to the mysql table after they have voted on one thing (there are multiple polls on one page) it says they cant vote on it anymore)

    for instance examplesvote.php has 3 seperate polls on it, and once a person votes, it says they have voted... and writes on poll.txt... then when they try to vote again, it says "sorry you have already voted on this ip"

    for reference go to http://www.kalrith.com/vote.php to see what im talking about

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    This is a bad idea, since the user can use proxies to get around it. I have a friend who absolutely loves RapidShare: RapidShare uses this sort of system to ensure that an unregistered user can't download more than his/her fair share in a given timelimit, but my friend has dial-up, so he downloads, reconnects, and downloads again as many times as he likes.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Feb 2007
    Location
    Earth
    Posts
    133
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default

    a high percent of people dont know how to use proxies

    i really just want to know, besides if you have to log in, a lot of proxies dont let you log on to things without paying, so it is still a nice feature

    at least tell me a way i can prevent users from voting twice... i have already got that system completed where users can register, log on, and log off, so i guess i can make it so that they would have to re-register to vote again please

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You're forgetting, as well, that a lot of ISPs run users' requests through a proxy or web cache first, so by stopping one person from voting you might be stopping a whole region or perhaps even a whole country from voting (as seen with the Great Firewall of China).
    i have already got that system completed where users can register, log on, and log off, so i guess i can make it so that they would have to re-register to vote again please
    That's a much better idea. Obviously still bypassable, but it takes more effort and won't inconvenience innocent users.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    LOL great firewall of china - good one

  6. #6
    Join Date
    Feb 2007
    Location
    Earth
    Posts
    133
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default

    ok ok its a great idea but any examples so i can put it to use?

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Well, without knowing how your login system works, I can't modify it.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    if you wanted the poll code modified, you should have asked...
    ill get on it.
    EDIT:
    made changes to match yours. you'll only have to copy this new file over your old one.
    PHP Code:
    <?php
    $savefile 
    "save.txt";
    $ipfile "ip.txt";
    $cho $_POST['choice'];
    $address $_SERVER[REMOTE_ADDR];

    $mes = array(
    "File Not Found",
    "You, or someone using the same proxy or on the same network, have already voted.",
    "You picked choice number "$cho ."\r\n<br>Click <a href=\"?look\">Here</a> to View The Results."
    );
    $contentsave file_get_contents($savefile);
    $file explode("|",$contentsave);
    $contentip file_get_contents($ipfile);
    $ip explode("\r\n",$contentip);
    if(!
    $file || !$ip) {die($mes);};
    $in array_search($address$ip);

    if(isset(
    $cho)) {
      if(
    $ip[$in] == $address) {
        echo 
    $mes['1'];
      } else {
        
    $file[$cho]++;
        
    $data implode("|",$file);
    /* Save Poll Choice */
        
    $handle fopen($savefile,"w+");
        
    fwrite($handle,$data);
        
    fclose($handle);
    /* Write IP */
        
    $handip fopen($ipfile,"a+");
        
    fwrite($handip,$address ."\r\n");
        
    fclose($handip);
    /* Echo Out Choice Num */
        
    echo $mes['2'];
      };
    } elseif (isset(
    $_GET['look'])) { ?>

    #1 - Awesome: <?php echo $file['0']; ?><br>
    #2 - Ok: <?php echo $file['1']; ?><br>
    #3 - Terrible: <?php echo $file['2']; ?><br>

    <?php } else { ?>
    <form action="poll.php" method="post">

    #1 - Vote that the game is Awesome: <input type="radio" name="choice" value="0"><br>
    #2 - Vote that the game is Ok: <input type="radio" name="choice" value="1"><br>
    #3 - Vote that the game is Terrible:  <input type="radio" name="choice" value="2"><br>

    <input type="submit" value="Vote" name="Vote"></form>
    <?php };
    ?>
    Last edited by boxxertrumps; 02-27-2007 at 11:15 PM.
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  9. #9
    Join Date
    Feb 2007
    Location
    Earth
    Posts
    133
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default

    wow thanks! yet again a life saver! also that was me that added you on msn

  10. #10
    Join Date
    Feb 2007
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I use a system like that for the guestbook on my band's website and it works great. It blocks about half of the spam that we get. The rest is blocked by other means.

    Here are the relevant sections of code.

    Checking if an IP is blocked:

    Code:
    <?php
    
    include('../render/private/db_connect.inc');
    $query = "SELECT * FROM ban WHERE ip = '" . $REMOTE_ADDR . "'";
    $result = @mysql_query($query);
    if ($result)
    {
    	if (mysql_num_rows($result) != 0)
    	{
    		echo '<body>
    			Your IP address, ' . $REMOTE_ADDR . ', has been blocked.  This is likely because we have 
    			received a large volume of spam from your IP address.  Please contact Blake if you feel 
    			that this is a mistake.
    			</body></html>';
    
    		$query2 = "UPDATE ban SET blocks = blocks + 1 WHERE ip = '" . $REMOTE_ADDR . "'";
    		$result2 = @mysql_query($query2);
    		exit();
    	}
    }
    
    ?>
    Blocking or unblocking an IP

    Code:
    			$query = NULL;
    			$msgid = NULL;
    
    			if ($opt == 'block')
    			{
    				$query = "INSERT INTO ban (ip) VALUES ('" . $ip . "')";
    				$msgid = 'ib';
    			}
    			else if ($opt == 'unblock')
    			{
    				$query = "DELETE FROM ban WHERE ip = '" . $ip . "'";
    				$msgid = 'iu';
    			}
    			else
    			{
    				header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF'])
    					. "admin.php?action=NULL&msgid=ip");
    				exit();
    			}
    			
    			include('../render/private/db_connect.inc');
    			$result = @mysql_query($query);
    "Rock and roll ain't noise pollution." - AC/DC

    http://www.blake-foster.com

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •