I'm trying to make a Website with Symfony4. I use curl to get the html code from another webpage, and my goal is to get the link of the only image on this website, and display it on mine.
I've tried it from scratch (using Php) with curl and regex. To check the image URL, I print it and it works. I am using a Xampp server.
But now i'm trying to do it with Symfony and i have a 403 status. When I check the code, everything is fine but the image doesn't display. It's weird because if I visite the webpage before showing the image on my website, it works.
I'm sure that I have the right image URL to display but I don't understand why I must visite the source website to display it on my website.
image.html.twig
<img src="{{ img_link }}">
image.php
$curl = new Curl();
$curl->setUserAgent('Mozilla/4.0 (compatible; MSIE 6.0;Windows NT 5.0)');
$curl->setOpt (CURLOPT_RETURNTRANSFER, TRUE);
//$curl->setOpt(CURLOPT_BINARYTRANSFER, TRUE);
$curl->setOpt(CURLOPT_HEADER, FALSE);
$curl->get($this->random_link);
$this->html_content = $curl->response;
$curl->close();
html page generate
<div class="jumbotron text-center">
<h1>Donation</h1>
<img src="https://exemple_link.html/exemple">
</div>
error:
Failed to load resource: the server responded with a status of 403 ()
Thanks for your help