Hi there I am hoping that someone could help me with this... I was trying to redirect a page using header(); after successful login. I am going to share my codes:


<title>HCPSMSHS: Grade Viewing System</title>

<link rel="stylesheet" href="css.css" type="text/css" charset="UTF-8" media="all">

<center><div id="header"></div></center>
<div id="links">
<ul class="navheader">
<li><a href="home.html"><img src="home.png"></a></li>
<li><a href="event.html"><img src="calendar.png"></a></li>
<li><a href="grade.html"><img src="user.png"></a></li>
<center><div id="content"></div></center>
<center><div id="subcontent">
<div align="justify">
<font face="Courier New" size="1px" color="#aeaeae">
February 6, 2011, 8:21pm</font><br/>
<font face="georgia" size="5px">
Log in</font>
<form name="myform" action="script1.php" method="post">

<table width="500" border="0" cellpadding="1" cellspacing="1">
	<td width="30%" height="40">
	<font size="5px">User Name</font>
		<td><input type="text" name="username"  size="40px" maxlength=25> <br/>
	<td width="30%" height="40">
	<font size="5px">Password</font>
		<td><input type="password" name="password"  size="40px" maxlength=25> <br/>
	<td colspan="2"><center><input type="submit" name="submit" width="5"> <input type="button" value="Cancel"></center>




<!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">
<link rel="stylesheet" href="css.css" type="text/css" charset="UTF-8" media="all">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>


$conn=odbc_connect('MS Access Driver','','')
or die("connect error: ".odbc_error());


$sql="SELECT * FROM tbllogin WHERE username='$username' and password='$password'";

or die ("result error ".odbc_error().'-'.odbc_errormsg());

// if no result: no rows read
if (!odbc_fetch_row($result))
echo "<script>alert(\"ERROR! Try again.\");</script>";

// else: all is okay
else {

echo "<script>alert(\"Welcome $username!!\")</script>";
header("Location: grade.php");


When I try to load these I receive this error:

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\web\script1.php:10) in C:\xampp\htdocs\web\script1.php on line 36

line 36 points to the header() code. >.<
can anyone help me with these?

6 Years
Discussion Span
Last Post by kitschkath

the problem as i see it is that header syntaxing is correct but
* Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. *


So it means that I am going to put the header on the first part of the code? Where exactly? Sorry I am a noob in PHP, I just started yesterday >.<


ok so basically when your code executes in that line you shouldnt have a echo or print before header

obviously put line no: 35 below because thats one echo thats coming before the header


^ Okay so I put the header before the echo and I still got the same error. Is there any code for redirecting a page other than header?


Thank you I already solved the problem using an alternative script!

here it is:

print "<script>";
print " self.location='mynewpage.html';";
print "</script>";
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.