Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
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
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\HttpKernel;
013
014 /**
015 * Signs URIs.
016 *
017 * @author Fabien Potencier <fabien@symfony.com>
018 */
019 class UriSigner
020 {
021 private $secret;
022
023 /**
024 * Constructor.
025 *
026 * @param string $secret A secret
027 */
028 public function __construct($secret)
029 {
030 $this->secret = $secret;
031 }
032
033 /**
034 * Signs a URI.
035 *
036 * The given URI is signed by adding a _hash query string parameter
037 * which value depends on the URI and the secret.
038 *
039 * @param string $uri A URI to sign
040 *
041 * @return string The signed URI
042 */
043 public function sign($uri)
044 {
045 $url = parse_url($uri);
046 if (isset($url['query'])) {
047 parse_str($url['query'], $params);
048 } else {
049 $params = array();
050 }
051
052 $uri = $this->buildUrl($url, $params);
053
054 return $uri.(false === strpos($uri, '?') ? '?' : '&').'_hash='.$this->computeHash($uri);
055 }
056
057 /**
058 * Checks that a URI contains the correct hash.
059 *
060 * The _hash query string parameter must be the last one
061 * (as it is generated that way by the sign() method, it should
062 * never be a problem).
063 *
064 * @param string $uri A signed URI
065 *
066 * @return bool True if the URI is signed correctly, false otherwise
067 */
068 public function check($uri)
069 {
070 $url = parse_url($uri);
071 if (isset($url['query'])) {
072 parse_str($url['query'], $params);
073 } else {
074 $params = array();
075 }
076
077 if (empty($params['_hash'])) {
078 return false;
079 }
080
081 $hash = urlencode($params['_hash']);
082 unset($params['_hash']);
083
084 return $this->computeHash($this->buildUrl($url, $params)) === $hash;
085 }
086
087 private function computeHash($uri)
088 {
089 return urlencode(base64_encode(hash_hmac('sha256', $uri, $this->secret, true)));
090 }
091
092 private function buildUrl(array $url, array $params = array())
093 {
094 ksort($params, SORT_STRING);
095 $url['query'] = http_build_query($params, '', '&');
096
097 $scheme = isset($url['scheme']) ? $url['scheme'].'://' : '';
098 $host = isset($url['host']) ? $url['host'] : '';
099 $port = isset($url['port']) ? ':'.$url['port'] : '';
100 $user = isset($url['user']) ? $url['user'] : '';
101 $pass = isset($url['pass']) ? ':'.$url['pass'] : '';
102 $pass = ($user || $pass) ? "$pass@" : '';
103 $path = isset($url['path']) ? $url['path'] : '';
104 $query = isset($url['query']) && $url['query'] ? '?'.$url['query'] : '';
105 $fragment = isset($url['fragment']) ? '#'.$url['fragment'] : '';
106
107 return $scheme.$user.$pass.$host.$port.$path.$query.$fragment;
108 }
109 }
110