I found a script in the open spaces of the network, the converter of cookies of Netscape format files in JSON format. But for some reason, instead of JSON Cookies, the source code of the html page is written to cookies.json; date() expects parameter 2 to be long, string given or file_get_contents(): filename cannot be empty because after reloading the page, the script was not working, something incomprehensible is happening to it, which is not clear to do. Here is the code itself:
<?php function extractCookies($string) { $cookies = array(); $lines = explode("\n", $string); foreach ($lines as $line) { if (isset($line[0]) && substr_count($line, "\t") == 6) { $tokens = explode("\t", $line); $tokens = array_map('trim', $tokens); $cookie = array(); $cookie['domain'] = $tokens[0]; $cookie['flag'] = $tokens[1]; $cookie['path'] = $tokens[2]; $cookie['secure'] = $tokens[3]; $cookie['expiration'] = date('Ymd h:i:s', $tokens[4]); $cookie['name'] = $tokens[5]; $cookie['value'] = $tokens[6]; $cookies[] = $cookie; } } if ($cookies != null) return json_encode( $cookies); } if (isset($_FILES['file'])) { $contents = file_get_contents( $_FILES['file']['tmp_name']); $outputName = 'cookies.json'; $convertContents = extractCookies($contents); file_put_contents($outputName, json_encode($convertContents)); if (file_exists($outputName)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="'.basename($outputName).'"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($outputName)); readfile($outputName); unlink($outputName); exit; } } ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Convert Cookies from "txt" to "json" format</title> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <div class="container my-5"> <p class="lead mb-5"> Browse an `cookies.txt` for upload <i>(file name doesn't matter)</i> and begin converting. </p> <form method="POST" enctype="multipart/form-data"> <label class="btn btn-lg btn-block btn-secondary"> <input type="file" id="file" name="file" hidden> Browse </label> <button type="submit" class="btn btn-block btn-primary">Convert!</button> </form> </div> </body> </html> Please tell me where and what is the error.