douzi2785 2013-11-22 17:15
浏览 120
已采纳

自动登录IP摄像机

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.

  • 写回答

3条回答 默认 最新

  • douyao1856 2014-01-13 15:02
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条