Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Trying to redirect to a new page, and it is failing.
Old 06-30-2010, 01:20 PM Trying to redirect to a new page, and it is failing.
leebert45's Avatar
Novice Talker

Posts: 14
Name: Lee Wentzel
Location: Michigan, USA
Trades: 0
I scoured this site as well as W3Cschool.com and am doing what I believe should work but it doesn't. Any suggestions would be appreciated. The error is pointing to the head line.

Code:
<?php
$contact = $_POST['contPref'];
$address = $_POST['eMail'];
$subject = 'EMail from the website';
$fname = $_POST['fName'];
$lname = $_POST['lName'];
$street1 = $_POST['street1'];
$street2 = $_POST['street2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$email = $_POST['emailadd'];
$comments = $_POST['comments'];
 
$mailsend = mail($address, $subject, "Name:    $fname $lname
Contact: $contact
Address: $street1
         $street2
         $city , $state $zip
 
Phone:   $phone
Email:   $email
Comments: $comments");
 
echo $mailsend;
 
header("Location:" . 'thankyou.htm');
?>
The error message I am getting is:
Quote:
Warning:
Quote:
Cannot modify header information - headers already sent by (output started at /home/content/89/6324089/html/mailme.php:26) in /home/content/89/6324089/html/mailme.php on line 28
__________________
It's never "just a game" when you're winning.
~ George Carlin ~

Last edited by leebert45; 06-30-2010 at 01:25 PM.. Reason: Adding error message
leebert45 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-30-2010, 01:28 PM Re: Trying to redirect to a new page, and it is failing.
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
headers have to be sent before any output is.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-30-2010, 01:32 PM Re: Trying to redirect to a new page, and it is failing.
leebert45's Avatar
Novice Talker

Posts: 14
Name: Lee Wentzel
Location: Michigan, USA
Trades: 0
Yup, sort of figured that out. I deleted the "echo" line just above the header and it worked flawlessly. Thanks.
__________________
It's never "just a game" when you're winning.
~ George Carlin ~
leebert45 is offline
Reply With Quote
View Public Profile
 
Old 09-06-2010, 11:59 PM Re: Trying to redirect to a new page, and it is failing.
Experienced Talker

Posts: 34
Trades: 0
i think you should re frame the coding of the article or there are some errors which can be modified with the help of the experts like the site developers
__________________

Please login or register to view this content. Registration is FREE
asbharmal is offline
Reply With Quote
View Public Profile
 
Old 09-08-2010, 09:58 AM Re: Trying to redirect to a new page, and it is failing.
Banned

Posts: 408
Name: mushget
Trades: 0
The fix is, obviously, to remove that whitespace from the file. Read the error message carefully. It says "output started at ..." followed by a file name and a line number. That is the file (and line) that you need to edit. Ignore the second file name - that is only a file that included the file that has the whitespace. The first file is the one you have to edit, not the second one.
mushget is offline
Reply With Quote
View Public Profile Visit mushget's homepage!
 
Old 09-08-2010, 01:19 PM Re: Trying to redirect to a new page, and it is failing.
orionoreo's Avatar
Ultra Talker

Posts: 335
Name: Jerry
Trades: 0
Quote:
Originally Posted by mushget View Post
The fix is, obviously, to remove that whitespace from the file. Read the error message carefully. It says "output started at ..." followed by a file name and a line number. That is the file (and line) that you need to edit. Ignore the second file name - that is only a file that included the file that has the whitespace. The first file is the one you have to edit, not the second one.
sorry my friend but you are incorrect... you should check the previous postings prior as well... the problem has been solved...

header outputs cannot be made after other outputs has been made... the echo prior to the header is affecting it that's why..
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
orionoreo is offline
Reply With Quote
View Public Profile
 
Old 09-11-2010, 02:35 AM Re: Trying to redirect to a new page, and it is failing.
Experienced Talker

Posts: 40
Name: Fernades jacob
Trades: 0
Add the following line on the first line of the page that you are redirecting ob_start()

ie

ob_start()

This should be the first line of the script, that is after

<?php
ob_start();
$contact = $_POST['contPref'];
$address = $_POST['eMail'];
$subject = 'EMail from the website';
$fname = $_POST['fName'];
$lname = $_POST['lName'];
$street1 = $_POST['street1'];
$street2 = $_POST['street2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$email = $_POST['emailadd'];
$comments = $_POST['comments'];

$mailsend = mail($address, $subject, "Name: $fname $lname
Contact: $contact
Address: $street1
$street2
$city , $state $zip

Phone: $phone
Email: $email
Comments: $comments");

echo $mailsend;

header("Location:" . 'thankyou.htm');
?>
fernades is offline
Reply With Quote
View Public Profile
 
Old 09-11-2010, 05:36 PM Re: Trying to redirect to a new page, and it is failing.
mad_willsy's Avatar
Super Spam Talker

Latest Blog Post:
R&R Catering Hire Testimonial
Posts: 805
Name: Will Craig
Location: Cheltenham, Gloucestershire, UK
Trades: 0
fernades, It's not a good idea to use an output buffer as a quick fix, why echo anything if you are just redirecting the user to another page?

All you are doing is adding extra load onto the server. Besides you forgot to flush the buffers.
__________________
Wont :P

Please login or register to view this content. Registration is FREE
mad_willsy is offline
Reply With Quote
View Public Profile Visit mad_willsy's homepage!
 
Old 09-12-2010, 01:23 PM Re: Trying to redirect to a new page, and it is failing.
Marik's Avatar
Skilled Talker

Posts: 99
Trades: 0
I use redirections in my code so much that I find the headers already sent error too obtrusive. So I just use javascript:

PHP Code:
function redirect($page) {
    echo 
"<script type='text/javascript'>window.location = '$page';</script>";
    die();

By no means the best solution but at least it can be used anywhere in the script.
__________________

Please login or register to view this content. Registration is FREE
Marik is offline
Reply With Quote
View Public Profile
 
Old 09-12-2010, 01:49 PM Re: Trying to redirect to a new page, and it is failing.
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Quote:
Originally Posted by Marik View Post
I use redirections in my code so much that I find the headers already sent error too obtrusive. So I just use javascript
The problem with javascript is users can disable/not support it (Think screen readers or mobile devices), so that puts you back into square one.

I'm also not a big fan of ob_start(), mostly because the page load times drop dramatically because the page will only be sent once it's finished processing instead as it's outputted. Here is my solution:

PHP Code:
// [...]

if(mail($address$subject"[..]")){ // mail() only returns TRUE or FALSE.
        
header('location: thankyou.htm');
        die();
}
die(
'There was an error sending mail'); // Remember to stop your script running after sending the header, some browsers/bots (Such as googlebot) ignore headers. 
Never forgot the die() bit, otherwise you may be attacked by a Spider of Doom.
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE

Last edited by rogem002; 09-12-2010 at 01:58 PM..
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 09-12-2010, 05:38 PM Re: Trying to redirect to a new page, and it is failing.
Novice Talker

Posts: 7
Name: Iman Ghasrfakhri
Trades: 0
In here removing the echo is the best way, I use meta redirect in the cases that I cannot prevent outputs before header-redirect, it is just like that:
HTML Code:
<meta http-equiv="refresh" content="0; URL='URL-To-An-Othe-Page'" />
You can also change the '0' value to a number to redirect after few seconds (it is time to wait before transfer the user to new page)
__________________

Please login or register to view this content. Registration is FREE
, the first Persian freelancing website.
Quote:
Who can, do; who can't, teach!
Perfect Support, reasonable prices just in
Please login or register to view this content. Registration is FREE
. Shared, Dedicated, Cloud Hosting.
imangh is offline
Reply With Quote
View Public Profile
 
Old 09-19-2010, 12:14 PM Re: Trying to redirect to a new page, and it is failing.
mad_willsy's Avatar
Super Spam Talker

Latest Blog Post:
R&R Catering Hire Testimonial
Posts: 805
Name: Will Craig
Location: Cheltenham, Gloucestershire, UK
Trades: 0
You should never rely on client side browsers behaving as expected. I am intrigued about this spider issue, but fail to see how the die statement above prevents this.

Surely the solution is to use SESSION cookies to detect a logged in user not browser cookies? I only use die statements for errors which would only occur if the user was using the website in an unexpected way, i.e. a hacker.

Aren't PHP redirects handled by the server? Why would you kill the page because the email was successfully sent?
__________________
Wont :P

Please login or register to view this content. Registration is FREE

Last edited by mad_willsy; 09-19-2010 at 12:15 PM..
mad_willsy is offline
Reply With Quote
View Public Profile Visit mad_willsy's homepage!
 
Reply     « Reply to Trying to redirect to a new page, and it is failing.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.53461 seconds with 12 queries