addBoard.php中获取到ip
$ip=$_SERVER['REMOTE_ADDR'];
通过ajax采取POST方式发送到服务器
$("#submit").on("click",function(){ pcontent = $("#contain").val(); check(); ip=$("#username").attr("data-ip"); $.ajax({ url: "handle.php", dataType: "json", type: "POST", data: { type:"addboard",f_name:title,f_desc:pcontent}, success:function(data){ $("#notice").html("添加成功") console.log(data.toString()); }, error:function(data){ console.log(data); $("#notice").html("添加失败,请稍后再试"); } }); })
服务器端获取到数据,并写入数据库,即可记录ip
$f_ip=isset( $_POST['ip'])?$_POST['ip']:"";
$sql="INSERT into t_article (f_parent_id, f_title, f_username, f_board_id,f_post_time, f_ip) values"; $sql.="('".$f_parent_id."','".$f_title."','".$f_username."','".$f_board_id."','".$f_post_time."','".$f_ip."')"; $rs1=$conn->query($sql); $ttt=mysqli_insert_id($conn);