0

I am trying to receive a cURL POST from another server, process the post in a script and give a response back by doing another cURL post to a website, according to a URL contained in the first POST. But I have no idea how to accept a cURL post in a PHP script.

Is it like:

if (isset($_POST['test'])){
  //execute some code
}

So Website 45661 posts to Server 1 and the script on Server 1 see it's Website 45661 and posts back to it via cURL.

Thanks

LSerni
  • 55,617
  • 10
  • 65
  • 107
Roy van Zanten
  • 3,125
  • 2
  • 17
  • 12

1 Answers1

0

Welcome to SO!

Your code is a start. FYI, it doesn't matter how your script is called, be it through curl, form submission, etc, so long as a post parameter called test is sent.

You could complete the code like so:

<?php
    //Simply exiting when the condition is not true is more elegant than
    //putting everything in curly braces
    if(!isset($_POST['test'])) exit;

    //Execute some code...

    //Give feedback using json, not curl
    $feedback=array(
        'success' => true,
        'message' => 'success message'
    );
    echo json_encode($feedback);
?>

It is much easier to deliver data to the one requesting your script with json than posting something back with curl. That way, you don't need to check who actually called your script, and it is also easier for testing, since the json object feedback will be shown in your browser.

Dennis Hackethal
  • 13,662
  • 12
  • 66
  • 115
  • I dont want to echo the code ofcourse. I want to send it back via curl to the correct website and user. – Roy van Zanten Sep 29 '12 at 15:45
  • If I curl post to the website running script will it return the json encoded string thas is being echoed? – Roy van Zanten Sep 29 '12 at 16:21
  • That is the idea :-) No matter how you call your script, it will echo out the json object (which will always be echoed to the user who requested the script) and based on that object the user can then evaluate it/perform an action. – Dennis Hackethal Sep 29 '12 at 23:04