Extract data from HTTP Auth with PHP

0

I want to access a URL from my site as follows:

http://username:[email protected]

How do I, with PHP, receive the Username and Password data without using cURL? Is there a possibility?

    
asked by anonymous 06.02.2017 / 16:56

1 answer

0

If there is a possibility, just use the variables to http authentication , follow an example basic, just for understanding the operation

$valid_passwords = array("user" => "pass");
$valid_users = array_keys($valid_passwords);

//se você não colocou o user na url ele mostra a "caixa" autenticação
//caso queira obrigar o usuário a digitar ela url é só tirar o if
if(!isset($_SERVER['PHP_AUTH_USER'])){
    header('WWW-Authenticate: Basic realm="My Realm"');
}

$user = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : '';
$pass = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : '';



$validated = (in_array($user, $valid_users)) && ($pass == $valid_passwords[$user]);

if (!$validated) {

    header('HTTP/1.0 401 Unauthorized');
    echo $user." - ".$pass;
    die("Not authorized");


}

One important note is that in IE they put extra security protection, it might not work, more details #

    

06.02.2017 / 23:38