Link to home
Start Free TrialLog in
Avatar of nfuids
nfuids

asked on

HTTP Authentification

I know this question has already been asked and I looked at http://www.phpbuilder.com/mail/php-general/2000091/1829.php

but without success! Here is my php script:

<?php

$string = GetFromHost("www.partenaires12-18.qc.ca", "/phpmyadmin");

print $string;


function GetFromHost($host,$path)
{
  $fp = fsockopen($host,80);
  set_socket_blocking($fp, true);
  fputs($fp,"GET $path HTTP/1.0\r\nAuthorization: Basic " . base64_encode("username:password")."\r\n\r\n");
  while(!feof($fp)){
    $string .= fgets($fp,1024);
  }
  fclose($fp);
 return $string;
}

?>


First of all, this return me a 401 Authorization Required
Second, I don't want to have the result into $string, but I want the user to be redirected to the appropriate page, so he can navigate through the admin area .. that function return the page.. do you follow me here? :)

Thanks for you help
ASKER CERTIFIED SOLUTION
Avatar of axis_img
axis_img

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of axis_img
axis_img

Couple of notes...


In this line, you obviously need to replace USERNAME and PASSWORD with the correct values:

readfile("http://USERNAME:PASSWORD@www.partenaires12-18.qc.ca/phpmyadmin/");

Also... readfile() only returns the number of bytes read, not a string of the contents read. The function automatically displays the content to stdout, which I think is what you said you wanted.

http://www.php.net/manual/en/function.readfile.php
Avatar of nfuids

ASKER

I would like to use header location.. this wont work since the username/pass are encrypted using base64 and the Authentification header needs to be passed along with the resquest I guess :(