Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP redirecting external site and POST json

Options
  • 18-09-2013 2:57pm
    #1
    Registered Users Posts: 338 ✭✭


    I am integrating a registration with another website. The other website posts my site some registration data in json, to a registration page on my site and prepopulating the fields. I take the user through the registration, then on success redirect back to the original site. This redirect is supposed to post some info back, in json format, the user ID etc. I'm not sure how to go about redirecting back and posting this data? I'd rather not use a JS form submit.

    Any help appreciated.
    //After I have registered the user on my site and it is successful  
    if($success){
    
    $postJsonArray = json_encode(array('success' => TRUE, 'userID' = 10));
    $postUrl = 'http://thirdpartysite.php';
    //somehow redirect and post this $postJsonArray to the URL
    
    }
    

    I see something like cURL suggested i.e:
    $ch = curl_init();
    
    $json = json_encode($data);
    
    curl_setopt($ch,CURLOPT_URL, $curl_url);
    curl_setopt($ch,CURLOPT_POST,1);
    curl_setopt($ch,CURLOPT_POSTFIELDS,$json);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    
    //execute post
    $result = curl_exec($ch);
    
    curl_close($ch);
    
    header("Location: http://example.com/redirect");
    

    How does this work on the third party site? i.e usually when you post the data using a submit button or something, you are sent to a new page and can use $_REQUEST to do something with the posted data. What happens when the data is sent with CURL and then you are redirected separately? That POST data is not on the page that the user has been directed to, right?


Comments

  • Registered Users Posts: 2,031 ✭✭✭colm_c


    That redirect you are doing is separate to the Json post request.

    For integrations I've done when you want to post data between two sites as part of a user handover, there are usually two ways:

    1. Server side post with identifier, this is as you are doing but has some identifier in the request to track the user, e.g. session id. Then you're just doing redirects. You'll need to somehow track this identifier and data across whatever applications use it

    2. Client side post. Create a form which has the data in hidden inputs and use JavaScript to submit/post the data when handing it over to the other applications.


  • Registered Users Posts: 2,781 ✭✭✭amen


    Why do you appear to be sending user login data over http ?


  • Registered Users Posts: 338 ✭✭jimmybeige


    amen wrote: »
    Why do you appear to be sending user login data over http ?

    Well it's not really critical information. Just an acknowledgement that the user successfully signed up to our site.


Advertisement