Page 1 of 1

Redirect Problem .............

Posted: Sun Aug 12, 2007 2:24 pm
by myharshdesigner
i am getting error in this line :-

Code: Select all

header("Refresh: 10; url=index.php");


The error is :-

Code: Select all

Warning: Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\Web\mail\include\header.php:12) in D:\xampp\htdocs\Web\mail\submit.php on line 62
[s]pl[/s] PLEASE help me and Guide me [s]pl[/s] PLEASE


thanks
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.

Posted: Sun Aug 12, 2007 2:34 pm
by superdezign
You are making output on line 12 of header.php before your header() call. Once output is made, default headers are sent, and are no longer available for modification.

Posted: Sun Aug 12, 2007 3:35 pm
by feyd
The refresh header is not supported by a large number of browsers and servers. You will need to use <meta> tags.

Posted: Sun Aug 12, 2007 8:46 pm
by myharshdesigner
superdezign wrote:You are making output on line 12 of header.php before your header() call. Once output is made, default headers are sent, and are no longer available for modification.

here is the header.php :-

Code: Select all

<?php
session_start();
?>
<!-- saved from url=(0014)about:internet -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Speed Mail</title>
<style type="text/css">td img {display: block;}body {
	background-color: #999999;
}
</style>
</head>
<body topmargin="0">
<center>
<div>
<table border="0" cellpadding="0" cellspacing="0" width="664">
<!-- fwtable fwsrc="header.png" fwbase="header.gif" fwstyle="Dreamweaver" fwdocid = "1048292929" fwnested="0" -->
  <tr>
   <td><img src="../header/spacer.gif" width="51" height="1" border="0" alt="" /></td>
   <td><img src="../header/spacer.gif" width="122" height="1" border="0" alt="" /></td>
   <td><img src="../header/spacer.gif" width="268" height="1" border="0" alt="" /></td>
   <td><img src="../header/spacer.gif" width="29" height="1" border="0" alt="" /></td>
   <td><img src="../header/spacer.gif" width="145" height="1" border="0" alt="" /></td>
   <td><img src="../header/spacer.gif" width="49" height="1" border="0" alt="" /></td>
   <td><img src="../header/spacer.gif" width="1" height="1" border="0" alt="" /></td>
  </tr>

  <tr>
   <td rowspan="3" bgcolor="#FFFFFF"></td>
   <td rowspan="2"><img name="Title" src="include/header/Title.gif" width="122" height="50" border="0" id="Title" alt="" /></td>
   <td colspan="2" rowspan="3" bgcolor="#FFFFFF"></td>
   <td colspan="2" valign="top" bgcolor="#FFFFFF"><p style="margin:0px"></p></td>
   <td><img src="include/header/spacer.gif" width="1" height="26" border="0" alt="" /></td>
  </tr>
  <tr>
   <td rowspan="3"><img name="Stamp" src="include/header/Stamp.gif" width="145" height="72" border="0" id="Stamp" alt="" /></td>
   <td rowspan="4" bgcolor="#FFFFFF"></td>
   <td><img src="include/header/spacer.gif" width="1" height="24" border="0" alt="" /></td>
  </tr>
  <tr>
   <td bgcolor="#FFFFFF"></td>
   <td><img src="include/header/spacer.gif" width="1" height="45" border="0" alt="" /></td>
  </tr>
  <tr>
   <td rowspan="2" colspan="3"><img name="Menu" src="include/header/Menu.gif" width="441" height="17" border="0" id="Menu" alt="" /></td>
   <td rowspan="2" bgcolor="#FFFFFF"></td>
   <td><img src="include/header/spacer.gif" width="1" height="3" border="0" alt="" /></td>
  </tr>
  <tr>
   <td bgcolor="#FFFFFF"></td>
   <td><img src="include/header/spacer.gif" width="1" height="14" border="0" alt="" /></td>
  </tr>
</table>
</div>

Here is the submit.php :-

Code: Select all

<?php
require_once("dbconn\dbconn.php");
require_once("include\header.php");
?>
<style type="text/css">
<!--
.style1 {font-family: Verdana, Arial, Helvetica, sans-serif}
.style3 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px; }
-->
</style>

<script type="text/javascript">
<!--
function delayer()
{
    window.location = "../javascriptredirect.php"
}
//-->
</script>

<link href="css/mail22.css" rel="stylesheet" type="text/css" />
<?php

$_SESSION['userid'] = $_POST['userid'];
$_SESSION['password'] = $_POST['password'];
$_SESSION['repassword'] = $_POST['repassword'];
$_SESSION['name'] = $_POST['name'];
$_SESSION['address'] = $_POST['address'];

$pref = "admin";
$date1 = date("Y-m-d");
$ad = "admin";
global $queary;
?>
<table border="0" cellpadding="0" cellspacing="0" width="664">
<!-- fwtable fwsrc="body.png" fwbase="registration.gif" fwstyle="Dreamweaver" fwdocid = "1797656754" fwnested="0" -->
  <tr>
   <td><img src="registration/spacer.gif" width="23" height="1" border="0" alt="" /></td>
   <td><img src="registration/spacer.gif" width="618" height="1" border="0" alt="" /></td>
   <td><img src="registration/spacer.gif" width="23" height="1" border="0" alt="" /></td>
   <td><img src="registration/spacer.gif" width="1" height="1" border="0" alt="" /></td>
  </tr>

  <tr>
   <td height="300" valign="top" bgcolor="#EBE8E8"><p style="margin:0px"></p></td>
   	<td valign="middle" bgcolor="#EBE8E8">
	<div>
   		<p align="center" style="margin:0px">
		<?php
			// SQL QUERY ///////////////////////////////////////////------------------------
			if(pref != $ad)
			{
				$queary = 'INSERT INTO email_registration (user_id,pass,name,address,date1) VALUES('.$_SESSION['userid'].','.$_SESSION['password'].','.$_SESSION['name'].','.$_SESSION['address'].','.$date1.')';
			}
			elseif(pref == 'admin')
			{
				$queary = 'INSERT INTO email_registration (user_id,pass,name,address,preference,date1) VALUES('.$_SESSION['userid'].','.$_SESSION['password'].','.$_SESSION['name'].','.$_SESSION['address'].','.$ad.','.$date1.')';
				echo $queary;
			}
			echo $queary; 
			
			header("Refresh: 10; url=index.php");
		?> 
   		</p>
	</div>
	</td>
   <td valign="top" bgcolor="#EBE8E8"><p style="margin:0px"></p></td>
   <td><img src="registration/spacer.gif" width="1" height="300" border="0" alt="" /></td>
  </tr>
</table>

<?php
require_once("include\footer.php");
?>

and footer.php :-

Code: Select all

<title>Speed Mail</title>
<style type="text/css">
<!--
.style6 {
	color: #000000;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
}
a:link {
	color: #000000;
	text-decoration: none;
}
a:visited {
	text-decoration: none;
	color: #000000;
}
a:hover {
	text-decoration: underline;
	color: #333333;
}
a:active {
	text-decoration: none;
}
.style7 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
}
-->
</style>
<div>
<table border="0" cellpadding="0" cellspacing="0" width="664">
<!-- fwtable fwsrc="Footer.png" fwbase="Footer.gif" fwstyle="Dreamweaver" fwdocid = "219680605" fwnested="0" -->
  <tr>
   <td><img src="footer/spacer.gif" width="216" height="1" border="0" alt="" /></td>
   <td><img src="footer/spacer.gif" width="448" height="1" border="0" alt="" /></td>
   <td><img src="footer/spacer.gif" width="1" height="1" border="0" alt="" /></td>
  </tr>

  <tr>
   <td valign="top" bgcolor="#FFFFFF"><p style="margin:0px"></p></td>
   <td valign="top" bgcolor="#FFFFFF"><p align="left" class="style7" style="margin:0px"><a href="index.php" target="_self">Index</a> | <a href="contect.php" target="_blank">Contect Us</a> | <a href="about.php" target="_self">About Us</a> </p></td>
   <td><img src="footer/spacer.gif" width="1" height="18" border="0" alt="" /></td>
  </tr>
  <tr>
   <td valign="middle" bgcolor="#FFFFFF"><p align="left" style="margin:0px"><span class="style6"><strong>&nbsp;&nbsp;Powered By</strong> <a href="http://www.techinfocomp.com" target="_blank">Techinfocomp</a></span></p></td>
   <td valign="top" bgcolor="#FFFFFF"><p style="margin:0px"></p></td>
   <td><img src="footer/spacer.gif" width="1" height="36" border="0" alt="" /></td>
  </tr>
</table>
</div>
</center>
</body>
</html>

[s]Pl[/s] PLEASE solve the problem Thanks
& [s]pl[/s] PLEASE tell me that what is the problem Thanks
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.

Posted: Sun Aug 12, 2007 9:12 pm
by s.dot
Why are you including a full html file in the header? (don't think that is the problem here, but surely doesn't help)

Posted: Sun Aug 12, 2007 9:48 pm
by iknownothing
scottayy wrote:Why are you including a full html file in the header? (don't think that is the problem here, but surely doesn't help)
Thats exactly the problem. header.php is full of output, then you call header() in submit.php.

You'll have to move your require_once's and and other output code before your header() call.

It certainly makes it easier when the majority of PHP processes are at the very top of a file, to avoid any later confusion, if you want to then place output in a particular area of the page, just echo the variables where you want them.


PS. Makes everyone elses job (helping you) easier, if you use the correct tags (eg. PHP and Syntax (HTML)) instead of just the Code tag.

Posted: Sun Aug 12, 2007 10:39 pm
by myharshdesigner
Thanks for your Help Thanks a LOT

You'll have to move your require_once's and and other output code before your header() call

I have just started PHP so can't find out more Pl Show me how to do that.
i am very thankfull to u show me.


iknownothing wrote:
scottayy wrote:Why are you including a full html file in the header? (don't think that is the problem here, but surely doesn't help)
Thats exactly the problem. header.php is full of output, then you call header() in submit.php.

You'll have to move your require_once's and and other output code before your header() call.

It certainly makes it easier when the majority of PHP processes are at the very top of a file, to avoid any later confusion, if you want to then place output in a particular area of the page, just echo the variables where you want them.


PS. Makes everyone elses job (helping you) easier, if you use the correct tags (eg. PHP and Syntax (HTML)) instead of just the Code tag.

Posted: Sun Aug 12, 2007 10:40 pm
by myharshdesigner
scottayy wrote:Why are you including a full html file in the header? (don't think that is the problem here, but surely doesn't help)
thank your to also dear.

Posted: Sun Aug 12, 2007 11:08 pm
by RobertGonzalez
myharshdesigner wrote:[s]Pl[/s] PLEASE solve the problem Thanks
& [s]pl[/s] PLEASE tell me that what is the problem Thanks
Steps to figuring out why you are getting this error message:
1. Scroll to the top of this page.
2. Click the "search" link.
3. In the search term field, enter the term "headers already sent".
4. Read the answers to this same question that has been asked about 10 times in the last two weeks.
5. Move any code calls that require headers not be sent to a place before any output is sent.

In a nutshell, you cannot send response headers from the server (this happens just before output is sent) then expect to be able to send more headers. Think of response headers as a frisbee or a baseball. Once you throw it, you cannot throw it again because it is no longer in your hand. Once you start sending output to the browser, the response headers are gone so you cannot send them anymore.

Posted: Mon Aug 13, 2007 4:31 am
by myharshdesigner
i have solved this problem through

this javascript:-

Code: Select all

<script type="text/javascript">
						function redirect()
						{
							window.location.href = "index.php";
						}
						window.onload = setTimeout("redirect()", 10000);
						</script>
but With PHP remain the problem as it is.

any one can solve & tell me the Solved Code in php?

Posted: Mon Aug 13, 2007 6:02 am
by superdezign
myharshdesigner wrote:any one can solve & tell me the Solved Code in php?
Everah already did.

If you output before handling your headers, it's bad design. Headers in file are exactly that: Headers. It is data that exists before the data in the file. Once you start outputting data into the file, the headers can no longer be reached. That's why header calls should be dealt with BEFORE ANY output, and why the error message is 'headers already sent.' Once they are sent, they cannot be modified.

Using JavaScript is a bad idea because not everyone has JavaScript enabled.

Posted: Mon Aug 13, 2007 9:46 am
by CoderGoblin
Unless you need javascript to enhance user experience don't rely on it being there. I think the last time I looked at stats about 3% of people have it switched off.

My normal style of coding to give you an example of coding php logic first....

Code: Select all

<?php
  // All logic processing done here
  if (!empty($_POST['form_sent']) { // example quick form
      // do whatever
      header('Location: http://www.mypage.com/redirected.php'); // always try to use full url
      exit;  //always exit after redirect
  }
  // As part of this block you can set up variables to output in the html block.
  $body='Well how about this';
?>
<html>
  <head>
    <title>Hello</title>
  </head>
  <body>
    <p><?php echo $body; ?></p>
   <p>Well this was simple wasn't it</p>
  </body>
</html>

Posted: Mon Aug 13, 2007 9:10 pm
by myharshdesigner
Thanks & i will Chack it out.


CoderGoblin wrote:Unless you need javascript to enhance user experience don't rely on it being there. I think the last time I looked at stats about 3% of people have it switched off.

My normal style of coding to give you an example of coding php logic first....

Code: Select all

<?php
  // All logic processing done here
  if (!empty($_POST['form_sent']) { // example quick form
      // do whatever
      header('Location: http://www.mypage.com/redirected.php'); // always try to use full url
      exit;  //always exit after redirect
  }
  // As part of this block you can set up variables to output in the html block.
  $body='Well how about this';
?>
<html>
  <head>
    <title>Hello</title>
  </head>
  <body>
    <p><?php echo $body; ?></p>
   <p>Well this was simple wasn't it</p>
  </body>
</html>