XF 2.0 Visitor setup

Not quite, no.

What exactly are you trying to do? We'd generally only do setup(0) in XF1 if a user was being logged out. We have specific methods for handling that now.
 
Installing cookies for authorized users
Code:
class Listener
{
    private static $initialSetup = true;

    public static function visitor_setup(\XF\Entity\User &$visitor)
    {
        $isUserLoggedIn = $visitor['user_id'] != 0;
        if ($isUserLoggedIn)
        {
            if(!\XF::app()->request()->getCookie('logged_in'))
            {
                \XF::app()->response()->setCookie('logged_in', 1, 365 * 86400);

                if (self::$initialSetup)
                {
                    //XenForo_Visitor::setup(0);
                }
            }
        }
        else
        {
            $scriptName = basename($_SERVER['SCRIPT_NAME'], '.php');
            if ($scriptName == 'index')
            {
                if (!\XF::app()->request()->getCookie('logged_in'))
                {
                    \XF::app()->response()->setCookie('logged_in', false);
                }
            }
        }

        self::$initialSetup = false;
    }
}
 
As I said before, if you're trying to log a user out, there's specific methods to do that already.

Have a look at the Logout controller and actionLogout in the Admin Login controller.
 
PHP:
$scriptName = basename($_SERVER['SCRIPT_NAME'], '.php');
IMHO such code should be avoided.

A better approach would be
PHP:
$scriptName = basename(\XF::app()->request()->getBaseUrl(), '.php');
 
As I said before, if you're trying to log a user out, there's specific methods to do that already.

Have a look at the Logout controller and actionLogout in the Admin Login controller.
\XF::app()->session()->logoutUser(). thx
 
IMHO such code should be avoided.

A better approach would be
PHP:
$scriptName = basename(\XF::app()->request()->getBaseUrl(), '.php');
getBaseUrl() will return the same.
PHP:
public function getBaseUrl()
    {
        return $this->getServer('SCRIPT_NAME', '');
    }
But it's more beautiful, at the moment it was just a sketch.
 
It does not necessarily return the same. XF\Http\Request does get the data from the values passed to its constructor.

If the App is no started through a standalone web boostrap (eg. for integration purposes, unit testing, etc.) those values might be completely different from the raw values in $_SERVER), so if you access $_SERVER directly your code might have a completely different view of the world then the core.
 
It does not necessarily return the same. XF\Http\Request does get the data from the values passed to its constructor.

If the App is no started through a standalone web boostrap (eg. for integration purposes, unit testing, etc.) those values might be completely different from the raw values in $_SERVER), so if you access $_SERVER directly your code might have a completely different view of the world then the core.
I said it was a quick sketch
 
Back
Top Bottom