NET_Helper.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Netowrk helper file.
  4. *
  5. * Provides a helper to perform network operations.
  6. *
  7. * @category Helper.
  8. */
  9. /**
  10. * Require dependent files if not present.
  11. */
  12. require_once(PATH::HELPER . "Helper.php");
  13. /**
  14. * Netowrk helper.
  15. *
  16. * Contains netowrk related utilities.
  17. *
  18. * @category Helper.
  19. */
  20. final class NET extends Helper{
  21. /**
  22. * Finds out the protocol the user is connecting to the site with.
  23. *
  24. * @return string "http://" or "https://".
  25. */
  26. public static function get_protocol(){
  27. if (isset($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] == "on" || $_SERVER["HTTPS"] == 1) || isset($_SERVER["HTTP_X_FORWARDED_PROTO"]) && $_SERVER["HTTP_X_FORWARDED_PROTO"] == "https") {
  28. $protocol = "https://";
  29. }
  30. else {
  31. $protocol = "http://";
  32. }
  33. return $protocol;
  34. }
  35. /**
  36. * Finds out the IP address of the client.
  37. *
  38. * @return string Client IP address.
  39. */
  40. public static function get_ip(){
  41. $client = @$_SERVER["HTTP_CLIENT_IP"];
  42. $forward = @$_SERVER["HTTP_X_FORWARDED_FOR"];
  43. $remote = $_SERVER["REMOTE_ADDR"];
  44. if(filter_var($client, FILTER_VALIDATE_IP)){
  45. $ip = $client;
  46. }
  47. elseif(filter_var($forward, FILTER_VALIDATE_IP)){
  48. $ip = $forward;
  49. }
  50. else{
  51. $ip = $remote;
  52. }
  53. return $ip;
  54. }
  55. }
  56. ?>