17

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

My current url

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
Manish Jesani
  • 1,331
  • 5
  • 18
  • 32

1 Answers1

38

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']; ?>
Kausha Mehta
  • 2,610
  • 1
  • 15
  • 31