Created
February 12, 2017 13:38
-
-
Save woganmay/88f15e96fc019657a0e594366403b5cf to your computer and use it in GitHub Desktop.
PHP CURL code to authenticate with Flarum API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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