-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmofhapi.php
51 lines (44 loc) · 1.82 KB
/
mofhapi.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
// This is a placeholder.
// Replace these with your actual MOFH API credentials and endpoints
$apiUrl = 'https://panel.myownfreehost.net:2087/json-api/'; // Replace with the WHM API endpoint
$apiKey = 'your_api_key'; // Replace with your WHM API key
// Example API request data
$requestData = array(
'cpanel_jsonapi_user' => 'your_cpanel_username', // Replace with your cPanel username
'cpanel_jsonapi_module' => 'account',
'cpanel_jsonapi_func' => 'listaccts',
// Add other required parameters for your specific API request
);
// Initialize cURL session
$ch = curl_init($apiUrl);
// Set cURL options for the request
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); // Use GET or POST based on the API documentation
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($requestData)); // Send request data as POST parameters if needed
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the response as a string
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: WHM ' . $apiKey, // Use appropriate authorization header (WHM API typically uses this format)
));
// Execute the cURL request
$response = curl_exec($ch);
// Check for cURL errors and handle them if needed
if (curl_errno($ch)) {
echo 'cURL error: ' . curl_error($ch);
// Handle the error appropriately
} else {
// Process the API response
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($statusCode == 200) {
// API request was successful
$responseData = json_decode($response, true);
// Handle and parse the response data as needed
var_dump($responseData);
} else {
// API request failed with an error status code
echo 'API request failed with status code ' . $statusCode;
// Handle the error appropriately
}
}
// Close the cURL session
curl_close($ch);
?>