HTTP authentication from PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
neil6179
Forum Newbie
Posts: 3
Joined: Wed Jul 09, 2003 5:05 pm

HTTP authentication from PHP

Post by neil6179 »

Hi,

I have a website that’s main index page requires HTTP basic authentication which is currently done through apache. (This I cannot change)

What I am trying to do is create a PHP page that will relocate to this page using the code below and that will automatically log me on using the username and password already in the script.

Code: Select all

<?php
$user = “bob”; 
$passwd = “3he4kwf”; 

header( “Location: https://here.there.com”); 
?>
This redirects me to https://here.there.com however I am then prompted for my username and password.

One possible solution I have tried was:

Code: Select all

<?php 
$user = “bob”; 
$passwd = “3he4kwf”; 

header( “Location: https://$user:$passed@here.there.com”); 
?>
However this still prompts for a login, thus doesn’t work.

Another tried solution is:

Code: Select all

<?php 
$user = “bob”; 
$passwd = “3he4kwf”; 

header( “Location: https://here.there.com”); 
header(“Authorization: Basic “.base64_encode(“$user:$passwd”)) 

?>
This also does not work!

Does anyone have another solution that might work me?
Any extra information will be most welcome!

Neil
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Code: Select all

<?php
$user = “bob”; 
$passwd = “3he4kwf”; 
header( “Location: https://$user:$passwd@here.there.com”); 
?>
Worked for me, after I corrected a typo in the password (just in case you didn't notice, never know).
But (!) I'm not using SSL and https:// but http:// á la regular.

Perhaps you cannot provide header logins with those, or at least you have more info to go on...
Post Reply