简体   繁体   English

PHP-CORS策略已阻止对字体的访问:没有“ Access-Control-Allow-Origin”标头

[英]PHP - Access to Font has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header

I need to get data from website but I have problem with scrape, I have error 我需要从网站获取数据,但是刮擦有问题,我有错误

Access to Font has been blocked by CORS policy: No Access-Control-Allow-Origin header 对字体的访问已被CORS策略阻止:无Access-Control-Allow-Origin标头

I have tried to fix it by adding the follwoing to the script: 我试图通过将以下内容添加到脚本来修复它:

header('Access-Control-Allow-Origin: http://my-domain.com');

But it is not working. 但这是行不通的。 I have also tried to put in .htaccess but it is not working there too, here is my code: 我也尝试放入.htaccess但是它在那里也不起作用,这是我的代码:

$link = 'http://jakartagrosir.com/products/search-0.html?keyp=sny+230&do=';
$html = file_get_contents($link);
$html = str_replace("../","http://thsoite.com/", $html);
$html = str_replace("styles/tf_black_white/image/favicon.png","http://thsoite.com/styles/tf_black_white/image/favicon.png", $html);

echo $html;

How can I fix this? 我怎样才能解决这个问题?

You put the header on your server so that the page is allowed to connect to you (which you probably don't need anyway). 您可以将标头放在服务器上,以便允许页面连接到 (无论如何您可能都不需要)。 But they , where they got the font, didn't do it. 但是他们在哪里得到了字体却没有这么做。 The page refers to their domain when it refers to the font. 当引用字体时,页面引用其域。 You will have to download the font and replace the link to their font with the link to your font on your server. 您将必须下载字体,并将其字体的链接替换为服务器上字体的链接。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 已被 CORS 政策阻止:无“访问控制允许来源” - has been blocked by CORS policy: No 'Access-Control-Allow-Origin' 访问 abcd.com 上的字体已被 CORS 政策阻止:没有“访问控制允许来源” - Access to Font at abcd.com has been blocked by CORS policy: No 'Access-Control-Allow-Origin' 无法在React中使用GraphQL查询-已被CORS策略阻止:所请求的资源上不存在“ Access-Control-Allow-Origin”标头 - Cannot use GraphQL queries in React - has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource 被 CORS 策略阻止:“Access-Control-Allow-Origin”header 包含多个值 - Blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains multiple values Cors header “访问控制允许来源”被阻止 Api 响应 - Cors header “Access-control-allow-origin” blocked Api Response 缺少CORS标头“ Access-Control-Allow-Origin”-PHP,角度 - CORS header 'Access-Control-Allow-Origin' missing - PHP, Angular Laravel7 CORS:被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:否 'Access-Control-Allow-Origin' - Laravel7 CORS : blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header("访问控制允许来源:"); 不工作 CORS 策略,预检请求不允许重定向 - header("Access-Control-Allow-Origin: "); dont work CORS policy, Redirect is not allowed for a preflight request Laravel 从源访问 XMLHttpRequest 已被 CORS 策略阻止 - Laravel Access to XMLHttpRequest at from origin has been blocked by CORS policy header('Access-Control-Allow-Origin:*'); 不允许CORS请求 - header('Access-Control-Allow-Origin: *'); Not allowing CORS request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM