Skip to content

Instantly share code, notes, and snippets.

@woganmay
Created February 12, 2017 13:38
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save woganmay/88f15e96fc019657a0e594366403b5cf to your computer and use it in GitHub Desktop.
Save woganmay/88f15e96fc019657a0e594366403b5cf to your computer and use it in GitHub Desktop.
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