parsing a String in PHP -
i got string in following format:
a:5:{s:21:"securimage_code_value";s:4:"4l7z";s:6:"userid";s:2:"25";s:8:"username";s:6:"lupoxy";s:10:"angemeldet";s:4:"true";s:9:"user_role";s:3:"111";}
i need parse entries within quotes, , array this:
$testarray[0]['key'] = "securimage_code_value"; $testarray[0]['value'] = "417z"; $testarray[1]['key'] = "userid"; $testarray[1]['value'] = "25";
and on...
no i'm not trying hack sessions ;) i'm using uploadify codeigniter, , need verify, user allowed upload, based on session. cannot use codeigniter session functions, since uploadify creates own session upload-php-script. pass session_id uploadify scriptdata, , session_id in ci_sessions table, parse required session userdata myself.
maybe knows better solution well? ;)
$params = unserialize($string); $testarray = array(); foreach($params $key => $value) { $testarray[]= compact('key', 'value'); }
see unserialize documentation.
update. inherit/patch sess_read()
system/libraries/session.php make accept custom session id:
before:
function sess_read() { ... // unserialize session array $session = $this->_unserialize($session); ... }
after:
function sess_read($session_id = null) { ... // unserialize session array $session = $this->_unserialize($session); if ($session_id) $session['session_id'] = $session_id; ... }
also remember set sess_match_useragent = false
in session config file, otherwise request uploadify rejected, because flash's user agent different broswer's user agent.
and can load session id:
$this->session->sess_read($custom_session_id)
much less of hack parsing data db manually.
Comments
Post a Comment