/    Sign up×
Community /Pin to ProfileBookmark

Warning: Cannot modify header information

Hello,

I’ve working on a site that isn’t going to be hosted on the usual servers we use. I’m having abit of difficulty with the login script we use to make member areas.

Its giving me the warning on a successful attempt to login:

Warning: Cannot modify header information – headers already sent by (output started at /home/11293/domains/[B]xxxxxx[/B].co.uk/html/admin/index.php:11) in /home/11293/domains/[B]xxxxxx[/B].co.uk/html/admin/index.php on line 40

the whole page code is this:

[code=php]<?
session_start();
include ‘inc/connect.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″ />
<title>Admin 0.1</title>
<link href=”css/style.css” rel=”stylesheet” type=”text/css” />
<style type=”text/css”>
#loginbox{
width:300px;
margin:150px auto 50px auto;
padding:20px;
text-align:center;
}
#beta{
position: absolute;
top: 20px;
right: 20px;
}
</style>
</head>
<body>
<?
$username = htmlspecialchars($_POST[‘username’]);
$password = htmlspecialchars($_POST[‘password’]);
if($_POST[‘login’] == “true”){
$check = mysql_query(‘SELECT * FROM user_info WHERE username=”‘ . $username . ‘”‘);
if(!$check){ echo “<p>Database Error</p>”;
}
while ($row = mysql_fetch_array($check)) {
$realpassword = $row[‘password’];
$id = $row[‘id’];
$username = $row[‘username’];
}
if($password == $realpassword) {
if(!$realpassword == “”){
header(‘Location: dashboard.php’);
$_SESSION[‘login’]=”ok”;
}
} else {
echo ‘oops’;
}
}
?>
<div id=”loginbox”>
<form action=”index.php” method=”post” enctype=”application/x-www-form-urlencoded”>
Username:<br />
<input name=”username” type=”text” id=”username” tabindex=”1″/><br />
Password:<br />
<input name=”password” type=”password” tabindex=”2″/>
<br />
<input name=”login” type=”hidden” value=”true” />
<input type=”submit” name=”button” id=”button” value=”Submit” tabindex=”3″ />
</form>
</div>
</body>
</html>[/code]

I can’t understand whats wrong. I’ve used this code plenty of times before on the server at work fine. i’ve made a couple of changes but just the sql query.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@EckishAug 06.2008 — If that is all you changed, it shouldn't of worked before either.

header('Location: dashboard.php'); is the line that is breaking. And it should. Headers have to come before any html is layed down. Likely, prior to your sql changes, you weren't reaching the condition to make that header call. And after your change, you are reaching it now causing the error.
Copy linkTweet thisAlerts:
@MrCoderAug 07.2008 — [code=php]
<?
ob_start();
session_start();
include 'inc/connect.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" />
<title>Admin 0.1</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
#loginbox{
width:300px;
margin:150px auto 50px auto;
padding:20px;
text-align:center;
}
#beta{
position: absolute;
top: 20px;
right: 20px;
}
</style>
</head>
<body>
<?
$username = htmlspecialchars($_POST['username']);
$password = htmlspecialchars($_POST['password']);
if($_POST['login'] == "true"){
$check = mysql_query('SELECT * FROM user_info WHERE username="' . $username . '"');
if(!$check){ echo "<p>Database Error</p>";
}
while ($row = mysql_fetch_array($check)) {
$realpassword = $row['password'];
$id = $row['id'];
$username = $row['username'];
}
if($password == $realpassword) {
if(!$realpassword == ""){
$_SESSION['login']="ok";
ob_clean();
header('Location: dashboard.php');
die();
}
} else {
echo 'oops';
}
}
?>
<div id="loginbox">
<form action="index.php" method="post" enctype="application/x-www-form-urlencoded">
Username:<br />
<input name="username" type="text" id="username" tabindex="1"/><br />
Password:<br />
<input name="password" type="password" tabindex="2"/>
<br />
<input name="login" type="hidden" value="true" />
<input type="submit" name="button" id="button" value="Submit" tabindex="3" />
</form>
</div>
</body>
</html>
[/code]
×

Success!

Help @copes spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...