Solved

HTTP Authentification

Posted on 2002-07-02
3
629 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
xampp tool 12 47
php construct 5 24
error log using ftp 7 37
google analytics in wordpress 4 31
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.  …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

813 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

12 Experts available now in Live!

Get 1:1 Help Now