php - Page authentication doesn't work -


this code o'reilly head first php&mysql book. script doesn't recognize username , password somehow:

    <?php   $username = 'rock';   $password = 'roll';    if (!isset($_server['php_auth_user']) || !isset($_server['php_auth_pw']) ||     ($_server['php_auth_user'] != $username) || ($_server['php_auth_pw'] != $password)) {     // user name/password incorrect send authentication headers     header('http/1.1 401 unauthorized');     header('www-authenticate: basic realm="guitar wars"');     exit('<h2>guitar wars</h2>sorry, must enter valid user name , password      access page.');   } ?> 

and script, authentication file required:

 <?php   require_once('authorize.php'); ?>  <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en"   "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head>   <meta http-equiv="content-type" content="text/html; charset=utf-8" />   <title>guitar wars - high scores administration</title>   <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body>   <h2>guitar wars - high scores administration</h2>   <p>below list of guitar wars high scores. use page remove scores needed.</p>   <hr />  <?php   require_once('appvars.php');   require_once('connectvars.php');    // connect database    $dbc = mysqli_connect(db_host, db_user, db_password, db_name);    // retrieve score data mysql   $query = "select * guitarwars order score desc, date asc";   $data = mysqli_query($dbc, $query);    // loop through array of score data, formatting html    echo '<table>';   echo '<tr><th>name</th><th>date</th><th>score</th><th>action</th></tr>';   while ($row = mysqli_fetch_array($data)) {      // display score data     echo '<tr class="scorerow"><td><strong>' . $row['name'] . '</strong></td>';     echo '<td>' . $row['date'] . '</td>';     echo '<td>' . $row['score'] . '</td>';     echo '<td><a href="removescore.php?id=' . $row['id'] . '&amp;date=' . $row['date'] .       '&amp;name=' . $row['name'] . '&amp;score=' . $row['score'] .       '&amp;screenshot=' . $row['screenshot'] . '">remove</a>';     if ($row['approved'] == '0') {       echo ' / <a href="approvescore.php?id=' . $row['id'] . '&amp;date=' . $row['date'] .         '&amp;name=' . $row['name'] . '&amp;score=' . $row['score'] . '&amp;screenshot=' .         $row['screenshot'] . '">approve</a>';     }     echo '</td></tr>';   }   echo '</table>';    mysqli_close($dbc); ?>  </body>  </html> 

can see what's wrong here? thank you!

the authentication code fine.

you might have spaces (before <?php) or else there before header() calls.. in case don't see authentication popup.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -