error_exception.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. <?php
  2. use CodeIgniter\HTTP\Header;
  3. use CodeIgniter\CodeIgniter;
  4. $errorId = uniqid('error', true);
  5. ?>
  6. <!doctype html>
  7. <html>
  8. <head>
  9. <meta charset="UTF-8">
  10. <meta name="robots" content="noindex">
  11. <title><?= esc($title) ?></title>
  12. <style>
  13. <?= preg_replace('#[\r\n\t ]+#', ' ', file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'debug.css')) ?>
  14. </style>
  15. <script>
  16. <?= file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'debug.js') ?>
  17. </script>
  18. </head>
  19. <body onload="init()">
  20. <!-- Header -->
  21. <div class="header">
  22. <div class="environment">
  23. Displayed at <?= esc(date('H:i:s')) ?> &mdash;
  24. PHP: <?= esc(PHP_VERSION) ?> &mdash;
  25. CodeIgniter: <?= esc(CodeIgniter::CI_VERSION) ?> --
  26. Environment: <?= ENVIRONMENT ?>
  27. </div>
  28. <div class="container">
  29. <h1><?= esc($title), esc($exception->getCode() ? ' #' . $exception->getCode() : '') ?></h1>
  30. <p>
  31. <?= nl2br(esc($exception->getMessage())) ?>
  32. <a href="https://www.duckduckgo.com/?q=<?= urlencode($title . ' ' . preg_replace('#\'.*\'|".*"#Us', '', $exception->getMessage())) ?>"
  33. rel="noreferrer" target="_blank">search &rarr;</a>
  34. </p>
  35. </div>
  36. </div>
  37. <!-- Source -->
  38. <div class="container">
  39. <p><b><?= esc(clean_path($file)) ?></b> at line <b><?= esc($line) ?></b></p>
  40. <?php if (is_file($file)) : ?>
  41. <div class="source">
  42. <?= static::highlightFile($file, $line, 15); ?>
  43. </div>
  44. <?php endif; ?>
  45. </div>
  46. <div class="container">
  47. <?php
  48. $last = $exception;
  49. while ($prevException = $last->getPrevious()) {
  50. $last = $prevException;
  51. ?>
  52. <pre>
  53. Caused by:
  54. <?= esc($prevException::class), esc($prevException->getCode() ? ' #' . $prevException->getCode() : '') ?>
  55. <?= nl2br(esc($prevException->getMessage())) ?>
  56. <a href="https://www.duckduckgo.com/?q=<?= urlencode($prevException::class . ' ' . preg_replace('#\'.*\'|".*"#Us', '', $prevException->getMessage())) ?>"
  57. rel="noreferrer" target="_blank">search &rarr;</a>
  58. <?= esc(clean_path($prevException->getFile()) . ':' . $prevException->getLine()) ?>
  59. </pre>
  60. <?php
  61. }
  62. ?>
  63. </div>
  64. <?php if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE) : ?>
  65. <div class="container">
  66. <ul class="tabs" id="tabs">
  67. <li><a href="#backtrace">Backtrace</a></li>
  68. <li><a href="#server">Server</a></li>
  69. <li><a href="#request">Request</a></li>
  70. <li><a href="#response">Response</a></li>
  71. <li><a href="#files">Files</a></li>
  72. <li><a href="#memory">Memory</a></li>
  73. </ul>
  74. <div class="tab-content">
  75. <!-- Backtrace -->
  76. <div class="content" id="backtrace">
  77. <ol class="trace">
  78. <?php foreach ($trace as $index => $row) : ?>
  79. <li>
  80. <p>
  81. <!-- Trace info -->
  82. <?php if (isset($row['file']) && is_file($row['file'])) : ?>
  83. <?php
  84. if (isset($row['function']) && in_array($row['function'], ['include', 'include_once', 'require', 'require_once'], true)) {
  85. echo esc($row['function'] . ' ' . clean_path($row['file']));
  86. } else {
  87. echo esc(clean_path($row['file']) . ' : ' . $row['line']);
  88. }
  89. ?>
  90. <?php else: ?>
  91. {PHP internal code}
  92. <?php endif; ?>
  93. <!-- Class/Method -->
  94. <?php if (isset($row['class'])) : ?>
  95. &nbsp;&nbsp;&mdash;&nbsp;&nbsp;<?= esc($row['class'] . $row['type'] . $row['function']) ?>
  96. <?php if (! empty($row['args'])) : ?>
  97. <?php $argsId = $errorId . 'args' . $index ?>
  98. ( <a href="#" onclick="return toggle('<?= esc($argsId, 'attr') ?>');">arguments</a> )
  99. <div class="args" id="<?= esc($argsId, 'attr') ?>">
  100. <table cellspacing="0">
  101. <?php
  102. $params = null;
  103. // Reflection by name is not available for closure function
  104. if (! str_ends_with($row['function'], '}')) {
  105. $mirror = isset($row['class']) ? new ReflectionMethod($row['class'], $row['function']) : new ReflectionFunction($row['function']);
  106. $params = $mirror->getParameters();
  107. }
  108. foreach ($row['args'] as $key => $value) : ?>
  109. <tr>
  110. <td><code><?= esc(isset($params[$key]) ? '$' . $params[$key]->name : "#{$key}") ?></code></td>
  111. <td><pre><?= esc(print_r($value, true)) ?></pre></td>
  112. </tr>
  113. <?php endforeach ?>
  114. </table>
  115. </div>
  116. <?php else : ?>
  117. ()
  118. <?php endif; ?>
  119. <?php endif; ?>
  120. <?php if (! isset($row['class']) && isset($row['function'])) : ?>
  121. &nbsp;&nbsp;&mdash;&nbsp;&nbsp; <?= esc($row['function']) ?>()
  122. <?php endif; ?>
  123. </p>
  124. <!-- Source? -->
  125. <?php if (isset($row['file']) && is_file($row['file']) && isset($row['class'])) : ?>
  126. <div class="source">
  127. <?= static::highlightFile($row['file'], $row['line']) ?>
  128. </div>
  129. <?php endif; ?>
  130. </li>
  131. <?php endforeach; ?>
  132. </ol>
  133. </div>
  134. <!-- Server -->
  135. <div class="content" id="server">
  136. <?php foreach (['_SERVER', '_SESSION'] as $var) : ?>
  137. <?php
  138. if (empty($GLOBALS[$var]) || ! is_array($GLOBALS[$var])) {
  139. continue;
  140. } ?>
  141. <h3>$<?= esc($var) ?></h3>
  142. <table>
  143. <thead>
  144. <tr>
  145. <th>Key</th>
  146. <th>Value</th>
  147. </tr>
  148. </thead>
  149. <tbody>
  150. <?php foreach ($GLOBALS[$var] as $key => $value) : ?>
  151. <tr>
  152. <td><?= esc($key) ?></td>
  153. <td>
  154. <?php if (is_string($value)) : ?>
  155. <?= esc($value) ?>
  156. <?php else: ?>
  157. <pre><?= esc(print_r($value, true)) ?></pre>
  158. <?php endif; ?>
  159. </td>
  160. </tr>
  161. <?php endforeach; ?>
  162. </tbody>
  163. </table>
  164. <?php endforeach ?>
  165. <!-- Constants -->
  166. <?php $constants = get_defined_constants(true); ?>
  167. <?php if (! empty($constants['user'])) : ?>
  168. <h3>Constants</h3>
  169. <table>
  170. <thead>
  171. <tr>
  172. <th>Key</th>
  173. <th>Value</th>
  174. </tr>
  175. </thead>
  176. <tbody>
  177. <?php foreach ($constants['user'] as $key => $value) : ?>
  178. <tr>
  179. <td><?= esc($key) ?></td>
  180. <td>
  181. <?php if (is_string($value)) : ?>
  182. <?= esc($value) ?>
  183. <?php else: ?>
  184. <pre><?= esc(print_r($value, true)) ?></pre>
  185. <?php endif; ?>
  186. </td>
  187. </tr>
  188. <?php endforeach; ?>
  189. </tbody>
  190. </table>
  191. <?php endif; ?>
  192. </div>
  193. <!-- Request -->
  194. <div class="content" id="request">
  195. <?php $request = service('request'); ?>
  196. <table>
  197. <tbody>
  198. <tr>
  199. <td style="width: 10em">Path</td>
  200. <td><?= esc($request->getUri()) ?></td>
  201. </tr>
  202. <tr>
  203. <td>HTTP Method</td>
  204. <td><?= esc($request->getMethod()) ?></td>
  205. </tr>
  206. <tr>
  207. <td>IP Address</td>
  208. <td><?= esc($request->getIPAddress()) ?></td>
  209. </tr>
  210. <tr>
  211. <td style="width: 10em">Is AJAX Request?</td>
  212. <td><?= $request->isAJAX() ? 'yes' : 'no' ?></td>
  213. </tr>
  214. <tr>
  215. <td>Is CLI Request?</td>
  216. <td><?= $request->isCLI() ? 'yes' : 'no' ?></td>
  217. </tr>
  218. <tr>
  219. <td>Is Secure Request?</td>
  220. <td><?= $request->isSecure() ? 'yes' : 'no' ?></td>
  221. </tr>
  222. <tr>
  223. <td>User Agent</td>
  224. <td><?= esc($request->getUserAgent()->getAgentString()) ?></td>
  225. </tr>
  226. </tbody>
  227. </table>
  228. <?php $empty = true; ?>
  229. <?php foreach (['_GET', '_POST', '_COOKIE'] as $var) : ?>
  230. <?php
  231. if (empty($GLOBALS[$var]) || ! is_array($GLOBALS[$var])) {
  232. continue;
  233. } ?>
  234. <?php $empty = false; ?>
  235. <h3>$<?= esc($var) ?></h3>
  236. <table style="width: 100%">
  237. <thead>
  238. <tr>
  239. <th>Key</th>
  240. <th>Value</th>
  241. </tr>
  242. </thead>
  243. <tbody>
  244. <?php foreach ($GLOBALS[$var] as $key => $value) : ?>
  245. <tr>
  246. <td><?= esc($key) ?></td>
  247. <td>
  248. <?php if (is_string($value)) : ?>
  249. <?= esc($value) ?>
  250. <?php else: ?>
  251. <pre><?= esc(print_r($value, true)) ?></pre>
  252. <?php endif; ?>
  253. </td>
  254. </tr>
  255. <?php endforeach; ?>
  256. </tbody>
  257. </table>
  258. <?php endforeach ?>
  259. <?php if ($empty) : ?>
  260. <div class="alert">
  261. No $_GET, $_POST, or $_COOKIE Information to show.
  262. </div>
  263. <?php endif; ?>
  264. <?php $headers = $request->headers(); ?>
  265. <?php if (! empty($headers)) : ?>
  266. <h3>Headers</h3>
  267. <table>
  268. <thead>
  269. <tr>
  270. <th>Header</th>
  271. <th>Value</th>
  272. </tr>
  273. </thead>
  274. <tbody>
  275. <?php foreach ($headers as $name => $value) : ?>
  276. <tr>
  277. <td><?= esc($name, 'html') ?></td>
  278. <td>
  279. <?php
  280. if ($value instanceof Header) {
  281. echo esc($value->getValueLine(), 'html');
  282. } else {
  283. foreach ($value as $i => $header) {
  284. echo ' ('. $i+1 . ') ' . esc($header->getValueLine(), 'html');
  285. }
  286. }
  287. ?>
  288. </td>
  289. </tr>
  290. <?php endforeach; ?>
  291. </tbody>
  292. </table>
  293. <?php endif; ?>
  294. </div>
  295. <!-- Response -->
  296. <?php
  297. $response = service('response');
  298. $response->setStatusCode(http_response_code());
  299. ?>
  300. <div class="content" id="response">
  301. <table>
  302. <tr>
  303. <td style="width: 15em">Response Status</td>
  304. <td><?= esc($response->getStatusCode() . ' - ' . $response->getReasonPhrase()) ?></td>
  305. </tr>
  306. </table>
  307. <?php $headers = $response->headers(); ?>
  308. <?php if (! empty($headers)) : ?>
  309. <h3>Headers</h3>
  310. <table>
  311. <thead>
  312. <tr>
  313. <th>Header</th>
  314. <th>Value</th>
  315. </tr>
  316. </thead>
  317. <tbody>
  318. <?php foreach ($headers as $name => $value) : ?>
  319. <tr>
  320. <td><?= esc($name, 'html') ?></td>
  321. <td>
  322. <?php
  323. if ($value instanceof Header) {
  324. echo esc($response->getHeaderLine($name), 'html');
  325. } else {
  326. foreach ($value as $i => $header) {
  327. echo ' ('. $i+1 . ') ' . esc($header->getValueLine(), 'html');
  328. }
  329. }
  330. ?>
  331. </td>
  332. </tr>
  333. <?php endforeach; ?>
  334. </tbody>
  335. </table>
  336. <?php endif; ?>
  337. </div>
  338. <!-- Files -->
  339. <div class="content" id="files">
  340. <?php $files = get_included_files(); ?>
  341. <ol>
  342. <?php foreach ($files as $file) :?>
  343. <li><?= esc(clean_path($file)) ?></li>
  344. <?php endforeach ?>
  345. </ol>
  346. </div>
  347. <!-- Memory -->
  348. <div class="content" id="memory">
  349. <table>
  350. <tbody>
  351. <tr>
  352. <td>Memory Usage</td>
  353. <td><?= esc(static::describeMemory(memory_get_usage(true))) ?></td>
  354. </tr>
  355. <tr>
  356. <td style="width: 12em">Peak Memory Usage:</td>
  357. <td><?= esc(static::describeMemory(memory_get_peak_usage(true))) ?></td>
  358. </tr>
  359. <tr>
  360. <td>Memory Limit:</td>
  361. <td><?= esc(ini_get('memory_limit')) ?></td>
  362. </tr>
  363. </tbody>
  364. </table>
  365. </div>
  366. </div> <!-- /tab-content -->
  367. </div> <!-- /container -->
  368. <?php endif; ?>
  369. </body>
  370. </html>