Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
UriSigner.php
01 <?php
02
03 /*
04 * This file is part of the Symfony package.
05 *
06 * (c) Fabien Potencier <fabien@symfony.com>
07 *
08 * For the full copyright and license information, please view the LICENSE
09 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\HttpKernel;
13
14 /**
15 * Signs URIs.
16 *
17 * @author Fabien Potencier <fabien@symfony.com>
18 */
19 class UriSigner
20 {
21 private $secret;
22
23 /**
24 * Constructor.
25 *
26 * @param string $secret A secret
27 */
28 public function __construct($secret)
29 {
30 $this->secret = $secret;
31 }
32
33 /**
34 * Signs a URI.
35 *
36 * The given URI is signed by adding a _hash query string parameter
37 * which value depends on the URI and the secret.
38 *
39 * @param string $uri A URI to sign
40 *
41 * @return string The signed URI
42 */
43 public function sign($uri)
44 {
45 return $uri.(false === (strpos($uri, '?')) ? '?' : '&').'_hash='.$this->computeHash($uri);
46 }
47
48 /**
49 * Checks that a URI contains the correct hash.
50 *
51 * The _hash query string parameter must be the last one
52 * (as it is generated that way by the sign() method, it should
53 * never be a problem).
54 *
55 * @param string $uri A signed URI
56 *
57 * @return bool True if the URI is signed correctly, false otherwise
58 */
59 public function check($uri)
60 {
61 if (!preg_match('/^(.*)(?:\?|&)_hash=(.+?)$/', $uri, $matches)) {
62 return false;
63 }
64
65 return $this->computeHash($matches[1]) === $matches[2];
66 }
67
68 private function computeHash($uri)
69 {
70 return urlencode(base64_encode(hash_hmac('sha1', $uri, $this->secret, true)));
71 }
72 }
73