3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet { $ipaddress = $_SERVER['HTTP_CLIENT_IP']."\r\n"; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check if ip is pass from proxy { $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR']."\r\n"; } else { $ipaddress = $_SERVER['REMOTE_ADDR']."\r\n"; } $file = 'filename.txt'; //this is the file to which the IP address will be written; name it your way. $fp = fopen($file, 'a'); fwrite($fp, $ipaddress); fclose($fp); ?>
Output for 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
Notice: Undefined index: REMOTE_ADDR in /in/eVFLg on line 13 Warning: fopen(filename.txt): failed to open stream: Permission denied in /in/eVFLg on line 18 Warning: fwrite() expects parameter 1 to be resource, boolean given in /in/eVFLg on line 20 Warning: fclose() expects parameter 1 to be resource, boolean given in /in/eVFLg on line 22
Output for hhvm-3.10.0 - 3.12.0
Notice: Undefined index: REMOTE_ADDR in /in/eVFLg on line 13 Warning: Permission denied in /in/eVFLg on line 18 Warning: fwrite() expects parameter 1 to be resource, boolean given in /in/eVFLg on line 20 Warning: fclose() expects parameter 1 to be resource, boolean given in /in/eVFLg on line 22
Output for 4.3.2 - 5.2.17
Notice: Undefined index: REMOTE_ADDR in /in/eVFLg on line 13 Warning: fopen(filename.txt): failed to open stream: Permission denied in /in/eVFLg on line 18 Warning: fwrite(): supplied argument is not a valid stream resource in /in/eVFLg on line 20 Warning: fclose(): supplied argument is not a valid stream resource in /in/eVFLg on line 22
Output for 4.3.1
Notice: Undefined index: REMOTE_ADDR in /in/eVFLg on line 13 Warning: fopen(filename.txt) [http://www.php.net/function.fopen]: failed to create stream: Permission denied in /in/eVFLg on line 18 Warning: fwrite(): supplied argument is not a valid stream resource in /in/eVFLg on line 20 Warning: fclose(): supplied argument is not a valid stream resource in /in/eVFLg on line 22
Output for 4.3.0
Notice: Undefined index: REMOTE_ADDR in /in/eVFLg on line 13 Warning: fopen(filename.txt) [http://www.php.net/function.fopen]: failed to create stream: Read-only file system in /in/eVFLg on line 18 Warning: fwrite(): supplied argument is not a valid stream resource in /in/eVFLg on line 20 Warning: fclose(): supplied argument is not a valid stream resource in /in/eVFLg on line 22