Issue Solved! Soulution: Output Buffering. Thanks to icio and mainegate for the help!
hello! I am totally new to PHP, and I am trying to make use of a simple login script, that checks usernames and passwords against a flat text file, but I am encountering an error. I have looked into the use of - header(“Location: blah.com”); and found that it will not work if used after echo, or outputting data (correct?) the header function is called before any echo - Could someone point me in the right direction? here is the code i used, the errors i recieved, a link to the page itself, and a username and password for test.
username: kirupa
password: test
link: http://www.thanative.com/eteam/login.php
The Code:
<?php
if ($_SERVER['REQUEST_METHOD']=="POST"){
// Get UserNames and Passwords.
$Logi = file("users/log.txt");
// Work out how many there are
$size = sizeof($Logi);
// Break apart passwords and usernames
foreach($Logi as $Key => $Val)
{ $Data[$Key] = explode("||", $Val); }
// run through list and see if any match
for($K = 0; $K<$size; $K++)
{
$user = $Data[$K][0];
$pass = $Data[$K][1];
// If match set cookie and redirect.
if ($user == trim(addslashes($_POST["user"])) && $pass == trim(addslashes($_POST["pass"])) )
{
setcookie("in", 1, time()+3600);
// Start hidden page
header("Location: www.thanative.com");
}
}
echo "Login Failed.";
// If you didnt log in show login form
} else { ?>
<div style="width:250px">
<div><strong>Black Sheep E-Team Login</strong></div>
<div><form name="Login" method="post" action="<?=$_SERVER['PHP_SELF'];?>">
<div align="right">Username:
<input name="user" type="text" >
<br>
Password:
<input name="pass" type="password" >
<br>
<input type="submit" name="Submit" value="Submit">
</div>
</form>
</div></div>
<?php
}
?>
The Errors:
Warning: Cannot modify header information - headers already sent by (output started at /home/www/thanative/login.php:8) in /home/www/thanative/login.php on line 26
Warning: Cannot modify header information - headers already sent by (output started at /home/www/thanative/login.php:8) in /home/www/thanative/login.php on line 27
Login Failed.
I would truly appreciate any help you guys could offer with this!