Write a PHP script to get the client IP address


Introduction

PHP is a server scripting language, and It is a powerful tool for making interactive and dynamic Web-pages. I have used WampServer 2.2 for following excercise..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. <?php
  2. //whether ip is from share internet
  3. if (!empty($_SERVER['HTTP_CLIENT_IP']))
  4. {
  5. $ip_address = $_SERVER['HTTP_CLIENT_IP'];
  6. }
  7. //whether ip is from proxy
  8. elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
  9. {
  10. $ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
  11. }
  12. //whether ip is from remote address
  13. else
  14. {
  15. $ip_address = $_SERVER['REMOTE_ADDR'];
  16. }
  17. echo $ip_address;
  18. ?>

Result

python language techstudy.org

     





Related Topics




Popular Posts