Infinite redirects with drupal_goto I am writing my own 403 page, and would like to redirect the user to the login page if the user is not logged in. I use this code in a page callback, but when I am viewing an unauthorized page (say /user/1) as anonymous user, I got infinite redirect to /user/1.

function MODULE_membercheck() {
    global $user;
    if (!$user-&gt;uid) {
        //drupal_goto('user/login', array('query' =&gt; array('destination' =&gt; 'member/check')));
        drupal_goto('user/login'); //these two lines won't work 
        return;
    }
    // other stuff.
}


update

It is quite easy to reproduce the problem. Just create a module and add a menu (member/check), and redirect anonymous user to login page in the page callback function. Then set the default 403 page to this menu entry, and try to open an unauthorized page.
Where is MODULE_membercheck() getting called from? It would seem that it's getting called on user/login page requests which makes these pages redirect to themselves, hence the infinite loop.

You can either modify the calling of the function to ensure it doesn't get called on the login page or add a check in your function to make sure the current path is NOT user/login before doing the redirect, something like this:

function MODULE_membercheck(){
  global $user;
  if (!$user-&gt;uid &amp;&amp; current_path() != '/user/login') {
    drupal_goto('user/login', array('query' =&gt; array('destination' =&gt; 'member/check')));
  }
  // other stuff.
}