Solved

HTTP Authentification

Posted on 2002-07-02
3
613 Views
Last Modified: 2012-06-21
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
Comment
Question by:nfuids
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
axis_img earned 50 total points
ID: 7125824
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
 
LVL 7

Expert Comment

by:axis_img
ID: 7125833
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
 

Author Comment

by:nfuids
ID: 7125914
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now