PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 4th, 2012, 08:25 PM
scriptmagic scriptmagic is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 2 scriptmagic User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 28 m 54 sec
Reputation Power: 0
Warning: Cannot modify header information - headers already sent

I have a form in the index page of my site with the following php action attributed to it:

Code:
<form action="php.php" method="POST" enctype="multipart/form-data" onsubmit="return regchk()" name="myform">


When users submit their information, the field data gets POSTed to a url. After that, I need them to get redirected to a thank you page.

There is something clashing with the line
PHP Code:
 header('Location: thankyou.html'); 


Which is causing it to produce the following error:

Code:
Warning: Cannot modify header information - headers already sent by (output started at /home/jsanders/public_html/xxx.com/php.php:3) in /home/jsanders/public_html/xxx.com/php.php on line 48


Any suggestions? Here is the code in the php.php file.

PHP Code:
<html>
    <
body>
        <?
php
        
        
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            
error_reporting(E_ALL E_NOTICE);
            
$fname urlencode($_POST['fname']);
            
$lname urlencode($_POST['lname']);
            
$email urlencode($_POST['em']);
            
$st urlencode($_POST['st']);
            
$zip urlencode($_POST['zip']);
            
$ip urlencode($_POST['ip']);
            
$ts urlencode($_POST['ts']);
            
$phone urlencode($_POST['pn']);
            
$agree urlencode($_POST['custom1']);
            
$agree2 urlencode($_POST['custom2']);
            
$city urlencode($_POST['ct']);


              echo 
$fname "<br />";
              echo 
$lname "<br />";
              echo 
$email "<br />";
              echo 
$st "<br />";
              echo 
$zip "<br />";
              echo 
$ip "<br />";
              echo 
$ts "<br />";
              echo 
$phone "<br />"; */


            
$url "http://dailygobblet.com/13/cr-rtp-richalissa?fname=$fname&lname=$lname&em=$email&st=$st&zip=$zip&ip=$ip&ts=$ts&pn=$phone";

            
$ch curl_init();
            
curl_setopt($chCURLOPT_URL$url);
            
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
            
curl_setopt($chCURLOPT_CONNECTTIMEOUT1); // Socket Timeout value in mille second.
            
curl_setopt($chCURLOPT_FAILONERROR1);
            
curl_setopt($chCURLOPT_TIMEOUT60); // Total time to fetch the response in seconds after socket is opened.
            
$response curl_exec($ch);
            
$urlresponsecode curl_getinfo($ch);
            
curl_close($ch);
            if (
$urlresponsecode['http_code'] == 200) {
              
                
header('Location: thankyou.html');
            } else {
                print(
"There is an error present. Please copy and email this error to support@creditrepair2013.com.<br />");
            }
        }
        
?>
    </body>
</html> 

Reply With Quote
  #2  
Old December 4th, 2012, 08:33 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,690 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 3 h 43 m 47 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Ah, haven't seen this question in a while.

PHP FAQ
Quote:
#16 Why am I getting the error "Headers already sent"?

If you try to send a header using the header() function (like for a redirect) and headers have already been sent previously, the call will fail. ANY kind of output will send the plaintext headers, preventing a Location header from being sent. The error message contains the file and line that sent the output. Go there, find the problem, and remove it. Whitespace and Byte Order Markers (BOM) outside of the PHP tags count as output. It's best to remove the closing PHP tag from all your files anyway.

Your output is the HTML before the code and the echos you do inside it. Restructure your file so that the redirect can happen before any output is sent.

Reply With Quote
  #3  
Old December 4th, 2012, 08:58 PM
scriptmagic scriptmagic is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 2 scriptmagic User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 28 m 54 sec
Reputation Power: 0
Quote:
Originally Posted by requinix
Ah, haven't seen this question in a while.


Your output is the HTML before the code and the echos you do inside it. Restructure your file so that the redirect can happen before any output is sent.


Thanks for the response. It seems like the POST to the one url containing the database is conflicting with the header redirect to the url where I want the traffic to go...

Perhaps one solution is to set something up on their database that will direct all incoming traffic from the site back again and to the thank you page.

But is there another solution that I can do on my end that will direct the traffic through the url that the POST is going to and then onto the thank you page?

Reply With Quote
  #4  
Old December 4th, 2012, 10:46 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,690 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 3 h 43 m 47 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
The best solution is to move code around so that the header() can happen and does so before there's any kind of output.
Rather than output the form fields (do you still want to do that?) immediately, save it for later in case there's a problem - which is the only circumstance where the user would actually see them (because they'd be redirected immediately without seeing the contents of the page). Do the same if there's an error.

Basically,
PHP Code:
<?php

// process the form

// if there were any problems {
    // save information so you can customize the form to display the error/form fields
// } else {
    // redirect and exit
// }

?>
<!-- show the page -->

Be sure to exit; immediately after trying the redirect with header(). PHP will not stop the script for you and there's no point in outputting anything the user won't see. In fact it might even be harmful.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Warning: Cannot modify header information - headers already sent

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap