Jump to content

header difficulties


me16_17

Recommended Posts

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...