PHP - 对字体的访问已被 CORS 策略阻止:否 'Access-Control-Allow-Origin' header

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

我需要从网站获取数据,但我遇到了抓取问题,我有错误

Access to Font has been blocked by CORS policy: No Access-Control-Allow-Origin header

我试图通过在脚本中添加以下内容来修复它:

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

但它不起作用。我也尝试输入 .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;

我该如何解决这个问题?

您将页眉放在您的服务器上,这样页面就可以连接到(您可能根本不需要)。但是 他们,他们从哪里得到字体,却没有这样做。该页面在引用字体时引用了它们的域。您将必须下载字体并将 link 替换为他们的字体,将 link 替换为您服务器上的字体。