PHP致命错误:在不在对象上下文中时使用$ this ...用于重定向()

I am new to PHP. I've been trying to get this authorization code to work, but am getting this error:

Call to undefined function redirect()

Code:

$Auth = Auth::getAuth();
if($Auth->loggedIn())
{
    redirect(getCoreSitePath().'/account.'.SITE_CONFIG_PAGE_EXTENSION);
}

if(isset($_REQUEST['error_description']))
{
    $error = $_REQUEST['error_description'];
}
redirect(getCoreSitePath()."/login.".SITE_CONFIG_PAGE_EXTENSION."?social_login_error=".urlencode($error));

Based on some Googling, I saw that I might need to add $this->load->helper('url');

Revised code:

$Auth = Auth::getAuth();
$this->load->helper('url');
if($Auth->loggedIn())
{
    redirect(getCoreSitePath().'/account_home.'.SITE_CONFIG_PAGE_EXTENSION);
}

if(isset($_REQUEST['error_description']))
{
    $error = $_REQUEST['error_description'];
}
redirect(getCoreSitePath()."/login.".SITE_CONFIG_PAGE_EXTENSION."?plugin_social_login_error=".urlencode($error));

But now I get this error:

Using $this when not in object context

I tried the suggestions here but wasn't able to get it working.

redirect() is not a built-in function, do you have it defined somewhere? If not, you can simply define one without having to change your code

function redirect($url)
{
    header("Location: $url");
    die();
}

Note that this function is not really needed, you can simply change your redirect() calls with the header call that this function makes but i just added it because you have alot of calls for redirect() and will need to change a lot of code to do it that way. And you can define this function outside any class and then you can use it without $this->