简体   繁体   中英

Redirect user to last viewed page in hook_menu

I have implemented hook_menu in order to set a $_SESSION var that stores the current stylesheet preference for users. Once it's set, I'd like to redirect users back to the previous page they were viewing. How can I get the value of the previous url?

I just found the answer - referer_uri() returns the value I need and drupal_goto() will do the redirect.

So to redirect a user back to the previous page: drupal_goto( referer_uri() )

Drupal's referer_uri() is the way to do it, but be careful using this function, as it relies on php's HTTP_REFERER. HTTP_REFERER is not a reliable variable, as it is often not set. For more information check out : http://www.php.net/manual/en/reserved.variables.server.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM