PDA

View Full Version : Log in problem - PHP


neuro
05-25-2007, 04:24 PM
Hm... i was trying to create a log in with "setcookie" function, after a long hour i manage to get it work for the first time. When i tried to fix few things and try to log in again i got the following error:

Warning: Cannot modify header information - headers already sent by (output started at C:\Users\TIGER\Server\Web Root\Blog\index.php:9) in C:\Users\TIGER\Server\Web Root\Blog\index.php on line 28

Warning: Cannot modify header information - headers already sent by (output started at C:\Users\TIGER\Server\Web Root\Blog\index.php:9) in C:\Users\TIGER\Server\Web Root\Blog\index.php on line 29

Warning: Cannot modify header information - headers already sent by (output started at C:\Users\TIGER\Server\Web Root\Blog\index.php:9) in C:\Users\TIGER\Server\Web Root\Blog\index.php on line 35

couldnt find the answer till now...

index.php
------------------------------------------------------------------------

<!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=utf-8" />
<!-- **** layout stylesheet **** -->
<link rel="stylesheet" type="text/css" href="css/css.css" />
<title>Untitled Document</title>
</head>
<?php
if (isset($_POST['submitted'])) {
require_once ('connection/mysql_connect.php');
$errors = array();
if (empty($_POST['email'])) {
$errors[] = 'You forgot to enter your email address.';
} else {
$e = escape_data($_POST['email']);
}
if (empty($_POST['password'])) {
$errors[] = 'You forgot to enter your password.';
} else {
$p = escape_data($_POST['password']);
}
if (empty($errors)) {
$query = "SELECT user_id, first_name FROM users WHERE email='$e' AND password=SHA('$p')";
$result = @mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_NUM);
if ($row) {
setcookie ('user_id', $row[0], time()+3600, '/', '', 0);
setcookie ('first_name', $row[1], time()+3600, '/', '', 0);
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
$url = substr ($url, 0, -1);
}
$url .= '/loggedin.php';
header("Location: $url");
exit(); // Quit the script.
} else { // No record matched the query.
$errors[] = 'The email address and password entered do not match those on file.'; // Public message.
$errors[] = mysql_error() . '<br /><br />Query: ' . $query; // Debugging message.
}
}
mysql_close();
} else {
$errors = NULL;
}
?>
<body>
<!-- **** wrapper area **** -->
<div id="wrapper">
<!-- **** banner area **** -->
<div id="banner">
</div>
<!-- **** spacer area **** -->
<div id="spacer">
</div>
<!-- **** content area **** -->
<div id="main">
<!-- **** left content container - title area **** -->
<div id="left">
<h1>CINEMATOGRAPHY</h1>
<p align="justify">Picture composition is the break down of a picture into the foreground, middle ground and background. in all forms of photography and art, composition is critical in producing an interesting and well defined, result in spite of instinct, placing the subject always in the dead center of the picture can be just that.
Good composition is usually thought of in terms of an imaginary grid dividing up the picture plane, the picture plane is the actual space in which the image exists, variety is important in all aspects of creating good video and varying distance is no exception ,a video shot entirely from one distance, that is, the distance between the camera and the subject never varies ,would be unendurable dull , by choosing the distance of your shoot you establish and control the impact of the video..</p>
<p>There are four principle distance techniques:</p>
<ul>
<li><b>The wide shoot:</b> establishes the subject and location of the action, it is usually used at the beginning of a video or scene since it establishes the setting.</li>
<li><b>The medium shot:</b> clarifies the subject or action give the viewer more informat ion about the subject and clarifies the theme of video.</li>
<li><b>The medium close up:</b> provides even more detail for the viewer type of scene, the background has receded and the person or group of people being video taped fill out the entire scene.</li>
<li><b>The close up:</b> zeros in on a single object, someone face detail of experience and feeling maybe conveyed in a close up.</li>
</ul>
</div>
<!-- **** right content container **** -->
<div id="right">
<div class="rightitem">
<div class="rightitle">
<h1>Menu</h1>
</div>
<div class="rightcontent">
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="register.php">Register</a></li>
<li><a href="sound.html">Sound</a></li>
<li><a href="editing.html">Editing</a></li>
<li><a href="lighting.html">Lighting</a></li>
</ul>
</div>
</div>
<div id="rightitem">
<div class="rightitle">
<h1>User Login</h1>
</div>
<div class="rightcontent">
<form action="index.php" method="post">
<table width="180" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="60" height="25">Email</td>
<td width="120"><input type="text" name="email" size="15" maxlength="40" /></td>
</tr>
<tr>
<td height="30">Password</td>
<td> <input type="password" name="password" size="15" maxlength="20" /></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Login" /></td>
<td><input type="hidden" name="submitted" value="TRUE" /></td>
</tr>
</table>
</form>
<p>
<?php
if (!empty($errors)) {
echo '<h1 id="mainhead">Error!</h1>
<p class="error">The following error(s) occurred:<br />';
foreach ($errors as $msg) {
echo " - $msg<br />\n";
}
echo '</p><p>Please try again.</p>';
}
?>
</p>
</div>
</div>
</div>
</div>
<!-- **** footer area **** -->
<div id="footer">
</div>
</div>
</body>
</html>


thanks in advance.

neuro
05-25-2007, 05:31 PM
Nvm... solve it. just realize i put the coding for the log in between <head> and <body>. The right one suppose to be before other code.

Thx anyway :)