Note that there are some explanatory texts on larger screens.

plurals
  1. POAdmin username/password isn't working for PHP
    primarykey
    data
    text
    <p>So I am currently taking a course in PHP Programming and I have finally gotten into the art of Authentication and Authorization. </p> <p>So in the book, we started by restricting the page that grants access to all the accounts where you can update and delete all of them. We started by defining the constants:</p> <pre><code>define('VALID_USERNAME', ''); define('VALID_PASSWORD', ''); </code></pre> <p>To make it easy on myself, I just put them as empty strings.</p> <p>Everything goes smoothly, the dialogue that asks for the username and password pop up. However, when I put the empty strings in, the dialogue box keeps popping up as if the password was wrong, or it just didn't take the password at all. This happens even when I define the username and password with real strings. </p> <p>Here is my code for that portion:</p> <pre><code>if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) { header('http/1.1 401 Unauthorized'); header('WWW-Authenticate: Basic realm="Wonder Penguin"'); } else { if (($_SERVER['PHP_AUTH_USER'] != VALID_USERNAME) || ($_SERVER['PHP_AUTH_PW'] != VALID_PASSWORD)) { header('http/1.1 401 Unauthorized'); header('WWW-Authenticate: Basic realm="Wonder Penguin"'); } } </code></pre> <p>If you're wondering why I didn't use the exit() function to prevent people from hitting cancel to bypass the authentication and getting to the update page. I did that so my teacher can grade this page that I created last assignment. </p> <p><strong>How I've tired to troubleshoot:</strong></p> <p>I tested to see if I defined the valid usernames and passwords correctly by using the echo functions.</p> <pre><code>echo VALID_USERNAME; echo VALID_PASSWORD; </code></pre> <p>And it pops up exactly what I defined it as. So in theory, I think I defined it correctly.</p> <p>I tried to write the define function with single quotes, double quotes, and no quotes. The book wants me to write the function like this:</p> <pre><code>define(VALID_USERNAME, "admin"); define(VALID_PASSWORD, "password"); </code></pre> <p>However, this brings up an error that I am using an undefined constant when I tried to define them right there. </p> <p><code>var_dump($_SERVER);</code> Results:</p> <pre><code>array(37) { ["REDIRECT_HANDLER"]=&gt; string(23) "application/x-httpd-php" ["REDIRECT_STATUS"]=&gt; string(3) "200" ["HTTP_HOST"]=&gt; string(20) "patti-bee2.dcccd.edu" ["HTTP_CONNECTION"]=&gt; string(10) "keep-alive" ["HTTP_ACCEPT"]=&gt; string(74) "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" ["HTTP_USER_AGENT"]=&gt; string(108) "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36" ["HTTP_ACCEPT_ENCODING"]=&gt; string(17) "gzip,deflate,sdch" ["HTTP_ACCEPT_LANGUAGE"]=&gt; string(14) "en-US,en;q=0.8" ["HTTP_COOKIE"]=&gt; string(217) "__qca=P0-630369357-1378011844686; __utma=198331962.264424896.1377179965.1382812794.1384740700.12; __utmc=198331962; __utmz=198331962.1381981575.8.4.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)" ["PATH"]=&gt; string(135) "C:\Program Files (x86)\PHP\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\php;" ["SystemRoot"]=&gt; string(10) "C:\Windows" ["COMSPEC"]=&gt; string(27) "C:\Windows\system32\cmd.exe" ["PATHEXT"]=&gt; string(53) ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC" ["WINDIR"]=&gt; string(10) "C:\Windows" ["SERVER_SIGNATURE"]=&gt; string(0) "" ["SERVER_SOFTWARE"]=&gt; string(21) "Apache/2.2.22 (Win32)" ["SERVER_NAME"]=&gt; string(20) "patti-bee2.dcccd.edu" ["SERVER_ADDR"]=&gt; string(14) "144.162.99.193" ["SERVER_PORT"]=&gt; string(2) "80" ["REMOTE_ADDR"]=&gt; string(11) "99.7.247.36" ["DOCUMENT_ROOT"]=&gt; string(66) "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs" ["SERVER_ADMIN"]=&gt; string(16) "pburks@dcccd.edu" ["SCRIPT_FILENAME"]=&gt; string(106) "C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\Coleman\Wonder Penguin\PHP\show_all.php" ["REMOTE_PORT"]=&gt; string(5) "54619" ["REDIRECT_URL"]=&gt; string(40) "/coleman/wonder penguin/php/show_all.php" ["GATEWAY_INTERFACE"]=&gt; string(7) "CGI/1.1" ["SERVER_PROTOCOL"]=&gt; string(8) "HTTP/1.1" ["REQUEST_METHOD"]=&gt; string(3) "GET" ["QUERY_STRING"]=&gt; string(0) "" ["REQUEST_URI"]=&gt; string(42) "/coleman/wonder%20penguin/php/show_all.php" ["SCRIPT_NAME"]=&gt; string(40) "/coleman/wonder penguin/php/show_all.php" ["ORIG_SCRIPT_FILENAME"]=&gt; string(18) "C:/PHP/php-cgi.exe" ["ORIG_PATH_INFO"]=&gt; string(40) "/coleman/wonder penguin/php/show_all.php" ["ORIG_PATH_TRANSLATED"]=&gt; string(106) "C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\Coleman\Wonder Penguin\PHP\show_all.php" ["ORIG_SCRIPT_NAME"]=&gt; string(16) "/php/php-cgi.exe" ["PHP_SELF"]=&gt; string(40) "/coleman/wonder penguin/php/show_all.php" ["REQUEST_TIME"]=&gt; int(1385432192) } </code></pre> <p>I have pretty much copied it straight out of the book at this point. What am I doing wrong?</p> <p>If you want to try it out for yourself, here is <a href="http://patti-bee2.dcccd.edu/coleman/wonder%20penguin/php/show_all.php" rel="nofollow">link to my site</a>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload