简体   繁体   English

输入表单时跟踪客户端IP地址并存储在SQL表中

[英]Track client IP address and store in SQL table while entering form

I have PHP form processing data to sql table i have two input field 我有PHP表格处理数据到SQL表我有两个输入字段

  • i need a hidden field that hidden field should track client IP address and when form is submitted i need the client address also save in table 我需要一个隐藏字段,该隐藏字段应该跟踪客户端IP地址,并且在提交表单时我也需要将客户端地址保存在表格中

PHP form processing PHP表格处理

<?php
$db_username = "sanoj";
$db_password = "123456";
try {
#connection 
$conn = new PDO('mysql:host=localhost;dbname=localtest', $db_username, $db_password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$data = $conn->prepare('INSERT INTO test (first, last) VALUES (:first, :last)');
$first = filter_input(INPUT_POST, 'first', FILTER_SANITIZE_STRING);
$last = filter_input(INPUT_POST, 'last', FILTER_SANITIZE_STRING);
$data->execute(array(':first' => $first, ':last' => $last,));
#exception handiling
} catch (PDOException $e) {
echo $e->getMessage();
}
?>

can some one help me i found example and its hard to understand these code given in What is the most accurate way to retrieve a user's correct IP address in PHP? 我能找到一个示例吗?在PHP中检索用户正确IP地址的最准确方法是什么? since new to php 自从PHP新手
thanks in advance 提前致谢

我将用它来检索某人的IP

$_SERVER["REMOTE_ADDR"]
$REMOTE_ADDR = $_SERVER['REMOTE_ADDR'];/*add this line*/
$data->execute(array(':first' => $first, ':last' => $last, ':REMOTE_ADDR' => $REMOTE_ADDR));/* edit this line*/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM