フォームのコンテンツをデータベースに挿入する MySQL クエリがあります。
これらの値を挿入するだけでなく、ユーザーの IP アドレスも検出して挿入したいと考えています。これは、サイトの保護のためです。このようにして、ユーザーが有害なコンテンツを絶えず投稿している場合、IP をブロックできます。
これが私のスクリプトです。使用しようとしています" . $_SERVER['REMOTE_ADDR'] . "
が、うまくいきません。誰かがこれを行う方法を教えてください。
「ip」というテーブルの列に IP を保存しようとしています (int(10) 属性: UNSIGNED NULL:No Default:None)
アップデート:
列「ip」を VARCHAR(48) に変更すると、完全な IP ではなく列に次のように出力されます。::1
<?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]<br/><br/>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']="<div class=\"infobox-review-sent\"><strong>Thank You</strong> - Your review has been sent and is awaiting approval.</div><div class=\"infobox-close4\"></div>";
header("Location: {$_SERVER['HTTP_REFERER']}");
}
}
}
} } }
?>