Changeset 2738

Show
Ignore:
Timestamp:
06/02/2008 11:16:30 AM (6 months ago)
Author:
Shadowhand
Message:

Added slightly more advanced detection to request::referrer(), to return a URI if the referrer domain/path is the same as the base URL. This allows distinguishing between a remote and local referrer.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/helpers/request.php

    r2639 r2738  
    2626        public static function referrer($default = FALSE) 
    2727        { 
    28                 return ( ! empty($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : $default; 
     28                if ( ! empty($_SERVER['HTTP_REFERER'])) 
     29                { 
     30                        // Get base url 
     31                        $base = url::base((bool) Config::item('core.index_page')); 
     32 
     33                        // Set referrer 
     34                        $ref = $_SERVER['HTTP_REFERER']; 
     35 
     36                        if (strpos($ref, $base) === 0) 
     37                        { 
     38                                // Remove the base URL from the referrer 
     39                                $ref = substr($ref, strlen($base)); 
     40                        } 
     41                } 
     42 
     43                return isset($ref) ? $ref : $default; 
    2944        } 
    3045