Home > Backend Development > PHP Tutorial > php function code to get website address

php function code to get website address

WBOY
Release: 2016-07-25 08:55:29
Original
1000 people have browsed it
  1. /**

  2. * Get the full address of the website
  3. * by bbs.it-home.org
  4. */
  5. function getRootUrl(){
  6. $name = '';
  7. if ( isset($_SERVER['HTTP_HOST']) ) {
  8. $name = $_SERVER['HTTP_HOST'];
  9. }else{
  10. $name = $_SERVER['SERVER_NAME'];
  11. }
  12. if ( strpos($name,':') === false && $_SERVER ['SERVER_PORT'] != 80 ){
  13. $name .= ':'.$_SERVER['SERVER_PORT'];
  14. }
  15. $path = $_SERVER['PHP_SELF'];
  16. $path = substr($path, 0,strrpos($path,'/')+1);

  17. return 'http://'.$name . $path;

  18. }

Copy Code

>>> Further reading: Two methods to obtain visitor’s IP address in PHP PHP implementation code to obtain MAC address How to get the final address of youku video with php Example sharing of obtaining real IP address with php Discuss: How to obtain domain name and domain name IP address with PHP php example code to get the redirected URL address php code to get client ip address Example of php code to obtain computer MAC address Example code of php hiding the real download address of the file php code and function description to obtain the local area network (intranet) IP address of this machine Six ways to obtain the php client IP address Get the php code of the user’s real IP address php code to realize IP address and number exchange php gets the MAC address of the network card and the code of the main domain in the URL php determines whether the visiting IP address is domestic or foreign php code to obtain client IP address, geographical information, browser information, and local real IP php code for grabbing email addresses from web pages php code to record visitor’s IP address How to preset http string for URL address in php php function to verify email address Four ways to get the client IP address in php Code to get user IPv4 or IPv6 address using php



source:php.cn
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