php detect/ get the sender url (or server) of post request

亡梦爱人 提交于 2019-12-01 10:26:42

问题


Suppose X.com will send a post request to Y.com How Y know that the sender is X? Without the url query string course.

$_SERVER['HTTP_REFERER'] of http://php.net/manual/en/reserved.variables.server.php seems not the answer. The documentation it self says "it cannot really be trusted".

Should it use key & secret key parameter?


回答1:


Send a secret value across with your request, such as a key which you can check for in your script on X.com

Y.com:

$secret = 'SECRET_KEY';

X.com:

if(!empty(htmlentities($_POST['secret'])) {
    if(htmlentities($_POST['secret']) == 'SECRET_KEY') {
        //Request came from Y.com
    }
}


来源:https://stackoverflow.com/questions/26940454/php-detect-get-the-sender-url-or-server-of-post-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!