我正在尝试将div显示到特定的IP地址。我该怎么做呢?
谢谢!
答案 0 :(得分:7)
if ( $_SERVER['REMOTE_ADDR'] == '192.168.1.114' )
// show the div
答案 1 :(得分:2)
if (isset($_SERVER["REMOTE_ADDR"])){$ip = $_SERVER["REMOTE_ADDR"];}
else if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];}
else if ( isset($_SERVER["HTTP_CLIENT_IP"])){$ip = $_SERVER["HTTP_CLIENT_IP"];}
if($ip == 'xxx.xxx.xxx'){echo '<div>special content</div>';}
答案 2 :(得分:2)
最简单的就是:
<?php
if($_SERVER['REMOTE_ADDR'] == "127.0.0.1")
{
echo "<div>Nothing beats home</div>";
}
?>
请注意,如果服务器位于NAT后面,如果使用端口转发,$ _SERVER ['REMOTE_ADDR']将是路由器的。