Skip to content

Instantly share code, notes, and snippets.

@fdorantesm
Created February 22, 2018 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fdorantesm/6794f12069fb7ff822b474a5502de613 to your computer and use it in GitHub Desktop.
Save fdorantesm/6794f12069fb7ff822b474a5502de613 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