$url = current_url(); echo $url; // http://example.com/index.php?id=123#section-1
$url = 'http://example.com/page.php?id=123&name=John'; $query = $_SERVER['QUERY_STRING']; $current_url = $url . '?' . $query; echo $current_url; // http://example.com/page.php?id=123&name=John
$url = 'http://example.com/page.php'; $query = http_build_query(array('id' => 123, 'name' => 'John')); $current_url = $url . '?' . $query; echo $current_url; // http://example.com/page.php?id=123&name=JohnThis example shows how to get the current URL with custom parameters using the http_build_query() function. Package/library: The http_build_query() function is a built-in function of PHP, which means no external package or library is required.