How to get the full URL of the current page using PHP

What is the “less code needed” way to get parameters from an URL query string which is formatted like the following?

My current url

Read More
www.mysite.com/category/subcategory/#myqueryhash

I put this code

$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

It returns only www.mysite.com/category/subcategory/

Output should be :

www.mysite.com/category/subcategory/#myqueryhash

Related posts

Leave a Reply

1 comment

  1. You can use this for HTTP request

    <?php $current_url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>
    

    You can use this for HTTPS request

    <?php $current_url="https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>
    

    You can use this for HTTP/HTTPS request

    <?php $current_url="//".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>