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

How to Check Cookie ? Help

Discussion in 'XenForo Development Discussions' started by wmnitin, Jun 18, 2014.

  1. wmnitin

    wmnitin Member

    Hello, I am creating my own php application. Actually i want to get userid of logged in user. As far as i know first i have to get cookie.

    So, here is code that i have placed in /library/mycode/example/index.php

    class Mycode_Example_index
    public static function getHtml()
      $nit= (isset($_COOKIE["xf_user"]) ? $_COOKIE["xf_user"] : '');
      if ($nit) {
       echo "display information for users who are logged on";
      if (!$nit) {
       echo "display information for users who are not logged on";
    Now i am using it with callback <xen:callback class="Mycode_Example_index" method="getHtml"></xen:callback>

    But it is showing not logged on...even i am logged in !
  2. wmnitin

    wmnitin Member

    Actually I have resolved it by using another way ! ;) But still experts comments needed abt whats wrong in this code :)
  3. Brogan

    Brogan XenForo Moderator Staff Member

    Which method did you use, out of interest?
  4. wmnitin

    wmnitin Member

    I added some extra lines


    $visitor = XenForo_Visitor::getInstance()->toArray();

    then got userid from $visitor :cool: Hope it will also help others (y)
  5. digitalpoint

    digitalpoint Well-Known Member

    There's a static method that is simpler to get the user ID...

    $userId XenForo_Visitor::getUserId();
    wmnitin likes this.

Share This Page