Textpattern | PHP Cross Reference | Content Management Systems |
Description: Log visitors.
1 <?php 2 3 /* 4 * Textpattern Content Management System 5 * https://textpattern.com/ 6 * 7 * Copyright (C) 2020 The Textpattern Development Team 8 * 9 * This file is part of Textpattern. 10 * 11 * Textpattern is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU General Public License 13 * as published by the Free Software Foundation, version 2. 14 * 15 * Textpattern is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with Textpattern. If not, see <https://www.gnu.org/licenses/>. 22 */ 23 24 /** 25 * Log visitors. 26 * 27 * @package Log 28 */ 29 30 /** 31 * Adds a row to the visitor logs. 32 * 33 * This function follows the site's logging preferences. If $logging preference 34 * is set to 'refer', only referrer hits are logged. If $logging is set to 35 * 'none' or '$nolog' global to TRUE, the function will ignore all hits. 36 * 37 * If the $status parameter is set to 404, the hit isn't logged. 38 * 39 * @param int $status HTTP status code 40 * @example 41 * log_hit(200); 42 */ 43 44 function log_hit($status) 45 { 46 global $nolog, $logging; 47 callback_event('log_hit'); 48 49 if (!isset($nolog) && $status != 404) { 50 if ($logging == 'refer') { 51 logit('refer', $status); 52 } elseif ($logging == 'all') { 53 logit('', $status); 54 } 55 } 56 } 57 58 /** 59 * Writes a record to the visitor log using the current visitor's information. 60 * 61 * This function is used by log_hit(). See it before trying to use this one. 62 * 63 * The hit is ignore if $r is set to 'refer' and the HTTP REFERER header 64 * is empty. 65 * 66 * @param string $r Type of record to write, e.g. refer 67 * @param int $status HTTP status code 68 * @access private 69 * @see log_hit() 70 */ 71 72 function logit($r = '', $status = 200) 73 { 74 global $prefs, $pretext; 75 76 if (!isset($pretext['request_uri'])) { 77 return; 78 } 79 80 $protocol = false; 81 $referer = serverSet('HTTP_REFERER'); 82 83 if ($referer) { 84 foreach (do_list(LOG_REFERER_PROTOCOLS) as $option) { 85 if (strpos($referer, $option.'://') === 0) { 86 $protocol = $option; 87 $referer = substr($referer, strlen($protocol) + 3); 88 break; 89 } 90 } 91 92 if (!$protocol || ($protocol === 'https' && PROTOCOL !== 'https://')) { 93 $referer = ''; 94 } elseif (preg_match('/^[^\.]*\.?'.preg_quote(preg_replace('/^www\./', '', SITE_HOST), '/').'/i', $referer)) { 95 $referer = ''; 96 } else { 97 $referer = $protocol.'://'.clean_url($referer); 98 } 99 } 100 101 if ($r == 'refer' && !$referer) { 102 return; 103 } 104 105 insert_logit(array( 106 'uri' => $pretext['request_uri'], 107 'status' => $status, 108 'method' => serverSet('REQUEST_METHOD'), 109 'ref' => $referer, 110 )); 111 } 112 113 /** 114 * Inserts a log record into the database. 115 * 116 * @param array $in Input array consisting 'uri', 'ref', 'status', 'method' 117 * @see log_hit() 118 */ 119 120 function insert_logit($in) 121 { 122 $in = doSlash($in); 123 extract($in); 124 safe_insert( 125 'txp_log', 126 "time = NOW(), page = '$uri', refer = '$ref', status = '$status', method = '$method'" 127 ); 128 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
title