'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 1:[1]

Php offers the following function to invoke a page refresh

header("Refresh:0");

If you require a page redirect you can use the following.

header("Refresh:0; url=redirect_page.php");

Solution 2:[2]

just header("Refresh:0");

Solution 3:[3]

I'm surprised nobody mentioned the "Drupal Way":

drupal_goto(current_path()); 

This exact scenario is tested in modules/simpletest/tests/common_test.module function common_test_init():

/**
 * Implements hook_init().
 */
function common_test_init() {
  if (variable_get('common_test_redirect_current_path', FALSE)) {
    drupal_goto(current_path());
  }
  if (variable_get('common_test_link_to_current_path', FALSE)) {
    drupal_set_message(l('link which should point to the current path', current_path()));
  }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 WeeniehuahuaXD
Solution 2 Drop Shadow
Solution 3 Nimantha