diff --git a/database/database.mysql b/database/database.mysql
index 334561860b9f012f58673ab4d23cbbb5e6fdf62b..70bfb523111404e979eddba58831df56299c9dcf 100644
--- a/database/database.mysql
+++ b/database/database.mysql
@@ -768,6 +768,7 @@ CREATE TABLE watchdog (
   severity tinyint(3) unsigned NOT NULL default '0',
   link varchar(255) NOT NULL default '',
   location varchar(128) NOT NULL default '',
+  referer varchar(128) NOT NULL default '',
   hostname varchar(128) NOT NULL default '',
   timestamp int(11) NOT NULL default '0',
   PRIMARY KEY (wid)
diff --git a/database/database.pgsql b/database/database.pgsql
index 31c4fcd0d83fd897e45a37eff1763c1b5abc79ee..5aab7c4eda4e1ccc9f5fe416a1babb7c182d0530 100644
--- a/database/database.pgsql
+++ b/database/database.pgsql
@@ -762,6 +762,7 @@ CREATE TABLE watchdog (
   severity smallint NOT NULL default '0',
   link varchar(255) NOT NULL default '',
   location varchar(128) NOT NULL default '',
+  referer varchar(128) NOT NULL default '',
   hostname varchar(128) NOT NULL default '',
   timestamp integer NOT NULL default '0',
   PRIMARY KEY  (wid)
diff --git a/database/updates.inc b/database/updates.inc
index fa63b67e217b65e0896e468791dd591991b11f85..5427e9674d165d398206f882d53797b4288853ea 100644
--- a/database/updates.inc
+++ b/database/updates.inc
@@ -117,7 +117,8 @@
   "2005-05-10" => "update_138",
   "2005-05-11" => "update_139",
   "2005-05-12" => "update_140",
-  "2005-05-22" => "update_141"
+  "2005-05-22" => "update_141",
+  "2005-07-29" => "update_142"
 );
 
 function update_32() {
@@ -2511,6 +2512,12 @@ function update_141() {
   return $ret;
 }
 
+function update_142() {
+  $ret = array();
+  $ret[] = update_sql("ALTER TABLE {watchdog} ADD COLUMN referer varchar(128) NOT NULL");
+  return $ret;
+}
+
 function update_sql($sql) {
   $edit = $_POST["edit"];
   $result = db_query($sql);
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index 8354520e6609c3d444c68f44a506edaffedcf991..b307ab910c3e4e12115bf4b486011af43e5b37db 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -739,7 +739,7 @@ function request_uri() {
  */
 function watchdog($type, $message, $severity = WATCHDOG_NOTICE, $link = NULL) {
   global $user;
-  db_query("INSERT INTO {watchdog} (uid, type, message, severity, link, location, hostname, timestamp) VALUES (%d, '%s', '%s', %d, '%s', '%s', '%s', %d)", $user->uid, $type, $message, $severity, $link, request_uri(), $_SERVER['REMOTE_ADDR'], time());
+  db_query("INSERT INTO {watchdog} (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (%d, '%s', '%s', %d, '%s', '%s', '%s', '%s', %d)", $user->uid, $type, $message, $severity, $link, request_uri(), referer_uri(), $_SERVER['REMOTE_ADDR'], time());
 }
 
 /**
diff --git a/modules/watchdog.module b/modules/watchdog.module
index 64a580fef02b152ac1fbafe05366b4d9e223d596..68f460c35de11163700f7bb0e9d123ac422d12bf 100644
--- a/modules/watchdog.module
+++ b/modules/watchdog.module
@@ -141,6 +141,7 @@ function watchdog_event($id) {
     $output .= ' <tr><th>'. t('Date') .'</th><td>'. format_date($watchdog->timestamp, 'large') .'</td></tr>';
     $output .= ' <tr><th>'. t('User') .'</th><td>'. format_name($watchdog) .'</td></tr>';
     $output .= ' <tr><th>'. t('Location') ."</th><td>". l($watchdog->location, $watchdog->location) ."</td></tr>";
+    $output .= ' <tr><th>'. t('Referrer') ."</th><td>". l($watchdog->referer, $watchdog->referer) ."</td></tr>";
     $output .= ' <tr><th>'. t('Message') ."</th><td>$watchdog->message</td></tr>";
     $output .= ' <tr><th>'. t('Severity') .'</th><td>'. $severity[$watchdog->severity] .'</td></tr>';
     $output .= ' <tr><th>'. t('Hostname') ."</th><td>$watchdog->hostname</td></tr>";
diff --git a/modules/watchdog/watchdog.module b/modules/watchdog/watchdog.module
index 64a580fef02b152ac1fbafe05366b4d9e223d596..68f460c35de11163700f7bb0e9d123ac422d12bf 100644
--- a/modules/watchdog/watchdog.module
+++ b/modules/watchdog/watchdog.module
@@ -141,6 +141,7 @@ function watchdog_event($id) {
     $output .= ' <tr><th>'. t('Date') .'</th><td>'. format_date($watchdog->timestamp, 'large') .'</td></tr>';
     $output .= ' <tr><th>'. t('User') .'</th><td>'. format_name($watchdog) .'</td></tr>';
     $output .= ' <tr><th>'. t('Location') ."</th><td>". l($watchdog->location, $watchdog->location) ."</td></tr>";
+    $output .= ' <tr><th>'. t('Referrer') ."</th><td>". l($watchdog->referer, $watchdog->referer) ."</td></tr>";
     $output .= ' <tr><th>'. t('Message') ."</th><td>$watchdog->message</td></tr>";
     $output .= ' <tr><th>'. t('Severity') .'</th><td>'. $severity[$watchdog->severity] .'</td></tr>';
     $output .= ' <tr><th>'. t('Hostname') ."</th><td>$watchdog->hostname</td></tr>";