So i have something weird going on that i am not 100% sure what the reason for it is.
I am creating a script that logs into my ISP and saves the security token from the returned JSON to a file along with the current time + 300.
The HTTP request works perfectly fine and if i echo out the data it shows properly in the browser with no issues but when i try and save said data to a text file on my local server it seems to be getting encoded or something.
this is the security token returned
yJedovrH73bUz2Vuv2s8PPc3ju0U11eGaHMt73KLsYrb63Qe5IfZsz3BCAFv3vurasboPbiUjKXA0NlbE6lV0EWp2oZ8tnck9YODCHExCEmg9Gdv9dndyXkHAEaMDtJoGqEzie8_J9R7xg:071044
with 071044 being the current time + 300 but when i got and look in the text file i see the following
YWE0ZjBkZGUtODdlMi00ZDlmLWJjODUtYmRmNzgzMjhlOThkMjAyMjAzMDIwNzExNTc5NzVEQjY0OTA3RUE1MEMxNjhBQ0YxMTZGNThENjVDNDA2MkFCN0JG33F1272C
my code looks as follows
<?php
include 'functions.php';
$AUTH_URL = "https://api.domain.com/auth/token";
header('Content-Type: text/html; charset=UTF-8');
$AUTH_HEADERS = array(
"authorization: Basic sdfcdfasdffcgr",
"Content-Type: application/x-www-form-urlencoded",
"Cookie: token=sdfcdfasdffcgr; expires=Tue, 15-Mar-2022 18:52:53 GMT; Max-Age=1209600; path=/; domain=api.domain.com; secure; HttpOnly",
);
$AUTH_POST = "type=token";
$AUTH_REQUEST = REQUEST($AUTH_URL, $AUTH_POST, $AUTH_HEADERS, 30);
$AUTH_JSON = JSON_DECODE($AUTH_REQUEST, TRUE);
$AUTH_TOKEN = $AUTH_JSON['token'];
$AUTH_EXPIRATION = date("his", time() + $AUTH_JSON['expires']);
$NEW_DATA = $AUTH_TOKEN . ':' . $AUTH_EXPIRATION;
file_put_contents('token.txt', $NEW_DATA );
ECHO $NEW_DATA;
?>
inside of my functions.php file i have a single function to make the curl requests
function REQUEST($URL, $POST_DATA, $HEADERS, $TIMEOUT) {
$REQUEST = curl_init();
curl_setopt($REQUEST, CURLOPT_URL, $URL);
if ($POST_DATA && !empty($POST_DATA)) {
curl_setopt($REQUEST, CURLOPT_POST, 1);
curl_setopt($REQUEST, CURLOPT_POSTFIELDS, $POST_DATA);
}
if ($HEADERS && !empty($HEADERS)) {
curl_setopt($REQUEST, CURLOPT_HTTPHEADER, $HEADERS);
}
curl_setopt($REQUEST, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($REQUEST, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($REQUEST, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($REQUEST, CURLOPT_CONNECTTIMEOUT, $TIMEOUT);
$DATA = curl_exec($REQUEST);
if (curl_errno($REQUEST)) {
return 'Error:' . curl_error($REQUEST);
}
curl_close($REQUEST);
return $DATA;
}