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

James_Duh
  • 1,321
  • 11
  • 31
  • `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. – StackSlave Mar 20 '18 at 01: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. – StackSlave Mar 20 '18 at 01:45
  • You do realise you can submit your form without any information inputted, make sure you use some validation like `required` – TheWelshManc Mar 20 '18 at 01: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' – TheWelshManc Mar 20 '18 at 02: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 "

    You are a bot! Go away!

    "; } else if ($captcha_success->success==true) { header('location:https://androidstackoverflow.com/contactform/send-info.php');/* page on the server */ echo "

    You are not not a bot!

    "; }`
    – TheWelshManc Mar 20 '18 at 02:07
  • Make sure you have `https://www.` at the start or format it so it's just `send-info.php` – TheWelshManc Mar 20 '18 at 02:18
  • @TheWelshManc Could we place the verify.php code in the HTML file and if so how and where Need to know how to capture a checkbox click on the reCaptcha ? ? – James_Duh Mar 20 '18 at 02:27
  • I get the same result again, try changing the if statement or deleting it completely so you can run the page without the captcha needed at the moment and see if it runs correctly – TheWelshManc Mar 20 '18 at 02:30
  • @TheWelshManc I did that and if I omit the reCaptcha the send-info.php will do its job It send an email to the server and the server does a forward to me at a gmail account SEE my comment above this one – James_Duh Mar 20 '18 at 02:34

1 Answers1

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

John
  • 3,716
  • 2
  • 19
  • 21
  • 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 – James_Duh Mar 20 '18 at 02:45
  • 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. – John Mar 20 '18 at 03:05
  • 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. – John Mar 20 '18 at 03:09
  • so I found the blank line it was (space) in front of – James_Duh Mar 20 '18 at 03:15
  • Put the @ in front of @file_get_contents() and it should all work assuming no other error exists. – John Mar 20 '18 at 03:17
  • I think I have a name conflict the FOLDER contactform has all the files for one of the files is called and named
  • Contact
  • now the page is telling me it can not be found ? ? ? – James_Duh Mar 20 '18 at 03:35
  • OK, your original problem has been solved and header() is working and is now navigating somewhere else. I can only presume there is another header() in a different file and it is causing a file not found error - see the address bar of the file that it can't find. I can't really help you any further here given the original question has been answered. You probably best adding a new question because you now have a different error. – John Mar 20 '18 at 03:51
  • I removed the @ symbol and here is the root error 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 16 – James_Duh Mar 20 '18 at 03:53
  • /home/sites/5b/1/1535c434df/public_html/contactform/send-info.php on line 24 Notice: Undefined index: message in /home/sites/5b/1/1535c434df/public_html/contactform/send-info.php on line 25 /home/sites/5b/1/1535c434df/public_html/contactform/send-info.php on line 26 /home/sites/5b/1/1535c434df/public_html/contactform/send-info.php on line 56 Warning: Cannot modify header information - headers already sent by (output started at /home/sites/5b/1/1535c434df/public_html/contactform/send-info.php:24) in /home/sites/5b/1/1535c434df/public_html/contactform/send-info.php on line 56 – James_Duh Mar 20 '18 at 04:04
  • at a loss my best guess is no variables are sent to send-info.php and that stops the header code on verify.php I will look at possible solutions thanks a ton I will fix the site so it sends me e-mail PLEASE contact if you have time for direct e-mail conversation – James_Duh Mar 20 '18 at 04:07
  • These are different error caused by turning on the error reporting. You need to create a new question with example code of where it is failing and tell us what you are trying to do. – John Mar 20 '18 at 04:11