简体   繁体   中英

Get the domain that is doing the cross domain request in PHP?

I've got a site where I do a cross domain call to my other site. Is there a possibility to see what domain is trying to do the cross domain request?

Let me clarify this with an example :

On my site example.com I make a cross domain request to test.com . In test.com , example.com is allowed to make a cross domain request. So it will run the code. Now, in that piece of code I'm running, I want to see which site made the request. So in this case I want it to return example.com .

Is this possible?

$_SERVER['HTTP_REFERER'] should contain that information. According to the php official documentation

'HTTP_REFERER' The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

您可以在跨域请求中包含网站名称example.com。

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