Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2009
    Posts
    45
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Trace an IP via submitting a comment

    Is there anyway I can get someones IP when they click submit on one of my forms, it's a comment page and I don't want spammers. I have some moderators, but I want them to be able to do stuff. I can store the IP in my database, but I want to know how do I get the IP from users?

    Does anyone have any scripts, or tutorials? Thanks, and I really appreciate the help.

    (I'm sorry I've been posting so many help threads, I'm working on a script of mine and I want it to be perfect, and see if their are some different ways to do things.)

  • #2
    New Coder
    Join Date
    Jan 2009
    Posts
    45
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Anyone?

  • #3
    Regular Coder
    Join Date
    Oct 2009
    Posts
    438
    Thanks
    9
    Thanked 7 Times in 7 Posts

  • Users who have thanked treeleaf20 for this post:

    SRBuckey5266 (10-14-2009)

  • #4
    New Coder
    Join Date
    Jan 2009
    Posts
    45
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I've added it, but why doesn't it submit the IP to the database?

    Code:

    PHP Code:
    <center><style type="text/css">

    a:link {
    color:#24374C;
    text-decoration:bold;
    }

    a:visited {
    color:#24374C;
    text-decoration:bold;
    }

    a:active {
     outline: none;
     color:#24374C;
     text-decoration:bold;
    }

    body {background-color:#b0c4de}

    hr.{backround-color:#b0c4de}

    div.box {
    width:265px;
    padding:10px;
    border:3px double #000000;
    margin:10px;
    background-color:#74AFF2;
    }
    </style>
    <?php

    $con 
    mysql_connect('''''') or die(mysql_errno());
    if (
    function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
    {
        
    $_POST array_map('stripslashes'$_POST);
    }

    $name mysql_real_escape_string($_POST['name']);
    $message mysql_real_escape_string($_POST['message']);

    if (
    strlen($message)<=1
        echo 
    "<div class='box'><b><span style='color:red'>Please enter a message!</span></b></div>";
    else 
    {

    function 
    validip($ip) {
     
    if (!empty(
    $ip) && ip2long($ip)!=-1) {
     
    $reserved_ips = array (
     
     array(
    '255.255.255.0','255.255.255.255')
     
    );
     
     
    foreach (
    $reserved_ips as $r) {
     
    $min ip2long($r[0]);
     
    $max ip2long($r[1]);
     
    if ((
    ip2long($ip) >= $min) && (ip2long($ip) <= $max)) return false;
     
    }
     
    return 
    true;
     
    } else {
     
    return 
    false;
     
    }
     }
     
     function 
    getip() {
     
    if (
    validip($_SERVER["HTTP_CLIENT_IP"])) {
     
    return 
    $_SERVER["HTTP_CLIENT_IP"];
     
    }
     
    foreach (
    explode(",",$_SERVER["HTTP_X_FORWARDED_FOR"]) as $ip) {
     
    if (
    validip(trim($ip))) {
     
    return 
    $ip;
     
    }
     
    }
     
    if (
    validip($_SERVER["HTTP_X_FORWARDED"])) {
     
    return 
    $_SERVER["HTTP_X_FORWARDED"];
     
    } elseif (
    validip($_SERVER["HTTP_FORWARDED_FOR"])) {
     
    return 
    $_SERVER["HTTP_FORWARDED_FOR"];
     
    } elseif (
    validip($_SERVER["HTTP_FORWARDED"])) {
     
    return 
    $_SERVER["HTTP_FORWARDED"];
     
    } elseif (
    validip($_SERVER["HTTP_X_FORWARDED"])) {
     
    return 
    $_SERVER["HTTP_X_FORWARDED"];
     
    } else {
     
    return 
    $_SERVER["REMOTE_ADDR"];
     
    }
     }

     
    //connect
    $connect mysql_connect("","","") or die("Connection failed!");
    mysql_select_db("") or die("Database fail!");

    //write
    $write mysql_query("INSERT INTO posts VALUES ('','$name','$message', '$ip')") or die(mysql_eror());

    echo 
    "<div class='box'><font face='arial'><b><span style='color:green'>Posted! Your name was:</span> $name</b> - Your message was....<br><br><b>$message - <a href='index.php'>View it!</a></b>";
    }


    ?>
    Last edited by SRBuckey5266; 10-14-2009 at 04:15 AM.


  •  

    Posting Permissions

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