Solved

HTTP Authentification

Posted on 2002-07-02
3
655 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

691 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