Forum Moderators: coopster

Message Too Old, No Replies

How to put $REMOTE_ADDR in a html file

         

hisac

7:14 am on Apr 4, 2004 (gmt 0)

10+ Year Member



I need to access my server behind a linksys router. now i can do this by going to the router and check the status page, but if does not aways work from the outside because the ip changes very often.

i need to run a script on my server so it can be seen by another server on the internet wich olny grabs the the remote ip and writes it to a file every time the file is called by the server behind the router.

Thank u in advance for any help.
saludos desde playa del carmen mexico

hisac

3:21 pm on Apr 4, 2004 (gmt 0)

10+ Year Member



I just found outt that getting the ip is very simple

<?
echo "<a href=http://$REMOTE_ADDR>$REMOTE_ADDR</a>";
?>

now I need to write it to a file, so I can get it from the outside and that is what is very confusing to me.

mafitzpatrick

6:35 pm on Apr 5, 2004 (gmt 0)

10+ Year Member



If you need it to be accessed externally (via the web?) you may be able to just just load up the php file through your server's webserver. However, if that isnt an option, try this...

$output=<<<HTML
<html>
<body>
<a href="${_SERVER['REMOTE_ADDR']}">${_SERVER['REMOTE_ADDR']}</a>
</body>
</html>
HTML
;

$file=@fopen ("/path/to/your/file.html","w");
@fwrite($file,$output);
@fclose($file);

Hope that helps

seomike2003

8:47 pm on Apr 5, 2004 (gmt 0)



if (getenv('HTTP_X_FORWARDED_FOR')) {
$ip = getenv('HTTP_X_FORWARDED_FOR');
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}

echo $ip;

Here is another way.

hisac

9:31 pm on Apr 5, 2004 (gmt 0)

10+ Year Member



Thanks a million for all your help.
Is good to learn a little bit every day.

Yes, I finally managed to run the script to write the ip from my server behind a linksys firewall into a file in a server on the internet.
The mayor problem I had was with the crontab facility.
I had a file called post-ip with:

#!/bin/bash
/usr/bin/lynx -dump [webaddress...] >> /dev/null

and I wanted to run it with

crontab */30 * * * * /home/root/post-ip

If I executed the file from the shell it worked and the ip was udated on the server in the internet. But once I tried with crontab I was getting an error message via email telling me that my terminal was unable to clear the screen neither position the cursor.
I tried an tried until I learn that the problem was with lynx it does not like to be run hidden, it needs the shell. So now im using curl instead and it works like magic.

Thank you all for this forum.