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条)

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值