When is it necessary to check_url()? When is it necessary to use check_url()? For instance, if I create a login link by putting the code below in the body of a block, which of the 3 check_url() calls are necesssary and which ones are not?

&lt;?php print '&lt;a href="/user?destination=';
if ((preg_match('#^user(?:$|/login$|/logout$|/register$)#', 
  check_url(current_path())) &amp;&amp; !isset($_GET['destination'])) || 
  preg_match('#^user(?:$|/login$|/logout$|/register$)#', 
  drupal_get_normal_path(check_url($_GET['destination']))) || 
  drupal_get_http_header('Status') === '404 Not Found') {
    print 'homepage';
} 
else {
  print drupal_get_path_alias(check_url(reset(drupal_get_destination()))); 
}
print '"&gt;Login&lt;/a&gt;';
?&gt;
If you just use l($text, $path, array $options = array()) you can simplify your code and it will take care of check_url for you.