-
-
Save laocoi/eb4f394dd15254d25924bf4d5c351c33 to your computer and use it in GitHub Desktop.
Quickly Extract "Netscape HTTP Cookie File" to "JSON" (from ".txt" to ".json" format)
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 | |
require('extract-cookies.php'); // require the file from above... | |
if (isset($_FILES['file'])) { | |
$inputName = $_FILES['file']['tmp_name']; | |
$contents = file_get_contents($inputName); | |
$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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment