PHP basic auth setHeader if data incorrect -


i'm building api endpoint. endpoint needs secured http basic auth.

if api requests access show http basic auth, if data incorrect throw 403 forbidden message. if data correct show "correct" @ moment. here's code:

  $username = null;   $password = null;    // if data sent   if (isset($_server['php_auth_user']) && isset($_server['php_auth_pw']) ) {       $username = $_server['php_auth_user'];       $password = $_server['php_auth_pw'];        //perforn check if data correct       if($username == 'as' && $password = 'pass'){         die(var_dump("correct"));       }       //if data uncorrect throw 403 code       else         header('http/1.0 403 forbidden');    }    //request http auth if nothing sent   if (!isset($_server['php_auth_user']) && !isset($_server['php_auth_pw'])) {        header('www-authenticate: basic realm="my realm"');       header('http/1.0 401 unauthorized');        die();    } 

at moment code triggering 403 time. idea how fix matching requirements described above?

you're missing 1 = making test assignment:

if($username == 'as' && $password == 'pass'){ //right here     die(var_dump("correct")); } else { //if data incorrect throw 403 code     header('http/1.0 403 forbidden'); } 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -