Useful PHP Snippets
  • How to stored visitors ip in sql database

  • Asked by Adnan on 8th Jun 2018

how to stored visitors ip in sql database please guide me

    Add Answer

    1 Answer

      • Saran

      Get the visitor’s IP address use $_SERVER['REMOTE_ADDR'] or $_SERVER['REMOTE_HOST'] variables in PHP, and simply create a database table with fields, using PHP code you can store the IP address to database table. For example :

      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      $user_name = "some name"; $ip_address = $_SERVER['REMOTE_ADDR']; $query = "INSERT INTO table (username, ip_address) VALUES(?, ?)"; $statement = $mysqli->prepare($query); $statement->bind_param('ss', $user_name, $ip_address); $statement->execute();

      For more info about MySqli usage see https://goo.gl

      Can You Answer this? Help us answer the question!

        • Answer
        Supports basic Markdown syntax.