XF 2.1 php header(); in XF 2.1

Alteredd

Member
I recently upgraded to Xenforo 2 and am now running PHP 7.2, I'm using xf callback in the html template of a page to call my php function, everything is working as expected except the header('Location: https://....); call. I looks like this should work fine in PHP 7.2 do I need to do something special in XF 2 so the header redirect works?
 
What are you trying to accomplish, exactly? Where are you putting that header? If you just want to force https you can enable board url canonicalization in Options -> basic board information
 
Are you calling an exit() after header('Location:...')? Or even place the header() inside exit();
 
I'm not calling exit I'll give that a try, it's a form setup which when they submit adds record into a different database and then header redirects to PayPal with info obtained from form. Worked fine in XF 1 for me and quick test shows it worked ok in php7 wasn't sure if something specific to XF 2 that might precent that call
 
IMHO, you really should not be using header() within XF.

If you want to perform a redirect, the proper way probably would be smth. like this:
PHP:
class MyPage
{
    public static function myPageCallback(\XF\Pub\Controller\AbstractController $controller, \XF\Mvc\Reply\AbstractReply &$reply)
    {
        $reply = $controller->redirect($url);
    }
}
 
Top Bottom