For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > August 2007 > Axis camera and PHP









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Axis camera and PHP
Stefano

2007-08-12, 6:59 pm

I have to send a restart command to an IP camera from a PHP script. The
command is as follow:

http://192.168.1.5/axis-cgi/admin/restart.cgi

where 192.168.1.5 is the address of the camera.

In PHP, my idea was to open a socket connection and send the command, with
the following code:

$host="192.168.1.5" ;
$target="/axis-cgi/admin/restart.cgi" ;
$port=80 ;
$timeout=60;
$br="\r\n" ;
$usarname="root";
$password="password_root";
$sk=fsockopen($host,$port,$errnum,$errst
r,$timeout) ;
if(!is_resource($sk)){
exit("Connection failed: ".$errnum." ".$errstr) ;
}
else{
$headers = "GET ".$target." HTTP/1.1".$br ;
$headers.="Accept: */*".$br ;
$headers.="Accept-Language: it".$br ;
$headers.="Host: ".$host.$br ;
$headers.="Authorization: Basic root:password_root".$br.$br;
fputs($sk,$headers) ;

When printing $sk I see the error message

401 Unauthorized
You client does not have permission to get URL /axis-cgi/admin/restart.cgi
from this server

Seems there is something wrong with authentication.

Any idea ?
Is there somebody who uses PHP with Axis camera ? How do you send API
commands to the camera ?


Thank you for your help.

Stefano


C.

2007-08-13, 7:58 am

On 12 Aug, 16:34, "Stefano" <o...@interfree.it> wrote:
> I have to send a restart command to an IP camera from a PHP script. The
> command is as follow:
>
> http://192.168.1.5/axis-cgi/admin/restart.cgi

<snip>
> $usarname="root";
> $password="password_root";
> $sk=fsockopen($host,$port,$errnum,$errst
r,$timeout) ;
> if(!is_resource($sk)){
> exit("Connection failed: ".$errnum." ".$errstr) ;}
>
> else{
> $headers = "GET ".$target." HTTP/1.1".$br ;
> $headers.="Accept: */*".$br ;
> $headers.="Accept-Language: it".$br ;
> $headers.="Host: ".$host.$br ;
> $headers.="Authorization: Basic root:password_root".$br.$br;
> fputs($sk,$headers) ;
>

<snip>
> When printing $sk I see the error message
>
> 401 Unauthorized
> You client does not have permission to get URL /axis-cgi/admin/restart.cgi
> from this server
>


Why are you rolling your own HTTP stack? PHP comes with 2 builtin
methods - file wrappers and Curl which are both capable of handling
basic authentication (and ssl).

One reason your code is not working is because you haven't base64
encoded the username and password (and you're sending literals not
variables).

C.

Stefano

2007-08-13, 7:00 pm

You're right. It works now using base64_encode().
Thanks.
Stefano


"C." <colin.mckinnon@gmail.com> ha scritto nel messaggio
news:1187006754.240830.17030@g4g2000hsf.googlegroups.com...
> On 12 Aug, 16:34, "Stefano" <o...@interfree.it> wrote:
> <snip>
> <snip>
>
> Why are you rolling your own HTTP stack? PHP comes with 2 builtin
> methods - file wrappers and Curl which are both capable of handling
> basic authentication (and ssl).
>
> One reason your code is not working is because you haven't base64
> encoded the username and password (and you're sending literals not
> variables).
>
> C.
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com