aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/Utils.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/Utils.php')
-rw-r--r--application/Utils.php34
1 files changed, 33 insertions, 1 deletions
diff --git a/application/Utils.php b/application/Utils.php
index a1e97b35..658b97bc 100644
--- a/application/Utils.php
+++ b/application/Utils.php
@@ -84,4 +84,36 @@ function checkDateFormat($format, $string)
84 $date = DateTime::createFromFormat($format, $string); 84 $date = DateTime::createFromFormat($format, $string);
85 return $date && $date->format($string) == $string; 85 return $date && $date->format($string) == $string;
86} 86}
87?> 87
88/**
89 * Generate a header location from HTTP_REFERER.
90 * Make sure the referer is Shaarli itself and prevent redirection loop.
91 *
92 * @param string $referer - HTTP_REFERER.
93 * @param string $host - Server HOST.
94 * @param array $loopTerms - Contains list of term to prevent redirection loop.
95 *
96 * @return string $referer - final referer.
97 */
98function generateLocation($referer, $host, $loopTerms = array())
99{
100 $final_referer = '?';
101
102 // No referer if it contains any value in $loopCriteria.
103 foreach ($loopTerms as $value) {
104 if (strpos($referer, $value) !== false) {
105 return $final_referer;
106 }
107 }
108
109 // Remove port from HTTP_HOST
110 if ($pos = strpos($host, ':')) {
111 $host = substr($host, 0, $pos);
112 }
113
114 if (!empty($referer) && strpos(parse_url($referer, PHP_URL_HOST), $host) !== false) {
115 $final_referer = $referer;
116 }
117
118 return $final_referer;
119}