简体   繁体   中英

How to get the current full url (url + fragments) of the webpage in PHP?

I want to fetch the current URL which I've received as a callback during authorization from Salesforce.com. The data in the url is in the fragments portion.

With the $_SERVER variable, you could do this:

echo $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

Take a look at the following page for all available keys: php.net

You can use a combination of $_SERVER['HTTP_HOST'] and $_SERVER['REQUEST_URI'] but HTTP_HOST is not very reliable so try defining URL's for known sources and appending the request uri to the end.

define('URI', 'http://Salesforce.com');
echo URI. $_SERVER['REQUEST_URI'];

You will not be able to get the fragment portion of the URI back as it is used on the client only. If you need this you will manually have to send them to a server with some JavaScript.

I belive its something like $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'].$_SERVER['QUERY_STRING'];

http://php.net/manual/en/reserved.variables.server.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM