Affiche l'entete HTTP

  Information

Vous voulez connaitre le contenu de votre entête ? Voici une classe qui devrait vous y aider.

  code source classé dans  Classes

 
 01    
 02    
 03    
 04    
 05    
 06    
 07    
 08    
 09    
 10    
 11    
 12    
 13    
 14    
 15    
 16    
 17    
 18    
 19    
 20    
 21    
 22    
 23    
 24    
 25    
 26    
 27    
 28    
 29    
 30    
 31    
 32    
 33    
 34    
 35    
 36    
 37    
 38    
 39    
 40    
 41    
 42    
 43    
 44    
 45    
 46    
 47    
 48    
 49    
 50    
 51    
 52    
 53    
 54    
 55    
 56    
 57    
 58    
 59    
 60    
 61    
 62    
 63    
 64    
 65    
 66    
 67    
 68    
 69    
 70    
 71    
 72    
 73    
 74    
 75    
 76    
 77    
 78    
 79    
 80    
 81    
 82    
 83    
 84    
 85    
 86    
 87    
 88    
 89    
 90    
 91    
 92    
 93    
 94    
 95    
 96    
 97    
 98    
 99    
 100    
 101    
 102    
 103    
 104    
 105    
 106    
 107    
 108    
 109    
 110    
 111    
 112    
 113    
 114    
 115    
 116    
 117    
                               
<?php
/*---------------------------------------------------------------*/
/*
    Titre : Affiche l'entete HTTP                                                                                         
                                                                                                                          
    URL   : https://phpsources.net/code_s.php?id=341
    Auteur           : marco12                                                                                            
    Date édition     : 17 Fév 2008                                                                                        
    Date mise à jour : 09 Oct 2019                                                                                       
    Rapport de la maj:                                                                                                    
    - fonctionnement du code vérifié                                                                                    
*/
/*---------------------------------------------------------------*/?>
 <?php

      /**
      * Access the HTTP Request
      */
      class http_request {
      
/** additional HTTP headers not prefixed with HTTP_ in $_SERVER superglobal */
      var $add_headers array('CONTENT_TYPE''CONTENT_LENGTH');
      /**
      * Construtor
      * Retrieve HTTP Body
      * @param Array Additional Headers to retrieve
      */
      function http_request($add_headers false) {
       
      $this->retrieve_headers($add_headers);
      $this->body = @file_get_contents('php://input');
      }
      /**
      * Retrieve the HTTP request headers from the $_SERVER superglobal
      * @param Array Additional Headers to retrieve
      */
      function retrieve_headers($add_headers false) {
       
      if ($add_headers) {
      $this->add_headers array_merge($this->add_headers$add_headers);
      }
       
      if (isset($_SERVER['HTTP_METHOD'])) {
      $this->method $_SERVER['HTTP_METHOD'];
      unset($_SERVER['HTTP_METHOD']);
      }
      else {
$this->method=isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 
false;
      }
$this->protocol=isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL']
:false;
$this->request_method=isset($_SERVER['REQUEST_METHOD']) ? $_SERVER[
'REQUEST_METHOD']:false;
       
      $this->headers array();
      foreach($_SERVER as $i=>$val) {
      if (strpos($i'HTTP_') === || in_array($i$this->add_headers)) {
      $name str_replace(array('HTTP_''_'), array('''-'), $i);
      $this->headers[$name] = $val;
      }
      }
      }
      /**
      * Retrieve HTTP Method
      */
      function method() {
      return $this->method;
      }
       
      /**
      * Retrieve HTTP Body
      */
      function body() {
      return $this->body;
      }
       
      /**
      * Retrieve an HTTP Header
      * @param string Case-Insensitive HTTP Header Name (eg: "User-Agent")
      */
      function header($name) {
      $name strtoupper($name);
      return isset($this->headers[$name]) ? $this->headers[$name] : false;
      }
      /**
      * Retrieve all HTTP Headers
      * @return array HTTP Headers
      */
      function headers() {
      return $this->headers;
      }
       
      /**
      * Return Raw HTTP Request (note: This is incomplete)
      * @param bool ReBuild the Raw HTTP Request
      */
      function raw($refresh false) {
       
      if (isset($this->raw) && !$refresh) {
      return $this->raw// return cached
      }
       
      $headers $this->headers();
      $this->raw "{$this->method}\r\n";
       
      foreach($headers as $i=>$header) {
      $this->raw .= "$i$header\r\n";
      }
       
      $this->raw .= "\r\n{$http_request->body}";
      return $this->raw;
      }
      }
?>

Exemple :

 
 01    
 02    
 03    
 04    
 05    
 06    
 07    
 08    
 09    
                                
<?php

      $http_request = new http_request();
       
      $resp $http_request->raw();
      echo nl2br($resp);
?>

          Fonctions du code - Doc officielle PHP

   php.net   Description Versions PHP OUTIL
   array Crée un tableau PHP 4, PHP 5, PHP 7, PHP 8
   array_merge Fusionne un ou plusieurs tableaux PHP 4, PHP 5, PHP 7, PHP 8
   echo Affiche une chaîne de caractères PHP 4, PHP 5, PHP 7, PHP 8
   file_get_contents Lit tout un fichier dans une chaîne - (PHP 4 >= 4.3.0, PHP 5, PHP 7) PHP 4, PHP 5, PHP 7, PHP 8
   http_request Effectue une requête personnalisée - (PECL pecl_http:1.0.0-1.5.5) PHP 5, PHP 7, PHP 8
   in_array Indique si une valeur appartient à un tableau PHP 4, PHP 5, PHP 7, PHP 8
   isset Détermine si une variable est affectée PHP 4, PHP 5, PHP 7, PHP 8
   nl2br Insère un retour à la ligne HTML à chaque nouvelle ligne PHP 4, PHP 5, PHP 7, PHP 8
   return Retourne le controle du programme au module appelant. PHP 4, PHP 5, PHP 7, PHP 8
   strpos Trouve la position d'un caractère dans une chaîne PHP 4, PHP 5, PHP 7, PHP 8
   strtoupper Renvoie une chaîne en majuscules PHP 4, PHP 5, PHP 7, PHP 8
   str_replace Remplace toutes les occurrences dans une chaîne PHP 4, PHP 5, PHP 7, PHP 8
   unset Détruit une variable PHP 4, PHP 5, PHP 7, PHP 8

   Dites merci aux auteurs pour leurs travail, ça ne coûte rien et ça fait toujours plaisir wink

Présentation de PHP

PHP débutant et initié 50 Tutoriel

Présentation de MySQL

avatar

Marco12

  17 Fév 2008

  SOURCE   Télécharger

Information sur les mises à jour

Dernière mise à jour :

    09 Oct 2019
    fonctionnement du code vérifié

9 562 Vues
Compatibilité
PHP 5, 7 et 8+