简体   繁体   中英

Need tp find Request source URL in PHP

I want to determine the website from which the request to the particular website has been called. For Example..I have a website www.ex.com. Now this website link has been there on three websites www.a.com, www.b.com, and www.c.com. Suppose one user has clicked the link from www.a.com to go to www.ex.com. Now I want to determine that the request has come from the www.a.com and then the page in www.ex.com will be displayed accordingly. Similarly if the user has clicked the www.ex.com link from www.b.com then the page will be displayed accordingly.

So how can I determine this request source, means from which website www.ex.com has been called? It is good if you will explain this using code in PHP.

Thanks

Look here for HTTP_HOST and HTTP_REFERER.

Since both global variables are populated from HTTP headers, look also here for Host and Referer.

That's how you use them:

$host = $_SERVER['HTTP_HOST'];
$referer = $_SERVER['HTTP_REFERER'];

The 1st is the original host name (like 'www.a.com') referring to your page. The 2nd is the full URL (like https://www.a.com/some/path/to/some.html ).

Then, based on some conditional logic, you may return to your users appropriate HTML.

There are two different websites.

Say from a.com, you click on ex.com

So, for the link in a.com, add some parameter:

<a href="ex.com/somepage.php?from=a.com">Click Here</a>

Now, your from parameter will be

1) a.com 2) b.com 3) c.com

If none of the above, then its clicked from ex.com itself.

You can also add some encryption for this link to add security.

You can use this

$_SERVER['HTTP_REFERER'] 

for referral url

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