function referer_uri

You are here

4.6 bootstrap.inc referer_uri()
4.7 bootstrap.inc referer_uri()
5 bootstrap.inc referer_uri()
6 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.

File

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

Code

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

Comments

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

<?php
global $base_url;
if ((
$referer_uri = referer_uri()) && (preg_match("!^$base_url/!", $referer_uri))) {
 
// Do your stuff
}
?>

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).

DW

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:

<?php
$last_page_visited
= $_SERVER['HTTP_REFERER'];
if(
preg_match('/order-step1/', $last_page_visited) && preg_match('/cart/', current_path()))
{
drupal_goto($path = 'order-step2');
}
?>

You should be using session_api instead.