Skip to content

Instantly share code, notes, and snippets.

@sumonst21
Forked from fdorantesm/sessions.php
Created August 27, 2021 04:12
Show Gist options
  • Save sumonst21/33998b9252f98ba6e06edca9eadd980a to your computer and use it in GitHub Desktop.
Save sumonst21/33998b9252f98ba6e06edca9eadd980a to your computer and use it in GitHub Desktop.
PHPSESSID Helper functions
<?php
function decode_session($data){
$temp = $_SESSION;
session_decode($data);
$out = $_SESSION;
$_SESSION = $temp;
return $out;
}
function encode_session($data){
$temp = $_SESSION;
$_SESSION = $data;
$out = session_encode();
$_SESSION = $temp;
return $out;
}
function delete_session($id){
$session_file = session_save_path() . "sess_" . $id;
if (file_exists($session_file)) {
return unlink($session_file);
} else {
return -1;
}
}
function overwite_session($session_id, $data){
$sess = session_save_path() . "sess_" . $session_id;
if (file_exists($sess)) {
$sessionFile = fopen($sess, "w");
if (is_writable($sess)) {
fwrite($sessionFile, encode_session($data));
}
}
}
function get_session_data($hash){
$file = session_save_path() . "sess_" . $hash;
if (file_exists($file)) {
return decode_session(file_get_contents($file));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment