Reputation: 311
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]'=>'[email protected]',
'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
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)
Final Working Code
<?php
// set post fields
$post = [
// this i don`t master fell free to approach the subject for future reffrance
'authenticity_token'=>'NKWAg8mGA9gUueBaJ5Og+oEOC5O2rZarZzMK+GnjuCA=',
'user[email]'=>'',
'user[first_name]'=>'',
'user[last_name]'=>'',
'user[password]'=>'',//smart password (had to be 8char long)
'user[country]'=>'',
'user[mc]'=>'', //id of the country
'user[lc_input]'=>'', //id of the dropdown
'user[lc]'=>'',//id of the dropdown
'commit'=>'REGISTER',//value of submit
];
$ch = curl_init('https://auth.aiesec.org/users/');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
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);
?>
Upvotes: 0
Views: 169
Reputation: 2952
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.
Upvotes: 2