N
N
Nikita Dergachov2017-09-20 16:14:19
Nginx
Nikita Dergachov, 2017-09-20 16:14:19

How to solve the problem of cross-domain request?

Good afternoon. The site has a method that loads data from a third-party resource and when the request is executed it gives an error. How can this be resolved?

The 'Access-Control-Allow-Origin' header contains multiple values '*, *'

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nikita Dergachov, 2017-09-20
@vanillathunder

In some magical way, everything worked after the server was rebooted.

P
Pavel Kornilov, 2017-09-20
@KorniloFF

It is necessary that a third-party resource in its response give out the above header: If there is no such header, then the security policy is included.

E
Exploding, 2017-09-20
@Exploding

Here's a magic function for you. When you need a treasured page - use it.
For example:
$g = get_web_page("google.com");
echo $g['content'];

function get_web_page( $url ){
  $uagent = $_SERVER["HTTP_USER_AGENT"];

  $ch = curl_init( $url );

  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);   
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  curl_setopt($ch, CURLOPT_HEADER, 0);          
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);   
  curl_setopt($ch, CURLOPT_ENCODING, "");       
  curl_setopt($ch, CURLOPT_USERAGENT, $uagent); 
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120); 
  curl_setopt($ch, CURLOPT_TIMEOUT, 120);        
  curl_setopt($ch, CURLOPT_MAXREDIRS, 10);   

  $content = curl_exec( $ch );
  $err     = curl_errno( $ch );
  $errmsg  = curl_error( $ch );
  $page  = curl_getinfo( $ch );
  curl_close( $ch );

  $page['errno']   = $err;
  $page['errmsg']  = $errmsg;
  $page['content'] = $content;
  return $page;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question