Note that there are some explanatory texts on larger screens.

plurals
  1. PORetrieve users' IP addresses and store them in a database table?
    text
    copied!<p>I have a MySQL query that inserts the content of a form into my database.</p> <p>Along side inserting these values, I also want to discover and insert the users IP address. This is for the site's protection. This way if a user is constantly posting harmful content their ip can be blocked.</p> <p>Here's my script. I am trying to use <code>" . $_SERVER['REMOTE_ADDR'] . "</code> but its not working for me. Can someone please show me a way of doing this.</p> <p>I'm trying to store the IP in a column in my table called 'ip' (int(10) Atributes: UNSIGNED NULL:No Default:None)</p> <p>UPDATE:</p> <p>When I change the column 'ip' to a VARCHAR(48) I get this printed in the column rather than a full IP: <code>::1</code></p> <pre><code>&lt;?php ob_start(); // check if the review form has been sent if(isset($_POST['review_content'])) { if(isset($_POST['review_recipient'])) { $content = $_POST['review_content']; $review_recipient = $_POST['review_recipient']; //We remove slashes depending on the configuration if(get_magic_quotes_gpc()) { $content = stripslashes($content); $review_recipient = stripslashes($review_recipient); } $regex = "/(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w\.-]*)*\/?/"; $replacement = "[blocked url]"; $regex2 = "/(.*)\b(BLOCKED WORDS GO HERE!!!!)\b(.*)/"; $replacement2 = "[blocked content]&lt;br/&gt;&lt;br/&gt;This content was blocked because it was deemed offensive or inappropriate."; $replacement3 = "[blocked username]"; $review_recipient = preg_replace(Array($regex, $regex2),Array($replacement, $replacement3),$_POST['review_recipient']); //$profile_id = intval($_POST['profile_id']); //dont know how you get this $content = preg_replace(Array($regex, $regex2),Array($replacement, $replacement2),$_POST['review_content']); //We check if all the fields are filled if($_POST['review_content']!='') { if($_POST['review_recipient']!='') { $sql = "INSERT INTO ptb_reviews (id, from_user_id, from_guest, ip, to_user_id, content) VALUES (NULL, '-1', '".$review_recipient."', '" . $_SERVER['REMOTE_ADDR'] . "', '".$profile_id."', '".$content."');"; mysql_query($sql, $connection); $_SESSION['message']="&lt;div class=\"infobox-review-sent\"&gt;&lt;strong&gt;Thank You&lt;/strong&gt; - Your review has been sent and is awaiting approval.&lt;/div&gt;&lt;div class=\"infobox-close4\"&gt;&lt;/div&gt;"; header("Location: {$_SERVER['HTTP_REFERER']}"); } } } } } } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload