How do I retain the query string after login? I need the user,opening a certain page of my site (www.foo.com/page_to_visit), to login and then go to the requested page, so I set up an hook_menu for this specific page and a callback. In the callback I added this code which works

drupal_goto('user', array('query'=&gt;drupal_get_destination()))


but if the url contains query strings (www.foo.com/page_to_visit?id=12&amp;od=12) they are removed. I mean that, after login, the user gets redirected to www.foo.com/page_to_visit instead of www.foo.com/page_to_visit?id=12&amp;od=12. How do I avoid this behaviour?

UPDATE: Drupl_goto has something supporting this. Produced this code, following documentation

$args = array();
$params = $_GET;
$args[] = $params['q'];
unset($params['q'], $params['destination']);
if (count($params) &gt; 1) {
  $pippo['query'] = $params;
  $args[] = $pippo;
}
drupal_goto('user', array('query'=&gt;$args));

$args results in ---&gt;
Array
( [0] =&gt; page_to_visit
  [1] =&gt; Array
    ( [query] =&gt; Array
            ( [id] =&gt; 12 
              [od] =&gt; 12
            )
    )
)


The result is odd for the redirect looks like
    http://www.foo.com/user?0=page_to_visit&amp;1[query][id]=12&amp;1[query][od]=12
I think, my suggestion is :-


alter login form
add a hidden field for destination URL.
add submit handler  like $form['#submit'][] = 'destination_redirect_handler'
use drupal_goto('destination_redirect_url') in this destination_redirect_handler