Summary of how to use php to obtain page parameters

伊谢尔伦
Release: 2023-03-11 14:26:02
Original
2896 people have browsed it

javascriptImplementation:
top.location.href The address of the top-level window
this.location.href The address of the current window

PHP implementation

Test URL: http://localhost/blog/testurl.php?id=5

//Get the domain name or host address
echo $_SERVER['HTTP_HOST']."
Output localhost

//Get the web page address
echo $_SERVER['PHP_SELF']."
Output /blog/testurl. php

//Get the URL parameters
echo $_SERVER["QUERY_STRING"]."
Output id=5

//Get the user agent
echo $_SERVER['HTTP_REFERER']."

//Get the complete url
echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI' ];
echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
Output http://localhost /blog/testurl.php?id=5

//Complete url including port number
echo 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER[ "SERVER_PORT"].$_SERVER["REQUEST_URI"];
Output http://localhost:80/blog/testurl.php?id=5

//Only take the path
$url ='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"];
echo dirname($url);
Output http://localhost/ blog

The above is the detailed content of Summary of how to use php to obtain page parameters. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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