Link to home
Start Free TrialLog in
Avatar of tankergoblin
tankergoblin

asked on

how to set a user/pass to avoid the login prompt

is there anyway to set a user/pass in php to avoid the login prompt from HTTP authentication?
I want to by pass the login prompt with my own login form.
Avatar of fraserc
fraserc
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi,

You would need to remove the HTTP authentication to remove the prompt as there is no way to suppress or populate the dialogue box .
Usually this would be achieved by removing the relevant lines from the relevant Apache .htaccess file.

F.
Or changing IIS security options to use anonymous access.
Avatar of tankergoblin
tankergoblin

ASKER

i do not want a dialogue box i want to by pass the login page and direct me to the page that i want
i do not want a dialogue box i want to by pass the login page and direct me to the page that i want

i have try to copy the source code on the login page to my page and manually enter the use/pass and that doest work
im using apache

understood, those are probably your best solutions. If you really want to do it anyway, look here:

http://us2.php.net/features.http-auth
can you a simple code for me to see?
base on above how does the code know which site i want to login
and which username and password i need to type in?


<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
    header('WWW-Authenticate: Basic realm="My Realm"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Text to send if user hits Cancel button';
    exit;
} else {
    echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
    echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
}
?>
furthermore the page you show me is to prompt login for me type in username and password
i dont want this
i want to by pass login page.
Understood. Those are the headers its checks. Is the page running under the same web application / server? If so, running php under Apache as a module, you should be able to set

$_SERVER['PHP_AUTH_USER'] = username;
and
$_SERVER['PHP_AUTH_PW'] = password;

If not, you are probably SOL since you can't force the headers sent to a foreign application / host. At best, you could proxy the information, but that's a stretch. If the foreign website doesn't like you doing this, they could cut you off at any time.
Please read my fist comment again. If you dont want a dialogue the you MUST remove the http authentication. You cannot bypass or supress the authentication - only remove it!
You must have an .htaccess file in the directory.  Make sure that you can view invisible files and look for an .htaccess file.  You must have authentication set up.  If that is all there is in the .htaccess file you can probably delete it.  Otherwise, you need to remove just the part that checks for the correct username/password, usually an some code to restrict access.
@geowrian, @tankergoblin - The page can not load UNTIL IT HAS AUTHENTICATED, so NO php code can run at all!

@sscoti - That* is exactly* what I said in the first answer to the question (ID:24456505) and in my last comment (ID:24457407)
@fraserc:  You are right.  Just not sure it he tried it from the comments.
Some ftp browsers or file managers require you to set your preferences to see invisible files in order to see the .htaccess file.
@fraserc
That's correct; however, if the code is running within the same web application scope, a php script (that does not require authentication to load) can set those parameters prior to redirecting the user to the page that does require authentication. Although I have not done this personally, it is plausible. That said, I am reiterating that I do not suggest this approach.

And the ability to proxy the information is still possible via php, but I also do not suggest that.
ASKER CERTIFIED SOLUTION
Avatar of fraserc
fraserc
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial