How to get the current host, domain name, URL, path, port, and other parameters using PHP-php Tutorial

Source: Internet
Author: User
This article describes how PHP can obtain parameters such as the current host, domain name, URL, path, and port, if you are interested, please refer to this article. This article describes how PHP can obtain parameters such as the current host, domain name, URL, path, and port.

Lab environment:

The test domain name is daxiangtravel.com, the apache root directory/mnt/, the test directory/mnt/qa/test, and the test file name is index. php.

Get Code:

Get the current directory:

 getcwd();// /mnt/qa/testdirname(__FILE__);// /mnt/qa/test

Get domain name or host address

$_SERVER['HTTP_HOST'];  //daxiangtravel.com

Get webpage address

$_SERVER['PHP_SELF'];// /qa/test/index.php

Obtain URL parameters

$ _ SERVER ["QUERY_STRING"]; // v = 433 get user proxy $ _ SERVER ['http _ referer']; // http://daxiangtravel.com/qa/test/index.php? V = 433

Obtain the complete url

 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; // http://daxiangtravel.com/qa/test/index.php?v=433 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];// http://daxiangtravel.com/qa/test/index.php?v=433

Retrieve path only

$url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"];echo dirname($url);// http://daxiangtravel.com/qa/test

Complete url containing the port number

 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];// http://daxiangtravel.com:80/qa/test/index.php?v=433

The preceding section describes how to use PHP to obtain details about the current host, domain name, URL, path, port, and other parameters. For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.