views:

35

answers:

2

Alright, I don't know if anyone has tried to do this yet, however.

I have a website lets just call it localhost. for now. I have a form on that page. however, I want to be able to skip the form, and redirect my data to the form by using the basic authentication method. for example: http://admin:admin@localhost would send the username and password to my form.

Is there a way to do that without me having to modify the entire website?

A: 

Very easy using the $_SERVER array.

<form>
  <input name="username" value="<?php echo $_SERVER['PHP_AUTH_USER']; ?>">
  <input type="password" value="<?php echo $_SERVER['PHP_AUTH_PW']; ?>">
</form>
Brandon Horsley
A: 

you don't need to send it to the form.

you can do something like this

if(!isset($_SESSION['admin'])){
        //we are not logged in yet,
        if (!isset($_SERVER['PHP_AUTH_USER'])) {
                header('WWW-Authenticate: Basic realm="Admin"');
                header('HTTP/1.0 401 Unauthorized');
                echo 'Please Contact us if you are having problems logging in';
                exit;
        } else {
                //not their first time through
                //check their username and password here
                $username = trim($_SERVER['PHP_AUTH_USER']);
                $password = trim($_SERVER['PHP_AUTH_PW']);
                ... your auth code here....  
Doon