Echo or get the current page URL in a PHP page, use $_SERVER. Its build-in variable in PHP, which is used to fetch or echo the current page URL. It’s available for all scope and its super global variable.

The below examples show how it works and check URL on HTTPS or HTTP.

<?php if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'){ $url = ''; }else{ $url = ""; } $url .= $_SERVER['HTTP_HOST']; $url .= $_SERVER['REQUEST_URI']; echo $url; ?>

The shortcode to get the current page URL is below.

If not using SSL Certificate/ using HTTP in URL .



If  using SSL Certificate/ using HTTPS in URL .