Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the full URL of the current page using PHP [duplicate]

Tags:

php

wordpress

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
like image 731
Manish Jesani Avatar asked Sep 22 '14 06:09

Manish Jesani


People also ask

How can I get full page URL in PHP?

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.

How do I get a full URL?

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.

How can I get current URL ID in PHP?

In your detail. php use: $id = $_GET['id']; you can then use $id around the rest of your page.

How can I get source URL in PHP?

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.


1 Answers

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']; ?>
like image 151
Kausha Mehta Avatar answered Oct 02 '22 21:10

Kausha Mehta