• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 663
  • Last Modified:

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
0
nfuids
Asked:
nfuids
  • 2
1 Solution
 
axis_imgCommented:
This may be exactly what you want to avoid, but thought I would mention it nevertheless... Instead of using fsockopen(), you can also do:

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

It will basically just display the page. To actually _do_ the redirect, I have tried using stuff like:

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

But that never seemed to work. I am sure it is a matter of header timing, etc. Anyway... the readfile() should work ok. Let me know what problems it causes for you...

Regards,
Barry
0
 
axis_imgCommented:
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
0
 
nfuidsAuthor Commented:
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 :(


0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now