Auto-login into the IP Camera

10,635

Ok, so I've made it work using PHP and JavaScript. Maybe it will be helpful for someone else:

Save the PHP file as, for example, snapshot.php:

<?php
$img="http://user:password@camera_ip/cgi-bin/jpg/image.cgi?"; 
header ('content-type: image/jpeg'); 
readfile($img); 
?> 

In the HTML file, add this script:

<img src="http://domain.com/snapshot.php" width="640" height="380" name="refresh">

<script language="JavaScript" type="text/javascript">     
image = "http://domain.com/snapshot.php"
function Start() {
tmp = new Date();
tmp = "?"+tmp.getTime()
document.images["refresh"].src = image+tmp
setTimeout("Start()", 300)
}
Start();       
</script>

It works ok under every browser. If I set timeout to less then 300, there is some lag. I don't know why that would be caused by; maybe internet connection or website speed.

Share:
10,635
Odin
Author by

Odin

Updated on June 04, 2022

Comments

  • Odin
    Odin almost 2 years

    I have a IP Camera and I would like to show liveview at my webpage.

    IP Camera don't allow for anonymous log in so I need to put username and password while connecting.

    I have javascript:

    <img src="http://user:password@camera_ip_address/cgi-bin/jpg/image.cgi?" width="640" height="480" name="refresh">
    
    <script language="JavaScript" type="text/javascript">     
    image = "http://camera_ip_address/cgi-bin/jpg/image.cgi?"
    function Start() {
    tmp = new Date();
    tmp = "?"+tmp.getTime()
    document.images["refresh"].src = image+tmp
    setTimeout("Start()", 100)
    }
    Start();       
    </SCRIPT>
    

    And it works ok in firefox but:

    http://user:password@camera_ip_number
    

    don't work in other browsers (it popup a form to enter username and password).

    But in PHP you can use user:password I've check it by using:

    <?php
    header('Content-type: image/jpeg');
    print( file_get_contents( 'http://user:password@camera_ip_address/cgi-bin/jpg/image.cgi?' ));
    ?>
    

    of course it shows only one frame but you don't have to enter username and password.

    How can I log in into IP Camera using PHP ? If I could log in one time while enetering webpage, my javascript will work ok because browser will remember username and password until I close the browser.

    I don't know how to send username and password to log in.

    Sorry for my English.