Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Here is some code to get around this.
- PHP:
- $url = "http://192.168.1.$camera/cgi-bin/snapshot.cgi";
- $options = array(
- CURLOPT_URL => $url,
- CURLOPT_HEADER => true,
- CURLOPT_VERBOSE => true,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_FOLLOWLOCATION => true,
- CURLOPT_SSL_VERIFYPEER => false, // for https
- CURLOPT_USERPWD => $username . ":" . $password,
- CURLOPT_HTTPAUTH => CURLAUTH_DIGEST
- );
- $ch = curl_init();
- curl_setopt_array( $ch, $options );
- try {
- $raw = curl_exec( $ch );
- // validate CURL status
- if(curl_errno($ch))
- throw new Exception(curl_error($ch), 500);
- // validate HTTP status code (user/password credential issues)
- $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- if ($status_code != 200)
- throw new Exception("Response with Status Code [" . $status_code . "].", 500);
- } catch(Exception $ex) {
- if ($ch != null) curl_close($ch);
- throw new Exception($ex);
- }
- if ($ch != null) curl_close($ch);
- $start = strpos($raw,"\xff");
- $end = strpos($raw,$boundary,$start)-1;
- $frame = substr("$raw",$start,$end - $start);
- header("Content-type: image/jpeg");
- echo $frame;
- Javascript -- cache the http credentials in the background so the browser doesn't ask for them:
- function cacheHttpCameraCredentials(sender='default') {
- // Cache http user/pass for cameras
- $.ajax({
- type: 'GET',
- url: 'http://192.168.1.123/cgi-bin/snapshot.cgi',
- username: 'admin',
- password: 'admin',
- success : function(data) {
- //Success block
- console.log('Cached webserver camera credentials: ' + sender);
- },
- error: function (xhr,ajaxOptions,throwError){
- //Error block
- console.log('Error caching camera credentials: ' + sender);
- },
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement