Issues Questions How to stored visitors ip in sql database

asked on

how to stored visitors ip in sql database please guide me

    Add Answer
    All HTML codes will be stripped in the comment, except inline <code> HTML tag.
    1 Answer
    1 answered on

    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 :

    $user_name = "some name";
    $ip_address = $_SERVER['REMOTE_ADDR'];
    $query = "INSERT INTO table (username, ip_address) VALUES(?, ?)";
    $statement = $mysqli-&gt;prepare($query);
    $statement-&gt;bind_param('ss', $user_name, $ip_address);
    $statement-&gt;execute();

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

      All HTML codes will be stripped in the comment, except inline <code> HTML tag.

      Can You Answer this? Help us answer the question!

        • Answer
        Supports basic Markdown syntax. Excluded syntaxes (Headers, Lists, Blockquotes, Table, Images)