Created
February 14, 2020 18:29
-
-
Save numanturle/431a660ce77ba5e8fadbe24847903cc8 to your computer and use it in GitHub Desktop.
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
function encryptCookie($value){ | |
if(!$value){return false;} | |
$key = APP_KEY; | |
$text = $value; | |
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); | |
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); | |
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv); | |
return trim(base64_encode($crypttext)); //encode for cookie | |
} | |
function decryptCookie($value){ | |
if(!$value){return false;} | |
$key = APP_KEY; | |
$crypttext = base64_decode($value); //decode cookie | |
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); | |
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); | |
$decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $crypttext, MCRYPT_MODE_ECB, $iv); | |
return trim($decrypttext); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
fix;
if (isset($_SERVER['HTTP_COOKIE'])) {
$cookies = explode(';', $_SERVER['HTTP_COOKIE']);
foreach($cookies as $cookie) {
$parts = explode('=', $cookie);
$name = trim($parts[0]);
setcookie($name, '', time()-1000);
setcookie($name, '', time()-1000, '/');
}
}