Results 1 to 8 of 8

Thread: Ip

  1. #1
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default Ip

    how i can detect visitors IP?? i have sessions script if needed.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    The following PHP snippet displays the IP address of the visitor to the page.

    Code:
    <?php
     echo $_SERVER['REMOTE_ADDR'];
    ?>
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    but what if i want to save ip on sql?? maybe i need to save it when they registering? thanks

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    PHP Code:
    $userIP $_SERVER['REMOTE_ADDR'];
    // adjust SQL to suit your table/other values
    // use UPDATE instead if you're updating existing rows
    $IPsql mysql_real_escape_string("INSERT INTO userIPaddr (userIP) values ('$userIP')");
    //assumes you have already connected to your DB
    mysql_query($IPsql); 
    however, note that even under normal circumstances, many users may not have the same IP every time they connect - so using the IP to validate something (if that's what you're trying to do) won't always work.

  5. The Following User Says Thank You to traq For This Useful Post:

    auriaks (10-21-2009)

  6. #5
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    That's true, especially with networks, where there are many people connected, whose information is all passed as one IP by the router, so if you have one person in that network whose paid for a service, and you allow them access, it could mean that everyone else on that network could get through too.

    It would also work the other way round, where someone might be blocked, and then it block everyone on the network, which may cause more problems.

  7. #6
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    I don't want to create IP ban or smth... thanks for warnings TRAQ, all lines i have to write after connection script?? and what variables i have to create in the db->table to fit your written script? Many thanks..

  8. #7
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    what database columns? In my example above, I used the column name "userIP". You could name it anything you wanted.

  9. #8
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    It works... thx Can you take a look to this Q?? Question for rewriting script
    Last edited by auriaks; 10-21-2009 at 08:19 PM.

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
  •