Error: file_get_contents HTTP request failed! HTTP/1.0 403 Forbidden

Hi everyone. I am using elgg 2.3.4

I am using file_get_contents for getting user avatar then base64_encode for encoding data with MINE base64.

My code looks as followed

$context = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);
$context = stream_context_create($context);
$encoded_data = 'data:image/jpeg;base64,'.base64_encode(file_get_contents($user->getIconURL('large'),false,$context));
echo '<img class="src-image"  src="'.$encoded_data.'" />';

Everything was working perfectly since 6 months. 

But today I have changed my elgg advanced setting by enabling the option Restrict pages to logged-in users

Since I have enable that option I have the following php error generated by the above code.

"file_get_contents(https://esfam-simplesamlphp.auf.org/serve-file/e0/l1515440414/di/c1/Rs5GJxUpA__z2WJXTWW7RqQZEyzdnJAc5zyAFGxE8hc/1/36/profile/36large.jpg): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden\r\n" in file /home/pessek/Documents/WEB/elggtest/mod/pessek_profile/views/default/profile/details.php (line 285), referer: https://esfam-simplesamlphp.auf.org/profile/admin

So file_get_contents cannot get the content of the image anymore when  Restrict pages to logged-in users is enabled. But I can open the image using my browser

I need your guidance

Best regard

 

 

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking