문제

Hello I have this service with 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
}

My File test1.php:

<? php
$handle = fopen ('php :/ / stdin', 'r');
$input = fgets ($ handle);
fclose ($ handle);
$ip = $_SERVER['REMOTE_ADDR']
echo "Hello {$ input} your IP: $ip";
?>

I can not get the remote ip:

$ip = $ _SERVER['REMOTE_ADDR']

As I can get the remote ip??

도움이 되었습니까?

해결책

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";
?>

Thanks to: Gonzalo Ayuzo

다른 팁

I tested and found that:

Apache httpd passes "REMOTE_ADDR" and "REMOTE_PORT" and much more other environments to the CGI program.

But xinetd passes only "REMOTE_HOST" environment to my program defined by "server" in xinetd.d/xxxx 。and more, "REMOTE_HOST" looks like "::ffff:192.168.1.23" , not a pure IP address.(BTW: what does this mean ?)

So : xinetd + program can only acts a tiny httpd moudle

$REMOTE_ADDR is an environment variable that is set by a web server as part of the CGI protocol. You're running straight on a socket. There is no web server here. It is not surprising that this variable (or indeed the ones suggested by Laxus in a comment) aren't set.

If you want the remote address, you will have to get it yourself using getpeername.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top