Origin is not allowed by Access-Control-Allow-Origin

后端 未结 18 3551
北海茫月
北海茫月 2020-11-21 05:52

I\'m making an Ajax.request to a remote PHP server in a Sencha Touch 2 application (wrapped in PhoneGap).

The response from the server is the following:

18条回答
  •  萌比男神i
    2020-11-21 06:14

    This might be handy for anyone who needs to an exception for both 'www' and 'non-www' versions of a referrer:

     $referrer = $_SERVER['HTTP_REFERER'];
     $parts = parse_url($referrer);
     $domain = $parts['host'];
    
     if($domain == 'google.com')
     {
             header('Access-Control-Allow-Origin: http://google.com');
     }
     else if($domain == 'www.google.com')
     {
             header('Access-Control-Allow-Origin: http://www.google.com');
     }
    

提交回复
热议问题