me16_17 Posted March 1, 2006 Share Posted March 1, 2006 ok im trying to make a basic not really all that secure password system (because i dont know how to use encrypted files )http://65.170.242.137/mail.phpbut i am getting this errorWarning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\mail.php:7) in C:\Program Files\Apache Group\Apache2\htdocs\mail.php on line 47Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\mail.php:7) in C:\Program Files\Apache Group\Apache2\htdocs\mail.php on line 48it has been giving me this error whenever i try to use the header() command Link to comment Share on other sites More sharing options...
pulpfiction Posted March 1, 2006 Share Posted March 1, 2006 The "headers already sent" error is usually caused by having white space before or after the opening and closing PHP tags (<?php . . . ?>).http://forum.mamboserver.com/showthread.php?t=49427 Link to comment Share on other sites More sharing options...
me16_17 Posted March 1, 2006 Author Share Posted March 1, 2006 still cant seem to get it to workheres the code <?php $auth = false; // Assume user is not authenticatedif (isset( $PHP_AUTH_USER ) && isset($PHP_AUTH_PW)) { // Read the entire file into the variable $file_contents $filename = 'password.txt'; $fp = fopen( $filename, 'r' ); $file_contents = fread( $fp, filesize( $filename ) ); fclose( $fp ); // Place the individual lines from the file contents into an array. $lines = explode ( "\n", $file_contents ); // Split each of the lines into a username and a password pair // and attempt to match them to $PHP_AUTH_USER and $PHP_AUTH_PW. foreach ( $lines as $line ) { list( $username, $password ) = explode( ':', $line ); if ( ( $username == "$PHP_AUTH_USER" ) && ( $password == "$PHP_AUTH_PW" ) ) { // A match is found, meaning the user is authenticated. // Stop the search. $auth = true; break; } }}if ( ! $auth ) { header('WWW-Authenticate: Basic realm="Private"'); header('HTTP/1.0 401 Unauthorized'); echo 'Authorization Required.'; exit;} else { echo '<P>You are authorized!</P>';} ?> Link to comment Share on other sites More sharing options...
pulpfiction Posted March 1, 2006 Share Posted March 1, 2006 did you check the code for blank spaces before and after the <? ... ?>? cos i cant check it here. Link to comment Share on other sites More sharing options...
me16_17 Posted March 1, 2006 Author Share Posted March 1, 2006 did you check the code for blank spaces before and after the <? ... ?>? cos i cant check it here.<{POST_SNAPBACK}> what code are we talking about that the white space needs to be fixed? Link to comment Share on other sites More sharing options...
pulpfiction Posted March 1, 2006 Share Posted March 1, 2006 C:\Program Files\Apache Group\Apache2\htdocs\mail.php Link to comment Share on other sites More sharing options...
me16_17 Posted March 1, 2006 Author Share Posted March 1, 2006 C:\Program Files\Apache Group\Apache2\htdocs\mail.php<{POST_SNAPBACK}> ya thats the code i pasted above Link to comment Share on other sites More sharing options...
gsmith Posted March 2, 2006 Share Posted March 2, 2006 I'm not exactly sure what your header problem is....but you could cut down some of your code and just use the file command....Instead of: $filename = 'password.txt'; $fp = fopen( $filename, 'r' ); $file_contents = fread( $fp, filesize( $filename ) ); fclose( $fp ); // Place the individual lines from the file contents into an array. $lines = explode ( "\n", $file_contents ); You could have: $filename = 'password.txt';$lines=file($filename); file() will read the contents of a file into an array. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now