PHP HTTP Referrer

后端 未结 4 1950
梦谈多话
梦谈多话 2021-01-05 01:58

I have a page which accepts POSTs from a remote site. I would like to detect the domain that these POSTs are coming from. I realize that it can be spoofed but it is better t

相关标签:
4条回答
  • 2021-01-05 02:04

    This works for me pretty well:

    https://stackoverflow.com/a/17958676/2635701

    <form action="http://www.yourdomain.com/subscribe" 
       method="POST" 
       onsubmit=
          "document.getElementById('www.yourdomain.com.referrer').value=window.location;" >
        <!-- hidden input for field starts with a domain registered by you 
        just so that it's unlikely to clash with anything else on the page -->
        <input type="hidden" id="www.yourdomain.com.referrer" name="referrer"/>
        your email: <input name="email" type="text"/>
        ... rest of form ...
        <input type="submit" value="Subscribe"/>
    </form>
    
    0 讨论(0)
  • 2021-01-05 02:18
    $_SERVER['HTTP_REFERER'] 
    

    with a single R, try var_dump($_SERVER) for more info.

    0 讨论(0)
  • 2021-01-05 02:20

    You spelled Referer correctly. It should be:

    $_SERVER['HTTP_REFERER']
    
    0 讨论(0)
  • 2021-01-05 02:25

    You are right that the referrer is easy to spoof, however there is a better solution. Read the ipn documentation in which they mention validation mechanisms. Never trust the user.

    0 讨论(0)
提交回复
热议问题