[英]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.