PHP Gets the current host, domain name, path, port and other parameter code sharing

Source: Internet
Author: User
This article mainly and we introduce how PHP obtains the current host, domain name, url, path, port and other parameters, with a certain reference value, interested can understand, hope to help everyone.

Lab Environment:

Test the domain name Daxiangtravel.com,apache root directory/mnt/, test the directory/mnt/qa/test, the test file is named index.php.

Get the code:

Get current directory:

  GETCWD ();///mnt/qa/testdirname (__file__);///mnt/qa/test

Get domain name or host address

$_server[' Http_host ']; Daxiangtravel.com

Get web Address

$_server[' php_self '];///qa/test/index.php

Get URL parameters

$_server["Query_string"];//v=433 get user agent $_server[' http_referer '];//http://daxiangtravel.com/qa/test/index.php?v=433

Get the full 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

Fetch path only

$url = ' http://' $_server[' server_name '].$_server["Request_uri"];echo dirname ($url);//Http://daxiangtravel.com/qa/test

Full URL with port number

' http://'. ' $_server[' server_name '. $_server["Server_port"].$_server["Request_uri"];///http/ daxiangtravel.com:80/qa/test/index.php?v=433

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.