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

xf_user cookie issue

Discussion in 'XenForo Development Discussions' started by liv4spd, Oct 20, 2013.

  1. liv4spd

    liv4spd Member

    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:
    ......
    }
     
  2. AndyB

    AndyB Well-Known Member

    I assume this is in an add-on, in that case the thread should have been started in this forum:

    http://xenforo.com/community/forums/xenforo-development-discussions.34/

    Try this:

    PHP:
    $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:
    ......
    }
     
    liv4spd likes this.
  3. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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.
     
    liv4spd likes this.
  4. liv4spd

    liv4spd Member

    It works! Now my website is clear of errors(y)

    I appreciate the big help very much.

     

Share This Page