Search code examples
phpweb-scrapingcors

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

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:

$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?


Solution

  • 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.