PHP check to make sure request is either xmlhttp from my site or normal request from a certain domain

前端 未结 4 416
心在旅途
心在旅途 2020-12-22 07:13

How would the condition be written to ensure a page is either accessed by xmlhttp request from my site or from an allowed outside domain?



        
4条回答
  •  北荒
    北荒 (楼主)
    2020-12-22 07:59

    Ajax requests are only possible from the same domain. You cannot make an XMLHttp request from another site due to inbuilt security reasons.

    This site outlines states perfectly that you cannot launch a cross-domain XMLHTTPRequest http://developer.yahoo.com/javascript/howto-proxy.html

    All modern web browsers impose a security restriction on network connections, which includes calls to XMLHttpRequest. This restriction prevents a script or application from making a connection to any web server other than the one the web page originally came from (Internet Explorer will allow cross-domain requests if the option has been enabled in the preferences). If both your web application and the XML data that application uses come directly from the same server, then you do not run into this restriction.

提交回复
热议问题