Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
iOS safe cookie session start
function cookiesafe_session_start(){
$sn = session_name();
if (isset($_COOKIE[$sn])) {
$sessid = $_COOKIE[$sn];
} else if (isset($_GET[$sn])) {
$sessid = $_GET[$sn];
} else {
session_start();
return false;
}
if (!preg_match('/^[a-zA-Z0-9,\-]{22,40}$/', $sessid)) {
$newSessId = md5(microtime());
session_id($newSessId);
if(isset($_COOKIE[$sn]))setcookie($sn,$newSessId);
}
session_start();
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment