I have a webpage that needs to display an image (mjpeg) from an IP camera on the same network. The camera requires authentication, so using the following code on the page obviously displays nothing:
<img src="http://10.0.0.74/mjpg/1/video.mjpg" />
However, if I navigate to the camera's setup page I get a 401 challenge and I can then enter my credentials. If I then return to the original page without closing the browser and refresh it, the image displays correctly.
My question is; how can I automate this using PHP/Javascript so the user doesn't have to do a manual login to the camera before seeing the image?
I have already tried using the following PHP function called on page load with the url of the image (as an attempt to pre-authorise the request, rather than actually doing anything useful), this seems to complete ok without throwing any errors, but the image is still not displayed on the page.
function authenticateInput($url, $user, $pass){
$c = curl_init($url);
$authString = '$user:$pass';
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_USERPWD, $authString);
curl_exec($c);
}