0

I am experinmenting with Facebook Messenger Bot.

When the below webhook (index.php) is placed under /var/www/wei48221.com/html/, it could capture the data sent from Facebook and save them in "fb.txt" under /var/www/wei48221.com/html/callback/. However, if the webhook (index.php) is placed under /var/www/wei48221.com/html/callback/ it cannot capture the data sent from Facebook even though the new callback URL https://wei48221.com/callback has passed Facebook's verification.

Below is the content of "index.php".

<?php
file_put_contents("/var/www/wei48221.com/html/callback/fb.txt", file_get_contents("php://input"));

Could anyone shed some light on this issue?

Barmar
  • 741,623
  • 53
  • 500
  • 612
WHHuang
  • 23
  • 7
  • Are there any errors in the PHP log? – Barmar Jul 09 '19 at 04:52
  • The location of the script shouldn't make any difference in whether it can read from `php://input` – Barmar Jul 09 '19 at 04:57
  • Thanks for the tip. Will check the PHP log.. – WHHuang Jul 09 '19 at 05:01
  • Found out where the problem is. Both "URL/callback" and "URL/callback/" will pass Facebook's URL verification. However, only the "URL/callback/" will give the expected result. Thank you for letting me know the location of the script shouldn't make any difference in whether it can read from php://input. – WHHuang Jul 09 '19 at 05:28
  • `URL/callback` results in a redirect to `URL/callback/`. But redirects are processed with GET not POST, so they don't post the data through the redirect. – Barmar Jul 09 '19 at 06:28
  • You should give FB the full URL, `URL/callback/index.php` so no redirects are involved. – Barmar Jul 09 '19 at 06:29
  • Ahh. I didn't know URL/callback results in a redirect to URL/callback/.. Thank you so much :-) – WHHuang Jul 09 '19 at 06:36

0 Answers0