Last active
August 29, 2015 14:21
-
-
Save andrienko/14331b88b0e877087a2f to your computer and use it in GitHub Desktop.
iOS safe cookie session start
This file contains 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 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