How to check if a request if coming from the same server or different server?

后端 未结 4 1969
北海茫月
北海茫月 2020-11-29 03:03

How can I check whether a request being received is sent from the same server??

Say, I\'ve my domain at www.domain.com. Now I\'ve php processing files which will pro

4条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 03:24

    this will check if there is a referer, then it will compare it with current domain, if different then it is from outside referer

    if ((isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']))) {
    if (strtolower(parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST)) != strtolower($_SERVER['HTTP_HOST'])) {
    // referer not from the same domain
    }
    }
    

提交回复
热议问题