Skip to content

Instantly share code, notes, and snippets.

@andrienko
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrienko/14331b88b0e877087a2f to your computer and use it in GitHub Desktop.
Save andrienko/14331b88b0e877087a2f to your computer and use it in GitHub Desktop.
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