Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
LinkBack Thread Tools Display Modes
Old 09-01-2009, 08:25 AM   #1 (permalink)
Member
 
Join Date: 08-13-09
Location: Montreal
Posts: 34
iTrader: 0 / 0%
Latest Blog:
None

splap is liked by many
Unhappy PHP header not working with godaddy

I've made a contact form on a website, and it send the user to a page that should redirect them back to the contact form after three seconds.

This is that code:
PHP Code:
<?php 

function spamcheck($field)
  {
  
//filter_var() sanitizes the e-mail
  //address using FILTER_SANITIZE_EMAIL
  
$field=filter_var($fieldFILTER_SANITIZE_EMAIL);

  
//filter_var() validates the e-mail
  //address using FILTER_VALIDATE_EMAIL
  
if(filter_var($fieldFILTER_VALIDATE_EMAIL))
    {
    return 
TRUE;
    }
  else
    {
    return 
FALSE;
    }
  }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
body {
padding: 0px;
margin: 0px;
font: 11px Arial, Helvetica, sans-serif;
color: rgb(32,32,32);
text-align:center;
}
</style>
</head>
<body>
<?php
if (isset($_REQUEST['email']))
{
    
$mailcheck spamcheck($_REQUEST['email']);
    
    if (
$mailcheck == FALSE
        {
?>
Invalid input.
<?php
        
}
    else 
        {
        
$name $_REQUEST['name'];
        
$email $_REQUEST['email'];
        
$phone $_REQUEST['phone'];
        
$comments $_REQUEST['comments'];

        
        
$to "martin@logobee.com";
        
$subject "Mail from -- contact form from $name";
        if (isset(
$_REQUEST['add_to_mailing_list']))
        {
            
$message "Name: $name \n E-mail: $email \n Phone Number: $phone \n This user wants to be added to the mailing list \n $comments";
        }
        
        else 
        {
            
$message "Name: $name \n E-mail: $email \n Phone Number: $phone \n $comments";
        }
        
mail($to,$subject,$message"From: $email");
?>
E-mail sent successfully to <?php echo $to?>, redirecting in 3 seconds...
<?php
        
}
    
//sleep for 3 seconds
    
sleep(3);
    
//redirect
    
header("Location: http://www.---.ca/contact.htm");
}
?>
But when I've tested it on the server, I get the following error message:

Warning: Cannot modify header information - headers already sent by (output started at /home/content/d/a/v/---r/html/contact.php:24) in /home/content/d/a/v/---/html/contact.php on line 73

The site is hosted on godaddy.com , does anyone know why this is happening?

EDIT: I've removed any information that would identify the website, because it's not mine and I can't give away my client's information

Last edited by splap; 09-01-2009 at 08:28 AM.. Reason: I can't give away my client's information
splap is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-01-2009, 09:49 AM   #2 (permalink)
Junior Member
 
Join Date: 05-26-07
Posts: 3
iTrader: 0 / 0%
Latest Blog:
None

prasanthmj is liked by many
This is because the headers should be sent before any other output like echo "something"
You can use ob_start() and ob_end_flush() functions.
prasanthmj is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-01-2009, 10:23 AM   #3 (permalink)
Contributing Member
 
Join Date: 08-30-09
Posts: 65
iTrader: 0 / 0%
warnesey333 is liked by somebodywarnesey333 is liked by somebodywarnesey333 is liked by somebody
Header functions need to be done before any output occurs.
"invalid input" is output
the echo lines are output.
warnesey333 is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-01-2009, 12:23 PM   #4 (permalink)
Member
 
Join Date: 08-13-09
Location: Montreal
Posts: 34
iTrader: 0 / 0%
Latest Blog:
None

splap is liked by many
I know what output is, but then how would I get it to show the output and then redirect after 3 seconds?
splap is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-01-2009, 01:12 PM   #5 (permalink)
Contributing Member
 
Join Date: 08-30-09
Posts: 65
iTrader: 0 / 0%
warnesey333 is liked by somebodywarnesey333 is liked by somebodywarnesey333 is liked by somebody
Javascript redirect?
warnesey333 is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-15-2009, 12:34 AM   #6 (permalink)
Junior Member
 
Join Date: 09-15-09
Posts: 1
iTrader: 0 / 0%
Latest Blog:
None

Help is liked by many
cannot modify header problem

I think the problem is not with the Godaddy server. In your code, there is a lot of space between the php starting tag and 'function'. plz remove the space. i think this will help
Help is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-22-2009, 11:06 PM   #7 (permalink)
Junior Member
 
Join Date: 09-21-09
Posts: 10
iTrader: 0 / 0%
Latest Blog:
None

dweebsonduty is liked by many
prasanthmj is right, you need to do 2 things:

1. Put it in the head
2. Make sure nothing else is echoed before that

Tip: echo "<meta http-equiv=\"REFRESH\" content=\"3;url=http://www.the-domain-you-want-to-redirect-to.com\">" instead of using header, it works every time for me on godaddy.

Tip #2: Chrome does not support html redirects, keep that in mind too.
dweebsonduty is offline  
Add Post to del.icio.us
Reply With Quote
Old 10-07-2009, 02:46 PM   #8 (permalink)
Junior Member
 
mafiaclassic's Avatar
 
Join Date: 07-17-09
Posts: 9
iTrader: 0 / 0%
Latest Blog:
None

mafiaclassic is liked by many
put up the top inside the <?php include("html.php");
mafiaclassic is offline  
Add Post to del.icio.us
Reply With Quote
Old 10-08-2009, 07:15 PM   #9 (permalink)
Moderator
 
Join Date: 02-10-07
Location: Central Kentucky
Posts: 1,291
iTrader: 2 / 100%
Latest Blog:
None

ScriptMan is a web professional of the highest orderScriptMan is a web professional of the highest orderScriptMan is a web professional of the highest orderScriptMan is a web professional of the highest orderScriptMan is a web professional of the highest orderScriptMan is a web professional of the highest orderScriptMan is a web professional of the highest orderScriptMan is a web professional of the highest orderScriptMan is a web professional of the highest orderScriptMan is a web professional of the highest orderScriptMan is a web professional of the highest order
The meta refresh as posted above should work fine even on a godaddy server.
__________________
These forums are as good as the posts that you contribute to them.
~~
ScriptMan
Webmaster Help Articles
Domains & Sites For Sale by Owner
ScriptMan is online now  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply

Tags
contact, error, godaddy, php


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
GoDaddy, DNN and SEO AnotherDomainStore Web Hosting Forum 2 06-19-2008 06:43 AM
Alternating Flash Header on Refresh Script not working in Firefox basslion Coding Forum 5 04-15-2008 04:59 AM
Godaddy being evil John Scott Domain Name Forum 28 07-05-2007 11:47 PM
Two HTML similar codes , one working well and another not working why? Banjika Web Design Lobby 1 06-11-2005 08:14 AM


Sponsor Links
Get exposure! Contextual Links V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 02:32 PM.
© Copyright 2008 V7 Inc
Powered by vBulletin
Copyright © 2000-2009 Jelsoft Enterprises Limited.


Search Engine Optimization by vBSEO 3.3.0 ©2009, Crawlability, Inc.