Hi everybody, I hope somebody can help me with this...
There are a section on my web site that is protected via http basic authentication. It works fine, asking for a valid username and password. But, if someone comes to this section from another application in wich the user provides a username and password, then I want that the user don't need to provide again a username and password. In other words, I want the user logs in automatically. But I get the next error:
PHP Warning: file_get_contents(http://localhost/secret/index.html) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: Se produjo un error durante el intento de conexi\xf3n ya que la parte conectada no respondi\xf3 adecuadamente tras un periodo de tiempo, o bien se produjo un error en la conexi\xf3n establecida ya que el host conectado no ha podido responder.\r\n in C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\auth5.php on line 8
The code below produces this error:
<?php
$url = 'http://localhost/secret/index.html';
$auth = base64_encode('mmucino:marquito');
$header = array("Authorization: Basic $auth");
$opts = array( 'http' => array ('method'=>'GET',
'header'=>$header));
$ctx = stream_context_create($opts);
file_get_contents($url,false,$ctx);
?>
What's wrong whit this? Thanks in advance.
Marco
Autoauthenticate
Moderator: General Moderators
Re: Autoauthenticate
How about you throw that code away and use
instead?
Code: Select all
file_get_contents($_SERVER["DOCUMENT_ROOT"] . "/secret/index.html");