I tried to make cross-domain ajax request, always getting 0 status response, and now, seems understand what was the problem. On the site side, there can be a list of domains that can send request to it. It is set by the next way, as far as I understood:
Access-Control-Allow-Origin: http://example.com
And as I understand, when I make request to another domain, browser automatically adds to request’s header value Origin, that contains the domain, where request came from.
So, will the server will be tricked, if to change that header value, and how can that be done?
<?php
$url = $_POST['url'];
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => $_POST['data']
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE)
echo('error');
else
echo($result);
?>