I'd like to show a message via drupal_set_message() after redirecting users from user/logout?destination=user.

I tested this code but it doesn't work.

if ($find) { 
  drupal_set_message(t('This entry is ignored.'), 'error');

  $form_state['redirect'] = array(
    array('query' => array('destination' => 'user')),


How do I display a message after redirecting user from the logout page?


1 Answer 1


Reading your code, it appears to me that you want to redirect /user/logout to /user.

If that's what you actually want, then you could use the Rules module for this, using an approach that is similar to my answer to the question "How to create a redirect to point to the user's id?", in which you use values for the_old_path and the_new_path that fit your needs here, i.e.:

  1. Change all occurences of the_old_path to user/logout.
  2. Change all occurences of the_new_path to user.
  3. Adapt the message being displayed to fit your needs, so that the user will also receive an informational message, e.g. similar to something like this one:

    The path /user/logout has been redirected automatically to path /user.

    If you don't want such message to appear, then just delete the line containing drupal_message in the rule.

Use the value of the [destination] variable in the redirect

In case you want to make the value (user in this case) of the URL argument (destination in this case) available as new variable to Rules, you can use the Rules URL Argument module. Here is a quote about it (from its project page):

... provides two rules conditions based on URL arguments:

  • check if a URL argument is present.
  • compare the value of an URL argument.

It also provides an action that makes the value of an URL argument available as new variable to Rules.

The newly provided Rules actions and conditions can be found under the "URL Argument" conditions and actions groups in the rule configuration interface.

For an example of how to use it, refer to Comment # 3 in issue # 1686360 which is about "Pass an amount to the url, ie; site/content/node-title?amount=10 or /node-title?=amount:10". Here is the relevant part of it:

  • add a "Check if URL argument exist" condition to your rule and set the "ARGUMENT" value to "amount".
  • add "Provide URL argument value" action to the rule and set "URL ARGUMENT NAME" value to "amount" and in the "Provided variables" section "ARGUMENT FROM URL - Variable name" to e.g. "amount_from_url".

You will now be able to use the amount value as a variable "amount-from-url" for other actions in this rule.

PS: If you're not familiar (enough/yet) with Rules, checkout the 32 (!!!) great, and free, video tutorials Learn the Rules framework.

  • I'm working on Drupal 7.37. When I just redirects to user/logout I am automatically redirected to node.
    – djik
    Aug 28, 2015 at 16:26
  • I'm not sure I understand your last comment. Are you saying something like 'I must use user/logout?destination=user instead of just user/logout as the path to be redirected'? If so, I'll adapt my answer accordingly (that's possible too). Aug 28, 2015 at 16:39
  • Hello, When I made ​​a redirection to user/logout page , I log out and automatically redirect to the page node
    – djik
    Aug 31, 2015 at 15:45
  • Thanks for your new comment. But it's about the same as your prior comment, and I still don't understand it completely. Try to correct my "guess" in my prior comment. I THINK you ask something like 'I must use user/logout?destination=user instead of just user/logout as the path to be redirected'? Can you CORRECT whatever is needed in what I think your question is? FYI: I extended my answer a bit. Aug 31, 2015 at 16:04
  • There is no module for drupal 8 but I can pass argument. However, I don't want to display message again when user refresh the page. Is there any way to do so?
    – cissharp
    Dec 30, 2016 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.