URL Reconstruction Using PHP

URL Reconstruction Using PHP
Reconstruct an URL in PHP by concatenating the domain-name, path and query string from three different variables.
// Domain-name
$Domain = $_SERVER['HTTP_HOST'];
// File Path
$Path = $_SERVER['SCRIPT_NAME'];
// Query String
$QString = $_SERVER['QUERY_STRING'];
 
// Put together the three strings
$URL = "http://".$Domain.$Path."?".$QString; // Or use $_SERVER['REQUEST_URI'] to get the path and query string together

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top