0

Yes this question has been asked before but we are including one step that we have not seen in any other answers. This question involves three pages one HTML and two PHP pages. The HTML page has a reCaptcha that is verified when the user clicks the SEND button that navigates to the verify.php page. It has your standard true or false if statements code below

if ($captcha_success->success==false) {
    echo "<p>You are a bot! Go away!</p>";
} else if ($captcha_success->success==true) {
    header('location:https://androidstackoverflow.com/contactform/send-
 info.php');/* page on the server */
    echo "<p>You are not not a bot!</p>";*/
}

This is where the fail or lack of results starts. if true we want to navigate to send-info.php and send the info to the server. We can not see the code in send-info.php load or execute. We know the code works by adding it inside the true if statement So the question is this a fail because the send-info.php is not loading or no variable info is being received from the HTML page with the data? Web Page can be seen here Web Page We are not web developers and this is the only PHP code we have ever written. It has taken 5 days to get this far with the contact form so we are desperate ! For clarity contactform is a folder and all three forms are in this folder we have tried with out contactform in the path

9
  • header('location: is happening before your echo. But even if it happened first that echo String would not be available to the page you're navigating to. Commented Mar 20, 2018 at 1:40
  • It must have to do with if($captcha_success->success == true), because the result I get at that URL, is Here we are. Please include relevant captcha code. Commented Mar 20, 2018 at 1:45
  • You do realise you can submit your form without any information inputted, make sure you use some validation like required Commented Mar 20, 2018 at 1:52
  • I noticed your code in the question has the header on two lines, that will throw an error. Have you got it all on one line on your site? When I test it myself it goes to a page and says 'Here we are' Commented Mar 20, 2018 at 2:00
  • I just tried it again and it didn't go to the send-info page, did you correct what I mentioned so your code is like this: if ($captcha_success->success==false) { echo "<p>You are a bot! Go away!</p>"; } else if ($captcha_success->success==true) { header('location:https://androidstackoverflow.com/contactform/send-info.php');/* page on the server */ echo "<p>You are not not a bot!</p>"; } Commented Mar 20, 2018 at 2:07

1 Answer 1

1

When you view the source code it contains

1 
2 <p>You are not not a bot!</p>

when you should only see

1 <p>You are not not a bot!</p>

Which implies there has been some white space outputted somewhere in the PHP file prior to the header command and I suspect you have warning/error reporting turned off otherwise you would have gotten the following warning appearing: "Cannot modify header information - headers already sent by (output started at..." The solution is to make sure there are no empty lines before the

<?php 

at the top of the php file.

Also try turning on error reporting... and it'll tell you where the first output occurred

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

Remember to remove the error reporting code once you've fixed it.

This post goes into extensive details of the cause and solutions How to fix "Headers already sent" error in PHP

Sign up to request clarification or add additional context in comments.

11 Comments

here are the errors NOT sure I can decipher Notice: file_get_contents(): Content-type not specified assuming application/x-www-form-urlencoded in /home/sites/5b/1/1535c434df/public_html/contactform/verify.php on line 23 You are not not a bot! Warning: Cannot modify header information - headers already sent by (output started at /home/sites/5b/1/1535c434df/public_html/contactform/verify.php:23) in /home/sites/5b/1/1535c434df/public_html/contactform/verify.php on line 32 So DO I want to remove ln 23 and not sure about 32
OK, you need to fix that Notice problem on line 23 which is a different error to what my answer solves and once you've fixed that problem you'll get different warning and some where in your php file will be a rogue character like a blank line causing header() to fail. Deleting the blank line / character(s) will fix the problem.
put an @ symbol in front of @file_get_contents() and it'll suppress the warning. Once you get the header() working you need to go back and remove the @ and solve it properly.
so I found the blank line it was (space) in front of <?php Not sure what to do with ln 23 will try to rewrite it the word false looks so wrong
Put the @ in front of @file_get_contents() and it should all work assuming no other error exists.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.