• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

xf_user cookie issue

#1
I am trying to use xf_user cookie to display different information depending on whether a user is logged on or not. Below is the code, I am thinking to use.

The problem is that when users are not logged in, xf_user is not definied, so I am getting a ton of the below error messages in my error log.
"undefinied index: xf_user".

Any idea, how I can get over this?

Thank you!


Code:
$bbuserid = $_COOKIE["xf_user"];

if ($bbuserid != '') {
// display information for users who are logged on:
......
}

if ($bbuserid == '') {
// display information for users who are not logged on:
......
}
 

Jake Bunce

XenForo moderator
Staff member
#3
Code:
$bbuserid = (isset($_COOKIE["xf_user"]) ? $_COOKIE["xf_user"] : '');

if ($bbuserid != '') {
// display information for users who are logged on:
......
}

if ($bbuserid == '') {
// display information for users who are not logged on:
......
}
That will fix the error message.
 
#4
It works! Now my website is clear of errors(y)

I appreciate the big help very much.

Code:
$bbuserid = (isset($_COOKIE["xf_user"]) ? $_COOKIE["xf_user"] : '');

if ($bbuserid != '') {
// display information for users who are logged on:
......
}

if ($bbuserid == '') {
// display information for users who are not logged on:
......
}
That will fix the error message.