Jump to content
xisto Community
epox

Php Redirectioning Trouble

Recommended Posts

hello!, i'm practicing with php sending mails, manipulating databases, and everything is going right, but when i try to redirect the browser to a page with header("Location: mysite.html"); after it ends the transactions, the navigator shows an error and don't redirects the browser, the error is:

Warning: Cannot modify header information - headers already sent by (output started at /home/epox/public_html/contacto.php:9) in /home/epox/public_html/contacto.php on line 13

if someone knows how to correct the error i will be so gratefuly. :D

Notice from BuffaloHELP:
You MUST use quote tags whenever you are copying.

Edited by BuffaloHELP (see edit history)

Share this post


Link to post
Share on other sites

It be much easier for us to help you in this problem if you actually showed us the coding.

Share this post


Link to post
Share on other sites

That error normally appears if you try to set a header after it has already been sent. Headers must be set before the script outputs anything to the browser or any action is taken like that. If you need to force another page, try using some simple javascript.

Share this post


Link to post
Share on other sites

Moe php code before html tags <head> </head> starts. I guest this is can help but if not the code is very helpfull :D--------------------Practice is when evrything is work but no one know why.Theory is when work nothing but evry one know why.Programmers join Practice with Theory - nothing work and no one know why :D

Share this post


Link to post
Share on other sites

helloo!, here goes the code:

 

this is the php code:

<?php	$dbh=mysql_connect ("localhost", "epox", "******") or die ('I cannot connect to the database because: ' . mysql_error());	mysql_select_db ("epox_tribusuburbanas");	$nombre=$_GET['nombre'];	$mail=$_GET['mail'];   	$movil=$_GET['movil'];	$fijo=$_GET['fijo'];	mysql_query("insert into agenda values ('$nombre','$mail','$movil','$fijo')",$dbh);	header("agenda.htm");?>

 

and here the htm:

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://forums.xisto.com/no_longer_exists/ http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Agenda</title><style type="text/css">body{	margin-top: 20px;	text-align: center;	background-color: #666;}#container{	background-color: #3399FF;	border: 1px solid #fff;	margin-right: auto;	margin-left: auto;	padding: 0px 10px 10px 0px;	width: 300px;}#header{	background-color:#FF9900;}	#header h3{	margin: 0px;	padding: 10px;	font-size: 20px;	color: #fff;	font-weight: normal;}#form{	padding-left: 10px;	padding-top: 10px;	color: #CCCCCC;	text-align: left;}	</style></head><body>	<div id="container">  <div id="header"><h3>Agenda</h3></div>  <div id="form">  	<form name="agenda" action="agenda.php">    <input type="text" name="nombre"> Nombre<br>    <input type="text" name="mail"> eMail<br>    <input type="text" name="movil"> Movil<br>    <input type="text" name="fijo"> Fijo<br>       <input type="submit" value="enviar">     </form>  </div>	</div></body></html>

well that's all, thank you for any colaboration! :D

 

Notice from snlildude87:
Fixed BBCode
Edited by snlildude87 (see edit history)

Share this post


Link to post
Share on other sites

I do not mysql much but don't you have to close the connection with the database? Try putting mysql_close(); before the header command.

 

Also, I've just noticed, that that's not how you redirect someone with php. It should be:

 

header("location:agenda.htm");

Try these small changes and then see if it works :D

Share this post


Link to post
Share on other sites

helloo!, here goes the code:

 

this is the php code:

<?php	$dbh=mysql_connect ("localhost", "epox", "******") or die ('I cannot connect to the database because: ' . mysql_error());	mysql_select_db ("epox_tribusuburbanas");	$nombre=$_GET['nombre'];	$mail=$_GET['mail'];   	$movil=$_GET['movil'];	$fijo=$_GET['fijo'];	mysql_query("insert into agenda values ('$nombre','$mail','$movil','$fijo')",$dbh);	header("agenda.htm");?>

 

[...]

 

169650[/snapback]


Make sure you have NO whitespace before your <?php tag, as that whitespace will cause PHP to start outputting to the browser, which in turn causes the default headers to be sent...

 

Also, you should specify the full URL to the file to redirect to..

 

This quote is from PHP.net on the subject:

Note:  HTTP/1.1 requires an absolute URI as argument to Location:  including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF']  and dirname() to make an absolute URI from a relative one yourself:

<?phpheader("Location: http://" . $_SERVER['HTTP_HOST']                     . dirname($_SERVER['PHP_SELF'])                     . "/" . $relative_url);?>

I hope that helps!!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.