Question : Authenticate into password protected directory with php

Hi

Im trying to access a file with remote script

file is located on a password protected directory and i tried to access it like this with a javascript in a php file

1:
document.location = 'http://username:[email protected]/cgi-bin/test.cgi';	


problem is when the url calls im getting a confirm box contain

"You are about to log into the site "192.168.1.1" with the username ''  "

is there way to avoid that confirm box? or better authentication method?

sorry for language errors.

Thanks

 

Answer : Authenticate into password protected directory with php

Hello,
PHP 5 comes with built-in class called cURL,which is an extension for command line utility cURL that is "wget on steroids".It supports .htaccess authentication.
Suppose that your URL of protected directory is:
http://192.168.1.1/cgi-bin/test.cgi'
username:  3xtr3m3d
password: secret


From linux comand line, to get file test.cgi you would write:
curl http://3xtr3m3d:secret@192.168.1.1./cgi-bin/test.cgi   > test.cgi

From php code,this is the code that will read the file from remote, HTTP-autentication protected directroy,and put it in a string. With this string you can continue, whether you would like to write it to a file,or anything you want.So this is a basic,and I think it is pretty much self-explanatory:




1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
<?php

$url="http://192.168.1.1./cgi-bin/test.cgi";

 $options = array(
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_USERPWD        => "3xtr3m3d:secret",
    );



$ch      = curl_init( $url );

curl_setopt_array( $ch, $options );
    $content = curl_exec( $ch );
    curl_close( $ch );

echo $content;
Random Solutions  
 
programming4us programming4us