Image from a secure site
| From: | Manolet Gmail | Date: | Thu, 08 Mar 2007 21:51:16 +0000 |
| Subject: | Image from a secure site | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-250129@lists.php.net to get a copy of this message | ||
hi, i install 4 IP cameras and i want to extract the images from their
web interface that is protected be a username and password (HTTP AUTH)
and show it into another system. so i do a function to connect to it
and get the image...
function subd($host,$port,$ownername,$passw,$request) {
$sock = fsockopen($host,$port);
if(!$sock) {
print('Socket error');
exit();
}
$authstr = "$ownername:$passw";
$pass = base64_encode($authstr);
$in = "GET $request\r\n";
$in .= "HTTP/1.0\r\n";
$in .= "Host:$host\r\n";
$in .= "Authorization: Basic $pass\r\n";
$in .= "\r\n";
fputs($sock, $in);
while (!feof($sock)) {
$result .= fgets ($sock,128);} fclose( $sock ); return $result; } and next i want to print it into the browser.. $request = "/IMAGE.JPG?cidx=20072261649239281"; $result = subd('contelec.sytes.net',2002,"invitado","invitado",$request); header ('Content-type: image/jpeg'); imagejpeg($result); exit(); but doesnt work.... if you want to check the cam you can go to http://contelec.sytes.net:2002 the username is invitado and the password is invitado. please help me!