首页 > 解决方案 > 欺骗站点认为请求来自它的域

问题描述

我尝试发出跨域ajax请求,总是得到0状态响应,现在,似乎明白了问题所在。在站点方面,可以有一个可以向其发送请求的域列表。据我了解,它是通过下一种方式设置的:

Access-Control-Allow-Origin: http://example.com

据我了解,当我向另一个域发出请求时,浏览器会自动添加到请求的标头值Origin中,其中包含请求来自的域。

那么,如果更改该标头值,服务器会被欺骗吗?怎么办?

<?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);


?>

标签: javascriptphpcross-domain

解决方案


推荐阅读