View Full Version : Code Help Again =D [+ Rep]
Jahova
15-02-2007, 06:09 PM
Hi people I'm sorry about all my threads, I am pretty new to php ect...
I have this piece of code:
setcookie("in", 1, time()+3600);
// Start hidden page
header("Location: http://cowly.co.uk/staff/logged.htm");
Which are lines 24, 25, 26.
I get this error when trying to log in...
Warning: Cannot modify header information - headers already sent by (output started at /home/cowly1a/public_html/staff/index.php:6) in /home/cowly1a/public_html/staff/index.php on line 24
Warning: Cannot modify header information - headers already sent by (output started at /home/cowly1a/public_html/staff/index.php:6) in /home/cowly1a/public_html/staff/index.php on line 26
Login Failed.
Help will be appreciated and repped, or put on my rep list.
Thanks,
- T.</SPAN>
Drompo
15-02-2007, 06:12 PM
can you post whole code.
Jahova
15-02-2007, 06:17 PM
Sure, Its from the user system in the tut section, I need to just get it..
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Login</title>
<?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 appart passwords and usernames
foreach($Logi as $Key => $Val)
{ $Data[$Key] = explode("||", $Val); }
// run threw 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: http://cowly.co.uk/staff/logged.htm");
}
}
echo "Login Failed.";
// If you didnt log in show login form
} else { ?>
</div>
<style type="text/css">
<!--
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 9px;
font-weight: bold;
color: #666666;
}
body,td,th {
color: #999999;
}
body {
background-color: #FFC900;
}
.style2 {color: #000000}
.style3 {font-size: 9px; font-weight: bold; font-family: Verdana, Arial, Helvetica, sans-serif;}
-->
</style>
<div align="center" class="style1">
<div style="width:250px">
<div class="style2">
<p> </p>
<p> </p>
<p> </p>
<p>Login</p>
</div>
<div class="style2">
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post" name="Login" id="Login">
Username:
<input name="user" type="text" class="style3">
<br />
Password:
<input name="pass" type="password" class="style3">
<br />
<input name="Submit" type="submit" class="style3" value="Login!" />
</form>
</div>
</div>
<p class="style2"></p>
<p class="style2"></p>
<p>
<span class="style2">
<?php
}
?>
</span></p>
</div>
timROGERS
15-02-2007, 06:21 PM
It is because you can't use headers after you've already send data to the browser.
Jahova
15-02-2007, 06:35 PM
What are headers plz...
I AM A PHP NOOB!
- T.
you need to move ob_start to the top. cookie info is stored in the packet's header, when you start outputting contnet, the header gets sent (therefore you cannot ammend/add to it). by putting ob_start at the top, yuo buffer the output and send it once the server finishes parsing the file (so practically, the header doesn't get sent off.. and you can mess about with it).
sdfbdfbdurfngrd
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2026 vBulletin Solutions Inc. All rights reserved.