abrogard Posted March 5, 2017 Share Posted March 5, 2017 (edited) Windows 10. IIS. when I try to echo or print $_SERVER values in my logon script (which I got from the web. I am very much a total beginner) I get no output at all. It seems to stop everything. There's something I am not understanding. Can anyone help? What I am trying to do is get the logged in User's name so's I send different users to different pages: each their own page. I have windows authentication on so they've all had to give a windows user logon to get to this page. then on this page they have give another login so's they can be prevented from going to each other's pages. If you see what I mean. That's the plan. I will post the script and you can see where I've put the echo. <?php/************************************************************************//* PHP Simple PasswordProtect v1.0 *//* =========================== *//* *//* Written by Steve Dawson - http://www.stevedawson.com *//* Freelance Web Developer - PHP, MySQL, HTML programming *//* *//* This program is free software. You can redistribute it and/or modify *//* but please leave this header intact, thanks *//************************************************************************/##########################################################################$password = "admin"; // Modify Password to suit for access, Max 10 Char.##########################################################################?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>Simple Password Protect - PHP PasswordProtect</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css"><!--P { FONT-SIZE: 8pt; COLOR: #000000; FONT-FAMILY: Verdana, Tahoma, Arial}TD { FONT-SIZE: 8pt; COLOR: #000000; FONT-FAMILY: Verdana, Tahoma, Arial}--></style></head><body><?php print "<h2 align=\"center\">PHP Simple Password Protect</h2>";// If password is valid let the user get accessif (isset($_POST["password"]) && ($_POST["password"]=="$password")) { header('Location: diana');?><!-- START OF HIDDEN HTML - PLACE YOUR CONTENT HERE --> <p align="center"><br><br><br> <b>Congratulations</b><br>you have gained access to the Protected and Secret Area!</p> <?php // doesn't work when put here.//echo $_SERVER['LOGON_USER']//echo $_SERVER['AUTH_USER']//echo $_SERVER['REDIRECT_LOGON_USER']//echo $_SERVER['REDIRECT_AUTH_USER']?><!-- END OF HIDDEN HTML --><?php}else{// Wrong password or no password entered display this messageif (isset($_POST['password']) || $password == "") { print "<p align=\"center\"><font color=\"red\"><b>Incorrect Password</b><br>Please enter the correct password</font></p>";} print "<form method=\"post\"><p align=\"center\">Please enter your password for access<br>"; print "<input name=\"password\" type=\"password\" size=\"25\" maxlength=\"10\"><input value=\"Login\" type=\"submit\"></p></form>";} print "<br><br><p align=\"center\">Written by <a href=\"http://www.stevedawson.com\">SteveDawson.com</a></p>";?><BR></body></html> Edited March 5, 2017 by abrogard Quote Link to comment Share on other sites More sharing options...
benanamen Posted March 5, 2017 Share Posted March 5, 2017 (edited) You need to stop grabbing stuff off the net. This code is junk. Your time will be better spent to actually learn how to do what you want. Edited March 5, 2017 by benanamen Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted March 6, 2017 Share Posted March 6, 2017 At the very beginning of your script, add the following three lines. If you are using sessions or setting headers, you need to be careful not to send content to the page (i.e. echo something), but for your script you are not doing so, so no worries. You can use var_dump() instead of print_r() to get a little more information, but I often find print_r() easier to read. Spend some time looking at the results. $_GET and $_POST are all yours, but for the $_SERVER output, use http://php.net/manual/en/reserved.variables.server.php to understand what they mean. If you are using sessions, cookies, etc, use the same approach as shown below to display "what you have". <?php echo('$_SERVER:<pre>'.print_r($_SERVER,1).'</pre>'); echo('$_GET:<pre>'.print_r($_GET,1).'</pre>'); echo('$_POST:<pre>'.print_r($_POST,1).'</pre>'); /************************************************************************/ /* PHP Simple PasswordProtect v1.0 */ /* =========================== */ Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 6, 2017 Share Posted March 6, 2017 Once you issue the header command the script doesn't execute anymore. Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted March 6, 2017 Share Posted March 6, 2017 Once you issue the header command the script doesn't execute anymore. Not true. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 6, 2017 Share Posted March 6, 2017 I should have specified "using the Location" instruction, as the OP was doing Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted March 6, 2017 Share Posted March 6, 2017 No, the script keeps running. Setting the Location header just sets the header, it doesn't magically stop the script. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 6, 2017 Share Posted March 6, 2017 So in this case, if it doesn't take you to another 'place', what IS it doing? Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted March 6, 2017 Share Posted March 6, 2017 It sets an HTTP header, that's it. The control flow of the script isn't affected in any way. Redirection happens client-side after the response has been sent. That's when the client may or may not decide to follow the URL in the Location header. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 6, 2017 Share Posted March 6, 2017 (edited) So that would be triggered by the exit() that usually follows one of these? So getting back to the OP's question. Since his SERVER outputs are all commented out in his post, what are we supposed to be diagnosing for him? Oh - Silly Me! If he had php error checking turned on, would he be seeing that "headers already sent" message and his echos would be failing because of that header? Edited March 6, 2017 by ginerjm Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 6, 2017 Share Posted March 6, 2017 It sets an HTTP header, that's it. The control flow of the script isn't affected in any way. Redirection happens client-side after the response has been sent. That's when the client may or may not decide to follow the URL in the Location header. Good point. A header to perform a redirect should (almost) always be followed by an exit() statement. Otherwise, depending on the structure of the logic flow, there could be additional logic that is being unnecessarily processed on that script. Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 6, 2017 Share Posted March 6, 2017 (edited) // doesn't work when put here. //echo $_SERVER['LOGON_USER'] //echo $_SERVER['AUTH_USER'] //echo $_SERVER['REDIRECT_LOGON_USER'] //echo $_SERVER['REDIRECT_AUTH_USER'] I assume you have error reporting off, because the above lines will cause an error (when they are not commented out) because they are not terminated with semi-colons. 1. Turn on error reporting when developing so you can see and fix errors. error_reporting(E_ALL); ini_set('display_errors', 1); 2. Add a semi-colon to the above lines if you want to output them to the page // doesn't work when put here. echo $_SERVER['LOGON_USER']; echo $_SERVER['AUTH_USER']; echo $_SERVER['REDIRECT_LOGON_USER']; echo $_SERVER['REDIRECT_AUTH_USER']; EDIT: I would suggest doing #1 first and then just un-commenting those lines and executing the script. That way you can verify that the error is reported and understand what it would look like. Edited March 6, 2017 by Psycho Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.