0

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.

Community
  • 1
  • 1
EngrAbbas
  • 149
  • 1
  • 3
  • 10

1 Answers1

1

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->

Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
  • so I should add this and disregard the '$this->load->helper('url');' – EngrAbbas Jan 29 '15 at 17:01
  • It is only to provide support for your redirect calls, it does nothing for helper url changes, You don't have to change anything else – Hanky Panky Jan 29 '15 at 17:02
  • now I'm having problems with `getCoreSitePath()` it says call to undefined function – EngrAbbas Jan 29 '15 at 17:12
  • That means you are using broken code, there are multiple functions that you are calling and are not defined. I would recommend you take a minute and check if there is any include file that came with that code and is missing because that might contain all those missing functions. Patching for everything wont take it anywhere. – Hanky Panky Jan 29 '15 at 17:13