Search code examples
phpdrupal

How to refresh the current page


I'm customizing a module in Drupal and in that module I'd like to refresh the current page right after an if statement, how can I refresh the current page in PHP


Solution

  • You can't in PHP if you've already outputted something (since all headers must be sent before output begins).

    If you haven't outputted:

    header('Location:: current_page_url');
    or
    header("Refresh:0");
    

    Better way is to do it through Javascript with the window object

    $window.location.reload();