How to get the current URL and replace parameters or URLs in PHP

In PHP, we often need to get the URL of the current website, and sometimes we need to replace some parameters in the URL or completely replace the entire URL. This article will introduce how to get the current website URL using PHP, and provide some sample code to demonstrate how to replace parameters in the URL or the entire URL.

Get the current website URL

To get the current website URL, we can use the sum $_SERVERin the superglobal variable . Contains the filename portion of the current script and the hostname portion of the current request. We can concatenate these two values ​​​​to get the current website URL.PHP_SELFHTTP_HOSTPHP_SELFHTTP_HOST

Here is a sample code:

$currentURL = 'http' . (isset($_SERVER['HTTPS']) 

Guess you like

Origin blog.csdn.net/qq_33885122/article/details/133433255