Re: Redirecting - here is the code
| From: | Joci | Date: | Thu, 16 Jan 2003 17:50:19 +0000 |
| Subject: | Re: Redirecting - here is the code | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-131904@lists.php.net to get a copy of this message | ||
Hi!
From manual (http://www.php.net/manual/en/function.header.php):
Remember that header() must be called before any actual output is sent,
either by normal HTML tags, blank linek in a file, or from PHP.
You need to start with header()...
Example:
<?php
header('Location: http://www.example.com/');
?>
<html>
or you can use ob_start and ob_end_flush();
Best Regards
----- Original Message -----
From: "Denis L. Menezes" <menezesd@singnet.com.sg>
To: "PHP general list" <php-general@lists.php.net>
Sent: Thursday, January 16, 2003 6:07 PM
Subject: [PHP] Redirecting - here is the code
I tried. But I get an error as follows :
Warning: Cannot add header information - headers already sent by (output
started at /usr/local/www/virtual2/66/175/19/84/html/maintenance.php:11) in
/usr/local/www/virtual2/66/175/19/84/html/maintenance.php on line 30
My code is as follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFCC">
<table width="70%" border="0">
<tr>
<td height="67" colspan="3" bgcolor="#330066">
<div align="center"><font color="#FFFF00" face="Arial,
Helvetica,
sans-serif"><strong><font size="5">Site
maintenance page<?php
//connecting to the database
$link = mysql_connect("localhost","mydomain","somepass");
if ($link){
Print "";
} else {
Print "No connection to the database";
}
if (!mysql_select_db("mydomain_com")){
Print "Couldn't connect database";
} else {
Print ""."<br>\n";
}
$sql="SELECT AdminFirstName,AdminLoginId,AdminPassword FROM Administrators
where
AdminLoginId = '$AdminLoginId' and AdminPassword ='$AdminPassword'";
if ($result=mysql_query($sql)) {
$numofrows=mysql_num_rows($result);
if ($numofrows==0){
header("Location: http://www.php-faq.com/");
Print "<STRONG><font color=\"#FF0000\"size=\"3\">We are
sorry.</STRONG></FONT>";
}
if ($numofrows==1){
Print "<font size=\"3\" color=\#ff0000\">Welcome
".$AdminFirstName."<Font>";
}
if ($numofrows>1){
Print "<STRONG>Something wrong</STRONG>";
}
while($row=mysql_fetch_array($result)){
Print"<Font size=\"3\">$row[AdminFirstName]</font>";
}
}
?></font></strong></font></div></td>
</tr>
</table>
</body>
</html>
Unquote.
Line no. 30 is the one with the line : header("Location:
http://www.php-faq.com/");
Can you please tell me what is wrong?
thanks
denis