WebHook and PHP


#1

I tried to implement WebHook and used PHP script to process form data.

  1. Here is an example of PHP script I tested to process data in JSON format

data = json\_decode(_POST[‘data.json’]);
$email=$data->email[0];
$company_name=$data->company_name[0];
$contact_name=$data->contact_name[0];

Unfortunately, this test didn’t work. Any ideas what is wrong with the script above?

  1. This is an example of script to process other parameters

page\_id=_POST[‘page_id’];
page\_url=_POST[‘page_url’];
variant=_POST[‘variant’];

It works fine.


#2

Hi Carl,
Thank you for the reply. I tried and tested your idea. Unfortunately, it didn’t help - still can’t process data posted in json format…
Cheers,
Alex


#3

Hi Alex, sorry to hear that didn’t get it working for you. I’ve just tested this again, using a sample PHP script I’ve created, and I can tell you that it definitely works. Here’s the exact script I used (just add your own email address at the bottom).

http://gist.github.com/430561

Can you send your script to support@unbounce.com so we can have a look? Also, which version of PHP are you using?


#4

Hi Alex, sorry for the late response. I think the issue is that PHP converts any dots in variable names to underscores, so simply changing your code to this:

data = json\_decode(_POST[‘data_json’]);

should fix it right up!

See here for more information:

http://www.php.net/manual/en/language…

I was reading a thread on PHP6, and there’s debate amongst the developers as to whether or not this behaviour makes sense. Here’s the discussion if you’re interested:

http://www.pubbs.net/201001/php/48930…

Hope that helps! Would love to hear more about how you’re using our webhook…

Cheers!

  • Carl