I’m trying to connect to McMyAdmin using the PHP function file_get_contents()
When I run the following code:
<?php
$url = 'http://mc.mywebsite.com/data.json?req=status';
$username = 'myuser';
$password = 'mypass';
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => sprintf("Authorization: Basic %s\r\n", base64_encode($username.':'.$password)).
"Content-type: application/x-www-form-urlencoded\r\n",
'timeout' => 3,
)
));
$data = file_get_contents($url, false, $context);
echo $data;
?>
I keep getting a 401 error. From what I’ve read this should get through the authentification. Am I doing something wrong?
Use CURL instead:
Note that without the “Accept: application/json” header – McMyAdmin 2 will reject API requests.