<?php | |
$api_url = "https://my.flarum.url/api/users"; | |
$token = $session->token; // See: https://gist.github.com/woganmay/88f15e96fc019657a0e594366403b5cf | |
// This must be a token for a user with Administrator access | |
$new_username = "johnsmith"; | |
$new_password = "password1234"; | |
$new_email = "john.smith@example.org"; | |
$ch = curl_init($api_url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, [ | |
'Content-Type: application/json', | |
'Authorization: Token ' . $token | |
]); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([ | |
'data' => [ | |
'attributes' => [ | |
"username" => $new_username, | |
"password" => $new_password, | |
"email" => $new_email | |
] | |
] | |
])); | |
$result = curl_exec($ch); | |
$new_user = json_decode($result); | |
$new_user; // Will be a large JSON object containing the new user's details: | |
/* SAMPLE | |
{ | |
"data": | |
"type": "users", | |
"id": "1", | |
"attributes": { | |
"username": "johnsmith", | |
"joinTime": "2017-02-11T16:34:40+00:00", | |
"isActivated": false, | |
"email": "john.smith@example.org", | |
} | |
} | |
*/ |
This comment has been minimized.
This comment has been minimized.
Its Done || Thanks :) `<?php $some_data_json = json_encode($some_data, true); $apikey = 'YACub2KLfe8hjfIUcUKtt6t2SMKJUIXnZbqhc3nX'; $curl = curl_init(); // We POST the data curl_setopt($curl, CURLOPT_HTTPHEADER, [ // You can also bunch the above commands into an array if you choose using: curl_setopt_array // Send the request //print_r($result); if(isset($token)) { ?>` |
This comment has been minimized.
How to login from outside, please share code?