Posts

How to get current page full URL in PHP

Step 1: Deciding on the SSL protocol whether the site using http or https.

if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
   $url = 'https';
} else {
   $url = 'http';
}

Step 2: Append domain name or IP to the URL

$url .= $_SERVER['HTTP_HOST'];

Step 3: Append the current page URL after domain / IP

$url .= $_SERVER[‘REQUEST_URI’]

Step 4: Let’s put all these together and create a function that can be reused.

function getfullpageurl() {
    if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')   
         $url = "https://";   
    else  
         $url = "http://";   
       
    $url.= $_SERVER['HTTP_HOST'];   
    
    $url.= $_SERVER['REQUEST_URI'];    
      
    return $url;  
}

Enforcing https on all WordPress pages

Step 1

Go to your file manager or access your files via any FTP client.

Step 2

Open your .htaccess file in edit mode (Where you can update the file and save.)

Step 3

Include the following two lines below RewriteEngine On as shown.

RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Step 4

Finally save your updates and close.

And that’s it! your pages will be loading with https.