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.