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
To get the current page URL, PHP provides a superglobal variable $_SERVER. The $_SERVER is a built-in variable of PHP, which is used to get the current page URL. It is a superglobal variable, means it is always available in all scope.
Just right-click in Chrome's address bar select “Always show full URLs” to make Chrome show full URLs. Chrome will now always show the full URL of every web address you open. To disable this feature, right-click in the address bar again and uncheck it.
In your detail. php use: $id = $_GET['id']; you can then use $id around the rest of your page.
Append the HTTP_HOST(The host to which we have requested, e.g. www.google.com, www.yourdomain.com, etc…) name of the server. Append the REQUEST_URI(The resource which we have requested, e.g. /index. php, etc…) to the URL string.
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']; ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With