Daniel Daniel - 3 months ago 14
Ajax Question

Complete form with cURL using PHP (POST)

I'm trying to make a registration system where users that visit us and register to our website will have an account on a secondary website in order for them to be able to see some opportunities.

So here it goes: The website were I want to POST the Form and Register

My code so far

<?php
// set post fields
$post = [
// this i don't master fell free to approach the subject for future reffrance
'authenticity_token'=>'vhmPffEAIiIbjo36K8CI77+YDQfMPBWEG8ymplsGJ0w=',
'user[email]'=>'test@gmail.com',
'user[first_name]'=>'test',
'user[last_name]'=>'test',
'user[password]'=>'12345678',//smart password (had to be 8char long)
'user[country]'=>'Country(placeholder)',
'user[mc]'=>'1560', //id of the country
'user[lc_input]'=>'1475', //id of the dropdown
'user[lc]'=>'1475',//id of the dropdown
'commit'=>'REGISTER',//value of submit

];

$ch = curl_init('https://auth.aiesec.org/users/sign_in');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

// execute!
$response = curl_exec($ch);

// close the connection, release resources used
curl_close($ch);

// do anything you want with your response
var_dump($response);
?>


Story:

As a user I want to be able to complete a form on domain A and at the same time have an account on domain B using CURL or even JS and AJAX.

If you have any solution to achieve this please let me know :) You can also have a look on the website.

Thank you!

Late edit

Postman POST account

I`ve made this in POSTMAN. So I think I should be able to make the for post that information. If you have other suggestions.

In this case server returns 500 as success and 200 as error (security)

Answer

You are connection via https. So you should add these lines:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

I tested your code and the website responded "Wrong username / password". That means curl is connecting correctly.