Is it possible using header function to redirect using authentication?
I have tried with:
header("Location: http://mydomain.com/protected/protected.html"); header("Authorization: Basic $encodedstring");
and tried reversing order to no avail. Is this possible? What must be done? Thanks.
As soon as the client encounters a location header, it requests the new page, regardlesss of the other headers. So no it is not possible.
You will need to use a PHP based authentication system to achieve this.
You could authenticate then send a location header.
From PHP.NET:
<?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 { /* check username and password here */ header("Location: http://mydomain.com/protected/protected.html"); } ?>
I seem to remember reading a browser can save authentication information for subsequent pages in the same realm. Might it be possible to authenticate first and then redirect? Thanks.