1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
redirect.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\Engine\Response;
4
5use Bitrix\Main;
6use Bitrix\Main\Context;
7use Bitrix\Main\Web\Uri;
8
10{
12 private $url;
14 private $skipSecurity;
15
16 public function __construct($url, bool $skipSecurity = false)
17 {
18 parent::__construct();
19
20 $this
21 ->setStatus('302 Found')
22 ->setSkipSecurity($skipSecurity)
23 ->setUrl($url)
24 ;
25 }
26
30 public function getUrl()
31 {
32 return $this->url;
33 }
34
39 public function setUrl($url)
40 {
41 $this->url = (string)$url;
42
43 return $this;
44 }
45
49 public function isSkippedSecurity(): bool
50 {
51 return $this->skipSecurity;
52 }
53
58 public function setSkipSecurity(bool $skipSecurity)
59 {
60 $this->skipSecurity = $skipSecurity;
61
62 return $this;
63 }
64
65 private function checkTrial(): bool
66 {
67 $isTrial =
68 defined("DEMO") && DEMO === "Y" &&
69 (
70 !defined("SITEEXPIREDATE") ||
71 !defined("OLDSITEEXPIREDATE") ||
72 SITEEXPIREDATE == '' ||
73 SITEEXPIREDATE != OLDSITEEXPIREDATE
74 )
75 ;
76
77 return $isTrial;
78 }
79
80 private function isExternalUrl($url): bool
81 {
82 return preg_match("'^(http://|https://|ftp://)'i", $url);
83 }
84
85 private function modifyBySecurity($url)
86 {
88 global $APPLICATION;
89
90 $isExternal = $this->isExternalUrl($url);
91 if (!$isExternal && !str_starts_with($url, "/"))
92 {
93 $url = $APPLICATION->GetCurDir() . $url;
94 }
95 if ($isExternal)
96 {
97 // normalizes user info part of the url
98 $url = (string)(new Uri($this->url));
99 }
100 //doubtful about &amp; and http response splitting defence
101 $url = str_replace(["&amp;", "\r", "\n"], ["&", "", ""], $url);
102
103 return $url;
104 }
105
106 private function processInternalUrl($url)
107 {
109 global $APPLICATION;
110 //store cookies for next hit (see CMain::GetSpreadCookieHTML())
111 $APPLICATION->StoreCookies();
112
113 $server = Context::getCurrent()->getServer();
114 $protocol = Context::getCurrent()->getRequest()->isHttps() ? "https" : "http";
115 $host = $server->getHttpHost();
116 $port = (int)$server->getServerPort();
117 if ($port !== 80 && $port !== 443 && $port > 0 && !str_contains($host, ":"))
118 {
119 $host .= ":" . $port;
120 }
121
122 return "{$protocol}://{$host}{$url}";
123 }
124
125 public function send()
126 {
127 if ($this->checkTrial())
128 {
129 die(Main\Localization\Loc::getMessage('MAIN_ENGINE_REDIRECT_TRIAL_EXPIRED'));
130 }
131
132 $url = $this->getUrl();
133 $isExternal = $this->isExternalUrl($url);
134 $url = $this->modifyBySecurity($url);
135
136
137 foreach (GetModuleEvents("main", "OnBeforeLocalRedirect", true) as $event)
138 {
139 ExecuteModuleEventEx($event, [&$url, $this->isSkippedSecurity(), &$isExternal, $this]);
140 }
141
142 if (!$isExternal)
143 {
144 $url = $this->processInternalUrl($url);
145 }
146
147 $this->addHeader('Location', $url);
148 foreach (GetModuleEvents("main", "OnLocalRedirect", true) as $event)
149 {
151 }
152
153 Main\Application::getInstance()->getKernelSession()["BX_REDIRECT_TIME"] = time();
154
155 parent::send();
156 }
157}
global $APPLICATION
Определения include.php:80
static getInstance()
Определения application.php:98
setSkipSecurity(bool $skipSecurity)
Определения redirect.php:58
__construct($url, bool $skipSecurity=false)
Определения redirect.php:16
addHeader($name, $value='')
Определения httpresponse.php:72
$protocol
Определения .description.php:9
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
Определения tools.php:5177
$host
Определения mysql_to_pgsql.php:32
$event
Определения prolog_after.php:141
die
Определения quickway.php:367
$url
Определения iframe.php:7