Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

SocketPost.php

Zuletzt modifiziert: 02.04.2025, 15:04 - Dateigröße: 4.03 KiB


001  <?php
002  /**
003   * This is a PHP library that handles calling reCAPTCHA.
004   *
005   * BSD 3-Clause License
006   * @copyright (c) 2019, Google Inc.
007   * @link https://www.google.com/recaptcha
008   * All rights reserved.
009   *
010   * Redistribution and use in source and binary forms, with or without
011   * modification, are permitted provided that the following conditions are met:
012   * 1. Redistributions of source code must retain the above copyright notice, this
013   *    list of conditions and the following disclaimer.
014   *
015   * 2. Redistributions in binary form must reproduce the above copyright notice,
016   *    this list of conditions and the following disclaimer in the documentation
017   *    and/or other materials provided with the distribution.
018   *
019   * 3. Neither the name of the copyright holder nor the names of its
020   *    contributors may be used to endorse or promote products derived from
021   *    this software without specific prior written permission.
022   *
023   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
024   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
025   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
026   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
027   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
028   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
029   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
030   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
031   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
032   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
033   */
034   
035  namespace ReCaptcha\RequestMethod;
036   
037  use ReCaptcha\ReCaptcha;
038  use ReCaptcha\RequestMethod;
039  use ReCaptcha\RequestParameters;
040   
041  /**
042   * Sends a POST request to the reCAPTCHA service, but makes use of fsockopen()
043   * instead of get_file_contents(). This is to account for people who may be on
044   * servers where allow_url_open is disabled.
045   */
046  class SocketPost implements RequestMethod
047  {
048      /**
049       * Socket to the reCAPTCHA service
050       * @var Socket
051       */
052      private $socket;
053   
054      /**
055       * Only needed if you want to override the defaults
056       *
057       * @param \ReCaptcha\RequestMethod\Socket $socket optional socket, injectable for testing
058       * @param string $siteVerifyUrl URL for reCAPTCHA siteverify API
059       */
060      public function __construct(Socket $socket = null, $siteVerifyUrl = null)
061      {
062          $this->socket = (is_null($socket)) ? new Socket() : $socket;
063          $this->siteVerifyUrl = (is_null($siteVerifyUrl)) ? ReCaptcha::SITE_VERIFY_URL : $siteVerifyUrl;
064      }
065   
066      /**
067       * Submit the POST request with the specified parameters.
068       *
069       * @param RequestParameters $params Request parameters
070       * @return string Body of the reCAPTCHA response
071       */
072      public function submit(RequestParameters $params)
073      {
074          $errno = 0;
075          $errstr = '';
076          $urlParsed = parse_url($this->siteVerifyUrl);
077   
078          if (false === $this->socket->fsockopen('ssl://' . $urlParsed['host'], 443, $errno, $errstr, 30)) {
079              return '{"success": false, "error-codes": ["'.ReCaptcha::E_CONNECTION_FAILED.'"]}';
080          }
081   
082          $content = $params->toQueryString();
083   
084          $request = "POST " . $urlParsed['path'] . " HTTP/1.0\r\n";
085          $request .= "Host: " . $urlParsed['host'] . "\r\n";
086          $request .= "Content-Type: application/x-www-form-urlencoded\r\n";
087          $request .= "Content-length: " . strlen($content) . "\r\n";
088          $request .= "Connection: close\r\n\r\n";
089          $request .= $content . "\r\n\r\n";
090   
091          $this->socket->fwrite($request);
092          $response = '';
093   
094          while (!$this->socket->feof()) {
095              $response .= $this->socket->fgets(4096);
096          }
097   
098          $this->socket->fclose();
099   
100          if (0 !== strpos($response, 'HTTP/1.0 200 OK')) {
101              return '{"success": false, "error-codes": ["'.ReCaptcha::E_BAD_RESPONSE.'"]}';
102          }
103   
104          $parts = preg_split("#\n\s*\n#Uis", $response);
105   
106          return $parts[1];
107      }
108  }
109