PHP get URL method summary:
1. How to get the complete url address of the current webpage in PHP
2. How to get the url address of the current page without parameters in php
3. Other operation methods for obtaining url addresses in php
How to get the complete url address of the current webpage in PHP
<?php
//来源 https://blog.csdn.net/qq_41221596/article/details/128150910
function getpageurl() {
$pageURL = 'http';
if(isset($_SERVER['HTTPS']) && $_SERVER["HTTPS"] == "on"){
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
}else{
$pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
}
return $pageURL;
}
echo getpageurl();
?>
How to get the url address of the current page without parameters in php
The above two functions about php getting the complete url address of the page will also get the parameters submitted in the url. If we only get an address without parameters, you can refer to the following example!
来源:https://blog.csdn.net/qq_41221596/article/details/128150910
<?php
function getpageurl_t() {
$pageURL = 'http';
if(isset($_SERVER['HTTPS']) && $_SERVER["HTTPS"] == "on"){
$pageURL .= "s";
}
$pageURL .= "://";
$this_page = $_SERVER["REQUEST_URI"];
//过滤要提交的参数
if(strpos($this_page, "?") !== false){
$this_pages = explode("?", $this_page);
$this_page = reset($this_pages);
}
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $this_page;
}else{
$pageURL .= $_SERVER["SERVER_NAME"] . $this_page;
}
return $pageURL;
}
?>
<?php
echo getpageurl_t() ;
?>
Other operation methods for obtaining url addresses in php
You can refer to some operation methods on the url address in the following php to realize your own needs!
<?php
//测试网址: http://localhost/blog/ss.php?id=10
//获取域名或主机地址
echo $_SERVER['HTTP_HOST']."<br>"; // localhost
//获取网页地址
echo $_SERVER['PHP_SELF']."<br>"; // blog/ss.php
//获取网址参数
echo $_SERVER["QUERY_STRING"]."<br>"; // id=10
//获取用户代理
echo $_SERVER['HTTP_REFERER']."<br>";
//获取完整的url
echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
// http://localhost/blog/ss.php?id=10
//包含端口号的完整url
echo 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
// http://localhost:80/blog/ss.php?id=10
//只取路径
$url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"];
echo dirname($url);
// http://localhost/blog
?>
Here are some ways to get server files:
<?php
echo "显示脚本文件的相对路径和文件名:\"".$_SERVER["PHP_SELF"]."\"<br>";
echo "显示服务器使用的CGI脚本规范:\"".$_SERVER["GATEWAY_INTERFACE"]."\"<br>";
echo "显示当前运行脚本所在服务器的IP地址:\"".$_SERVER["SERVER_ADDR"]."\"<br>";
echo "显示当前运行脚本服务器名称:\"".$_SERVER["SERVER_NAME"]."\"<br>";
echo "显示当前运行脚本服务器标识:\"".$_SERVER["SERVER_SOFTWARE"]."\"<br>";
echo "显示请求页面的通信协议的名称和版本:\"".$_SERVER["SERVER_PROTOCOL"]."\"<br>";
echo "显示访问页面的请求方法:\"".$_SERVER["REQUEST_METHOD"]."\"<br>";
echo "显示脚本开始运行时间:\"".$_SERVER["REQUEST_TIME"]."\"<br>";
echo "显示URL问号后的字符串:\"".$_SERVER["QUERY_STRING"]."\"<br>";
echo "显示当前运行脚本的文档根目录:\"".$_SERVER["DOCUMENT_ROOT"]."\"<br>";
echo "显示当前Accept请求的头信息:\"".$_SERVER["HTTP_ACCEPT"]."\"<br>";
echo "显示当前请求的字符信息:\"".$_SERVER["HTTP_ACCEPT_CHARSET"]."\"<br>";
echo "显示当前当前请求的Accept-Encoding头信息:\"".$_SERVER["HTTP_ACCEPT_ENCODING"]."\"<br>";
echo "显示当前请求的Accept-Language头信息:\"".$_SERVER["HTTP_ACCEPT_LANGUAGE"]."\"<br>";
echo "显示当前请求的Connection头信息:\"".$_SERVER["HTTP_CONNECTION"]."\"<br>";
echo "显示当前请求的Host头信息:\"".$_SERVER["HTTP_HOST"]."\"<br>";
echo "显示当前页面的前一个页面的URL地址:\"".$_SERVER["HTTP_REFERER"]."\"<br>";
echo "显示当前请求的User-Agent的头信息:\"".$_SERVER["HTTP_USER_AGENT"]."\"<br>";
echo "显示脚本是否可以通过HTTPS协议进行访问:\"".$_SERVER["HTTPS"]."\"<br>";
echo "显示浏览当前页面用户的IP地址:\"".$_SERVER["REMOTE_ADDR"]."\"<br>";
echo "显示浏览当前页面用户的主机名:\"".$_SERVER["REMOTE_HOST"]."\"<br>";
echo "显示用户连接到服务器时所使用的端口:\"".$_SERVER["REMOTE_PORT"]."\"<br>";
echo "显示当前执行脚本的绝对路径名:\"".$_SERVER["SCRIPT_FILENAME"]."\"<br>";
echo "显示Apache配置文件中的SERVER_ADMIN参数设置情况:\"".$_SERVER["SERVER_ADMIN"]."\"<br>";
echo "显示网络服务器使用的端口,默认为\"80\":\"".$_SERVER["SERVER_PORT"]."\"<br>";
echo "显示服务器版本和虚拟主机名的字符串:\"".$_SERVER["SERVER_SIGNATURE"]."\"<br>";
echo "显示脚本在文件系统中的基本路径:\"".$_SERVER["PATH_TRANSLATED"]."\"<br>";
echo "显示当前脚本的路径:\"".$_SERVER["SCRIPT_NAME"]."\"<br>";
echo "显示访问当前页面的URI:\"".$_SERVER["REQUEST_URI"]."\"<br>";
?>
I am a video brick~~
My Popular Article Recommendations
- Effect test of online cloud director switching for multi-channel live video broadcasting
- How to convert the video into a QR code, scan the code and play it directly?
- Which websites upload videos without inserting ads?
- How to generate a QR code from a video? Scan the QR code on WeChat to watch? no advertising
- Commonly used photo size comparison table, the size of the photo is right in this table
- Live Video Streaming Strategy (Push Streaming Interfaces of Major Platforms Organized)
- HTML5 video double speed playback function
- Teach you a trick: how to realize list playback of multiple videos?
- How to implement the function of playing videos in the video list on the WeChat public account
- H5 video double-speed playback function (an example of video multi-speed viewing function)
- How to configure an FTP server
- How to Upload Files Using FTP (FTP File Transfer)
- OBS Live Tool User Guide/Tool for Pushing Live Video Sources to Servers by OBS
- QQ browser hijacks the video tag to load its own advertisement (how to solve it?)