PHP CURL code to authenticate with Flarum API
<?php | |
// Details to access Flarum | |
$api_url = "https://my.forum.url/api/token"; | |
$username = "my_flarum_user"; | |
$password = "my_flarum_pass"; | |
// CURL call | |
$ch = curl_init($api_url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, [ | |
'Content-Type: application/json' | |
]); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([ | |
'identification' => $username, | |
'password' => $password | |
])); | |
$result = curl_exec($ch); | |
$session = json_decode($result); | |
$session->token; // API Token | |
$session->userId; // Authenticated user ID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment