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 |
SocketPost.php
001 <?php
002 /**
003 * This is a PHP library that handles calling reCAPTCHA.
004 *
005 * @copyright Copyright (c) 2015, Google Inc.
006 * @link http://www.google.com/recaptcha
007 *
008 * Permission is hereby granted, free of charge, to any person obtaining a copy
009 * of this software and associated documentation files (the "Software"), to deal
010 * in the Software without restriction, including without limitation the rights
011 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
012 * copies of the Software, and to permit persons to whom the Software is
013 * furnished to do so, subject to the following conditions:
014 *
015 * The above copyright notice and this permission notice shall be included in
016 * all copies or substantial portions of the Software.
017 *
018 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
019 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
020 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
021 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
022 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
023 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
024 * THE SOFTWARE.
025 */
026
027 namespace ReCaptcha\RequestMethod;
028
029 use ReCaptcha\RequestMethod;
030 use ReCaptcha\RequestParameters;
031
032 /**
033 * Sends a POST request to the reCAPTCHA service, but makes use of fsockopen()
034 * instead of get_file_contents(). This is to account for people who may be on
035 * servers where allow_furl_open is disabled.
036 */
037 class SocketPost implements RequestMethod
038 {
039 /**
040 * reCAPTCHA service host.
041 * @const string
042 */
043 const RECAPTCHA_HOST = 'www.google.com';
044
045 /**
046 * @const string reCAPTCHA service path
047 */
048 const SITE_VERIFY_PATH = '/recaptcha/api/siteverify';
049
050 /**
051 * @const string Bad request error
052 */
053 const BAD_REQUEST = '{"success": false, "error-codes": ["invalid-request"]}';
054
055 /**
056 * @const string Bad response error
057 */
058 const BAD_RESPONSE = '{"success": false, "error-codes": ["invalid-response"]}';
059
060 /**
061 * Socket to the reCAPTCHA service
062 * @var Socket
063 */
064 private $socket;
065
066 /**
067 * Constructor
068 *
069 * @param \ReCaptcha\RequestMethod\Socket $socket optional socket, injectable for testing
070 */
071 public function __construct(Socket $socket = null)
072 {
073 if (!is_null($socket)) {
074 $this->socket = $socket;
075 } else {
076 $this->socket = new Socket();
077 }
078 }
079
080 /**
081 * Submit the POST request with the specified parameters.
082 *
083 * @param RequestParameters $params Request parameters
084 * @return string Body of the reCAPTCHA response
085 */
086 public function submit(RequestParameters $params)
087 {
088 $errno = 0;
089 $errstr = '';
090
091 if (false === $this->socket->fsockopen('ssl://' . self::RECAPTCHA_HOST, 443, $errno, $errstr, 30)) {
092 return self::BAD_REQUEST;
093 }
094
095 $content = $params->toQueryString();
096
097 $request = "POST " . self::SITE_VERIFY_PATH . " HTTP/1.1\r\n";
098 $request .= "Host: " . self::RECAPTCHA_HOST . "\r\n";
099 $request .= "Content-Type: application/x-www-form-urlencoded\r\n";
100 $request .= "Content-length: " . strlen($content) . "\r\n";
101 $request .= "Connection: close\r\n\r\n";
102 $request .= $content . "\r\n\r\n";
103
104 $this->socket->fwrite($request);
105 $response = '';
106
107 while (!$this->socket->feof()) {
108 $response .= $this->socket->fgets(4096);
109 }
110
111 $this->socket->fclose();
112
113 if (0 !== strpos($response, 'HTTP/1.1 200 OK')) {
114 return self::BAD_RESPONSE;
115 }
116
117 $parts = preg_split("#\n\s*\n#Uis", $response);
118
119 return $parts[1];
120 }
121 }
122