I am attempting to stream an ipcamera through PHP while using following code

<?
# Stop apache timing out
set_time_limit(0);

# Set the correct header
header('Content-Type: multipart/x-mixed-replace;boundary=ipcamera');

# Read the images
readfile('http://[USER]:[PASSWORD]@[IPADDRESS]:[PORT]/videostream.cgi');
?>

This script works all right on my small localhost running apache and php, however on my small web server (examined on 2 servers), I get a 400 Bad Request error. I had been formerly getting a 'connection refused' error, but it was resolved by my host sending the right port.

Is 400 not something similar to incorrect syntax? Could this be because i've the "[USER]:[PASSWORD]@" within the url? If that's the case, can there be one other way I'm able to authenticate before you run readfile?

I've run the next cases to look for the response code

readfile('http://[USER]:[PASSWORD]@[IPADDRESS]:[PORT]/NONEXISTINGFILE.cgi');
// Returns 400 Bad Request (Should be 404)

readfile('http://[IPADDRESS]:[PORT]/NONEXISTINGFILE.cgi');
// Returns 404 Not Found (Correct Response)

readfile('http://[IPADDRESS]:[PORT]/videostream.cgi');
// Returns 401 Unauthorized (Correct Response)

readfile('http://[USER]:[PASSWORD]@[IPADDRESS]:[PORT]/videostream.cgi');
// Returns 400 Bad Request (Incorrect - Should be .. 200(?) OK)

readfile('http://[USER]:[PASSWORD]@[IPADDRESS]:[PORT]/FILETHATDOESEXIST.jpg');
// Returns 400 Bad Request (Should be 200(?) OK)

readfile('http://[IPADDRESS]:[PORT]/FILETHATDOESEXIST.jpg');
// Returns 200(?) OK (Correct Response)

If a person has the capacity to produce the curl same as this script, possibly this is actually the solution. The Bounty still stands to anybody who are able to solve this for me personally :)

Regards,

For curl, try something similar to:

<?php

# Stop apache timing out
set_time_limit(0);

# Set the correct header
header('Content-Type: multipart/x-mixed-replace;boundary=ipcamera');

# Read the images
$ch = curl_init('http://[IPADDRESS]:[PORT]/videostream.cgi');
curl_setopt($ch, CURLOPT_USERPWD, '[USER]:[PASSWORD]');
curl_exec($ch);

If you wish to continue using readfile(), you could use stream_context_create() to create a stream context for readfile. See this documentation on php.net to determine how that may be done - particularly, you will need to create an HTTP stream context that passes an Authentication header.

simply look at your [USER] and [PASSWORD] ... make certain it doesn't consists of :, /, @ ...

if there's escape it with \

You may have something occur your PHP.INI around the production server that's crippling readfile's capability to load exterior Web addresses.

I am particularly considering allow_url_fopen which might be set to FALSE, although it might be another thing.

You may also check you web server's error log for clues. PHP will often emit a particular warning.