4.6.x bootstrap.inc referer_uri()
4.7.x bootstrap.inc referer_uri()
5.x bootstrap.inc referer_uri()
6.x bootstrap.inc referer_uri()

Return the URI of the referring page.

2 calls to referer_uri()
statistics_exit in modules/statistics/statistics.module
Implementation of hook_exit().
watchdog in includes/bootstrap.inc
Log a system message.


includes/bootstrap.inc, line 832
Functions that need to be loaded on every Drupal request.


function referer_uri() {
  if (isset($_SERVER['HTTP_REFERER'])) {
    return $_SERVER['HTTP_REFERER'];


JulienD’s picture

Here is a code snippet to check if the user come from your site or not

global $base_url;
if (($referer_uri = referer_uri()) && (preg_match("!^$base_url/!", $referer_uri))) {
  // Do your stuff
dwatts3624’s picture

Thank you for the script. It works great!

But only for authenticated users. I found that when the user is not logged in referer_uri() doesn't return anything.

In fact, $_SERVER['HTTP_REFERER'] doesn't return anything to anonymous users.

Thoughts? Maybe I'm missing something obvious (usually the case).


dangswiss’s picture

I wanted to use referer_uri() in a 2-step product order process in Ubercart. Couldn't get it to work for anonymous users. So I stuck with the following snippet and got it to work just fine:

$last_page_visited = $_SERVER['HTTP_REFERER'];
if(preg_match('/order-step1/', $last_page_visited) && preg_match('/cart/', current_path()))
drupal_goto($path = 'order-step2');
nagiek’s picture

You should be using session_api instead.