Community Documentation

Front_page snippet: determining if a HOME link is internal or external for splash pages

Last updated October 21, 2007. Created by m1mic on August 27, 2005.
Edited by pwolanin, Dublin Drupaller. Log in to edit this page.

PLEASE NOTE These snippets are user submitted. Use at your own risk. For users who have setup Drupal using an alternate database to the default (MYSQL), please note that the snippets may contain some database queries specific to MYSQL.

<?php
/**
* This front_page php snippet checks to see if someone has clicked on
* a "home" link on your site or if they are clicking through
* from an external link or site.
*
* Useful for drupal sites with flash intros.
*
* Change the $yoursite value to your website address
*
* This has been tested and works with Drupal 4.5.x and Drupal 4.6.x
*
*/
$yoursite = "example.com";
// get referrer from _SERVER array
$ref = $_SERVER["HTTP_REFERER"];

// check the referrer
if  (!stristr($ref, "$yoursite"))
{
   
//Offsite referrer detected
   
print "display content for visitors clicking through from external sites";

}
else {print
"display content for internal HOME links";}
?>

About this page

Drupal version
Drupal 4.5.x or older, Drupal 4.6.x

Archive

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.