Xinetd用PHP获取远程IP [英] Xinetd obtain remote IP with PHP
本文介绍了Xinetd用PHP获取远程IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,xinetd 有这项服务:
service MyService
{
port = 8881
socket_type = stream
wait = no
user = nobody
server = /usr/local/bin/php
server_args = /home/file/public_html/php/port/test1.php
log_on_success + = USERID
log_on_failure + = USERID
disable = no
}
我的文件 test1.php:
<? php
$handle = fopen ('php :/ / stdin', 'r');
$input = fgets ($ handle);
fclose ($ handle);
$ip = $_SERVER['REMOTE_ADDR']
echo "Hello {$ input} your IP: $ip";
?>
我无法获取远程IP:
$ip = $ _SERVER['REMOTE_ADDR']
因为我可以得到远程ip??
推荐答案
解决方案是修改 PHP :
The solution is modifying the PHP with :
$IpX = $_SERVER['REMOTE_HOST'] ?$_SERVER['REMOTE_HOST'] : $_SERVER['HOST'];
<? php
$IpX = $_SERVER['REMOTE_HOST'] ? $_SERVER['REMOTE_HOST'] : $_SERVER['HOST'];
$handle = fopen ('php :/ / stdin', 'r');
$input = fgets ($ handle);
fclose ($ handle);
echo "Hello {$ input} your IP: $IpX";
?>
这篇关于Xinetd用PHP获取远程IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文