Created
February 1, 2016 06:48
-
-
Save AwaisKing/8e06b37b83df469cdc3e to your computer and use it in GitHub Desktop.
Netscape HTML Cookie from Firefox to Google Chrome Converter (PHP)
This file contains 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 | |
error_reporting(E_ALL); | |
ini_set('display_errors','On'); | |
ini_set("error_reporting", E_ALL); | |
ini_set('display_errors', 1); | |
ini_set('display_startup_errors', 1); | |
set_error_handler('errorHandler'); | |
/** | |
* Firefox Cookies to JSON (Chrome) | |
* -------------------------------- | |
* Converts Firefox's Netscape HTTP Cookie file to JSON | |
* for importing in Google Chrome through EditThisCookie | |
* extension. | |
* -------------------------------- | |
* Thanks to philipnorton42 @ HashBangCode | |
* http://www.hashbangcode.com/blog/netscape-http-cooke-file-parser-php | |
* for posting Cookie Parser. | |
**/ | |
function errorHandler( $errno, $errstr, $errfile, $errline, $errcontext) { | |
} | |
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('Y-m-d h:i:s', $tokens[4]); | |
$cookie['name'] = $tokens[5]; | |
$cookie['value'] = $tokens[6]; | |
$cookies[] = $cookie; | |
} | |
} | |
if ($cookies != null) | |
return json_encode( $cookies); | |
} | |
echo "<!DOCTYPE html><html style='text-align: center;'><head><style>html,body { height:100%; width:100%; padding:0; margin:0;}</style><title>Firefox Cookie Converter</title></head><body><hr><h1>Firefox Cookies to Chrome</h1><hr><br><br><h3>Select cookies.txt file</h3><br><form method='post' enctype='multipart/form-data'><input type='file' name='fileToUpload' id='fileToUpload'><input type='submit' value='Make it JSON!' name='submit'></form><br><br><br>"; | |
if(isset($_POST["submit"])) | |
echo '<textarea cols="100" rows="20">' . extractCookies( file_get_contents($_FILES['fileToUpload']['tmp_name']) ) . '</textarea>'; | |
echo "<br><br><br><br><br><hr><b>How to get cookie.txt:</b><br>Download and install <a href='https://addons.mozilla.org/en-US/firefox/addon/cookies-exportimport/'>Cookies Export/import</a> addon<br>Click on Tools in menu bar, then click on <i>Export cookies</i>.<br>"; | |
echo "<br><b>How to import into Google Chrome:</b><br>Download and install <a href='https://chrome.google.com/webstore/detail/edit-this-cookie/fngmhnnpilhplaeedifhccceomclgfbg'>EditThisCookie</a> addon<br>Click on <i>EditThisCookie</i> icon in toolbar, then click on <i>Import</i> button and paste."; | |
echo '</body></html>'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment