Reputation: 3141
I have tried bascially everything to get this working. Here's the chatLogin
function that I have currently:
function getUserID() {
$userid = 0;
if (!empty($_SESSION['basedata']) && $_SESSION['basedata'] != 'null') {
$_REQUEST['basedata'] = $_SESSION['basedata'];
}
if (!empty($_REQUEST['basedata'])) {
$userid = $_REQUEST['basedata'];
}
if (!empty($_COOKIE['ci_session'])) {
$uid = unserialize($_COOKIE['ci_session']);
if(!empty($uid['uid'])){
$userid = $uid['uid'];
}
}
return $userid;
}
The userid is saved as uid
in the cookie, and it doesn't work no matter what.
This is what the error log is showing me:
[16-Oct-2015 01:14:46 UTC] PHP Notice: unserialize(): Error at offset 0 of 40 bytes in /Applications/MAMP/htdocs/cometchat/integration.php on line 49 [16-Oct-2015 01:14:46 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/cometchat/integration.php:49) in /Applications/MAMP/htdocs/cometchat/cometchat_init.php on line 180
Any help is highly appreciated. I have been googling this exact issue for over 3 hours and no luck. Thank you very much guys.
Upvotes: 0
Views: 590
Reputation: 1865
The $_COOKIE['ci_session'] is just a pointer to session id in your webserver. You can't achieve any information from unserialize it (notice that the first PHP Notice you get from error log is because unserialize an invalid format value).
If you saved as userid as uid simply use $_COOKIE['uid'] to get it.
And about your getUserId has problems. If you're looking for userid first in session, then request, then cookie, the proper way would be:
function getUserID()
{
if (isset($_SESSION['basedata'])) return $_SESSION['basedata'];
if (isset($_REQUEST['basedata'])) return $_REQUEST['basedata'];
if (isset($_COOKIE['uid'])) return $_COOKIE['uid'];
return 0;
}
Regards,
Upvotes: 1