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 9 of 9
  1. #1
    Regular Coder
    Join Date
    Feb 2010
    Posts
    130
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Track down ip address on a database submission form?

    Is there any way I can do a php or sql code where a person submits data into a database using a form and their ip address is also submitted? Some sites have this such as wikipedia where if a user submits information, their ip information is put into the database. Does anyone know the code?

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    PHP Code:
    $ip=@$REMOTE_ADDR;
    echo 
    "<b>$ip</b>"
    The above would display an IP like this 71.53.210.46

    IP address if the register_global is off
    If at php.ini if register_global is set to Off then we have to change the script a bit to get the address. Here it is

    PHP Code:
    $ip=$_SERVER['REMOTE_ADDR']; 
    Then for your database query, just make a field for ipaddress and insert or update $ip
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #3
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Just to note you shouldn't have register globals on ever. It's very bad practice
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #4
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Correct, but just in case, I included both
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #5
    Regular Coder
    Join Date
    Feb 2010
    Posts
    130
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Out of curiosity...so the
    Code:
    $ip=$_SERVER['REMOTE_ADDR'];
    code captures the ip address?

    What code do I use to inset the captures ip address into the database? This is what I got:

    Code:
    //Insert IP address to database
    mysql_query("INSERT INTO quest (IPAddress) VALUES('$ip')") or die (mysql_error());
    
                    $quest_ipaddress=$_SERVER['IPAddress'];

  • #6
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    A good coder would gather all the data needed before sending it to the database because I have seen your code and your inserting a few times into the same database table which will missmatch the data and insert more than 1 row at a time, once you validate all the submitted data and its all correct thats when you should insert the data into the database table. And your also asking a question you could easerly find or a SEO such as google.
    Last edited by DJCMBear; 03-24-2010 at 07:13 AM.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #7
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DJCMBear View Post
    A good coder would gather all the data needed before sending it to the database because I have seen your code and your inserting a few times into the same database table which will missmatch the data and insert more than 1 row at a time, once you validate all the submitted data and its all correct thats when you should insert the data into the database table. And your also asking a question you could easerly find or a SEO such as google.
    One question I would like to follow up on is do you have to have 25 posts under your belt to purchase from a swap master?OR just to sell?
    _____________________
    Print koozies | Koozie printing

  • #8
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Quote Originally Posted by crazykid View Post
    Out of curiosity...so the
    Code:
    $ip=$_SERVER['REMOTE_ADDR'];
    code captures the ip address?

    What code do I use to inset the captures ip address into the database? This is what I got:

    Code:
    //Insert IP address to database
    mysql_query("INSERT INTO quest (IPAddress) VALUES('$ip')") or die (mysql_error());
    
                    $quest_ipaddress=$_SERVER['IPAddress'];
    Basically yes this is correct.
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #9
    New to the CF scene
    Join Date
    Mar 2011
    Location
    Hong Kong
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by JAY6390 View Post
    Just to note you shouldn't have register globals on ever. It's very bad practice
    Sorry, I am not a programmer. I'm developing a new company and I need a developer, so do you mind if I ask you why global is bad? Should I be telling a developer I don't want this? Thanks. I really appreciate it if you have time to reply. Lin


  •  

    Posting Permissions

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