Home > Backend Development > PHP Tutorial > Get domain name

Get domain name

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-25 09:08:07
Original
1352 people have browsed it
I was looking at the ecmall core file ecmall.php and saw that this function was written more clearly. I took it out and shared it.


  1. function get_domain() {
  2. /* protocol*/
  3. $protocol = (isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://';
  4. /* Domain name or IP address*/
  5. if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
  6. $host = $_SERVER['HTTP_X_FORWARDED_HOST'] ;
  7. } elseif (isset($_SERVER['HTTP_HOST'])) {
  8. $host = $_SERVER['HTTP_HOST'];
  9. } else {
  10. /* port*/
  11. if (isset($_SERVER['SERVER_PORT' ])) {
  12. $port = ':' . $_SERVER['SERVER_PORT'];
  13. if ((':80' == $port && 'http://' == $protocol) || (':443 ' == $port && 'https://' == $protocol)) {
  14. $port = '';
  15. }
  16. } else {
  17. $port = '';
  18. }
  19. if (isset($_SERVER[ 'SERVER_NAME'])) {
  20. $host = $_SERVER['SERVER_NAME'] . $port;
  21. } elseif (isset($_SERVER['SERVER_ADDR'])) {
  22. $host = $_SERVER['SERVER_ADDR'] . $port;
  23. }
  24. }
  25. return $protocol . $host;
  26. }
Copy code


Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template