데이터베이스에 IP를 쓰는 데 문제가 있습니다. $ip=$_SERVER['REMOTE_ADDR'];
뒤에 $ ip를 출력하면 54.231.128.128을 얻습니다. 하지만 데이터베이스에 ip를 삽입하면 203223이 삽입됩니다. 여기에 제 코드가 있습니다.데이터베이스에 IP 주소가 잘못 입력되었습니다.
<?php include "db.php";
session_start();
$toemail=$_POST["toemail"];
$report=$_POST["report"];
$ip=$_SERVER['REMOTE_ADDR'];
$fromemail=$_SESSION['nahid'];
$date=(time());
$tatus="Active";
if(!$_POST['submit']) {
echo "Please fill out the form";
} else {
// $query_auto = "INSERT INTO form (date, time) VALUE ('DATE: Auto CURDATE()', CURDATE())";
mysql_query("INSERT INTO report(`id`, `from`, `msg`, `to`, `date`, `ip`, `status`)
VALUES(NULL,'$fromemail','$report','$toemail','$date', '$ip', '$tatus')") or die(mysql_error());
header('Location: report_congratulations.php');
}
?>
데이터베이스의 IP 열은 어떤 유형입니까? – Neat
** 위험 ** : [오래된 ** 데이터베이스 API] (http://stackoverflow.com/q/12859942/19068)를 사용하고 있으며 [최신 대체] (http : // php. net/manual/ko/mysqlinfo.api.choosing.php). 또한 ** [SQL 주입 공격] (http://bobby-tables.com/) **에 현대적인 API를 사용하면 쉽게 방어 할 수 있습니다 ** (http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php)을 사용하십시오. – Quentin
ip 열 유형은 varchar 여야합니다. 그렇지 않으면 ip를 number로 변환하기 위해'ip2long' PHP 함수를 사용할 수 있습니다. 검색 할 때'long2ip'을 사용하여 IP로 다시 변환하십시오 –