Vous êtes ici Codes PHP et MySQL > Classes > Class INIT

 

Class INIT

La class INIT permet d'initialisé tout site Web. Il sécurise les données envoyées par l’utilisateur (GET, POST, FILE etc.). Défini des constantes concernant le site Internet et bien d’autres. Ce script sera en évolution souvent…
 
Eric Potvin
Site de l'auteur voir
[4] sources en PHP voir
Code vu 8944 fois
Enregistré le 26 Sept 2005
  • Digg ce code sur digg.com
  • Bookmark ce code sur del.icio.us
  • Bookmark ce code sur Google
  • Bookmark ce code sur Yahoo
  • Ajoute Class INIT
  • Partage ce code sur Facebook
 
 
 
 

Code Source


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.
 
<?php
/******************************************************************************/
/*                                                                            */
/*                       __        ____                                       */
/*                 ___  / /  ___  / __/__  __ _____________ ___               */
/*                / _ \/ _ \/ _ \_\ \/ _ \/ // / __/ __/ -_|_-<               */
/*               / .__/_//_/ .__/___/\___/\_,_/_/  \__/\__/___/               */
/*              /_/       /_/                                                 */
/*                                                                            */
/*                                                                            */
/******************************************************************************/
/*                                                                            */
/* Titre          : Class INIT                                                */
/*                                                                            */
/* URL            : http://www.phpsources.org/scripts141-PHP.htm              */
/* Auteur         : Eric Potvin                                               */
/* Date édition   : 26 Sept 2005                                              */
/* Website auteur : http://wwww.zendphp.com                                   */
/*                                                                            */
/******************************************************************************/

  error_reporting(0);  
  set_magic_quotes_runtime(false);
  set_time_limit(10);
  
    header("Cache-Control: no-cache, must-revalidate");

  //define your constant here
  define('OS'strtoupper(substr(PHP_OS,0,3)) == 'WIN' 'WIN' 'LINUX');
  define('PATH','/url/to/path/');

  define('IMGS_PATH','imgs/');
  define('TEMPLATE_PATH','template/');
  define('LIB_PATH','libs/');

class init {  
  var $envVariables =   array();
  
  function init() {
    headers_sent() ? die('FATAL ERROR') : '';
    $this->envVariables['get'] = init::parseVar($_GET);
    $this->envVariables['post'] = init::parseVar($_POST);
    $this->envVariables['cookie'] = init::parseVar($_COOKIE);
    
    unset($GLOBALS['HTTP_GET_VARS'],$GLOBALS['_GET']);
    unset($GLOBALS['HTTP_POST_VARS'],$GLOBALS['_POST']);
    unset($GLOBALS['HTTP_COOKIE_VARS'],$GLOBALS['_COOKIE']);
    unset($GLOBALS['HTTP_SERVER_VARS'],$GLOBALS['_SERVER']);
    unset($GLOBALS['HTTP_ENV_VARS'],$GLOBALS['_ENV']);
    unset($GLOBALS['HTTP_POST_FILES'],$GLOBALS['_FILES']);
    unset($GLOBALS['_REQUEST']);
    register_shutdown_function( array( &$this"_init" ) );
  }
  
  function _init() {
    unset($this->envVariables);
    $this->envVariables = array();
  }
  
  function parseVar($varName) {
    foreach ($varName as $key => $val) {
      $val = !get_magic_quotes_gpc() ? addslashes($val) :  $val;
      $varName[$key] = $val;
    }    
    return $varName;
  }
  
  function getEnvVariable($envName ''$varName ''$default NULL) {
    if(isset($this->envVariables[$envName])) {
      if(isset($this->envVariables[$envName][$varName])) {
        return $this->envVariables[$envName][$varName];
      }
      elseif(empty($varName)) {
        return $this->envVariables[$envName];
      }
    }
  }
  
  function isCallable($filename '') {
    return file_exists($filename) && is_readable($filename);
  }
  
}  

//Example of CODE

  $_obj_INIT = new init();

  echo $_obj_INIT->getEnvVariable('get','pge');
  
  if($_obj_INIT->isCallable(PATH.'file.php')) {
    require_once(PATH.'file.php');
  }
  
?>

 

Fonctions du code

: Fixe le niveau de rapport d'erreurs PHP - (PHP 4, PHP 5)
: Active/désactive l'option magic_quotes_runtime - (PHP 4, PHP 5)
: Fixe le temps maximum d'exécution d'un script - (PHP 4, PHP 5)
: Envoie un en-tête HTTP - (PHP 4, PHP 5)
: Définit une constante - (PHP 4, PHP 5)
: Renvoie une chaîne en majuscules - (PHP 4, PHP 5)
: Retourne un segment de chaîne - (PHP 4, PHP 5)
: Crée un tableau - (PHP 4, PHP 5)
: Alias de la fonction exit() - (PHP 4, PHP 5)
: Indique si les en-têtes HTTP ont déjà été envoyés - (PHP 4, PHP 5)
: Détruit une variable - (PHP 4, PHP 5)
: Enregistre une fonction pour exécution à l'extinction - (PHP 4, PHP 5)
: Ajoute des antislashs dans une chaîne - (PHP 4, PHP 5)
: Retourne la configuration actuelle de l'option magic_quotes_gpc - (PHP 4, PHP 5)
: Détermine si une variable est affectée - (PHP 4, PHP 5)
: Détermine si une variable contient une valeur non nulle - (PHP 4, PHP 5)
: Vérifie si un fichier ou un dossier existe - (PHP 4, PHP 5)
: Indique si un fichier est accessible en lecture - (PHP 4, PHP 5)
: Affiche une chaîne de caractères - (PHP 4, PHP 5)
Ajouter un commentaire
Code de sécurité

Attention: Les champs marqués d'une étoile * sont obligatoires
 
Librairie PHP

Connexion

 
 

Classes

 
 

PHP

 
 
 
 
    Offres d'emploi

Plus de 500 offres d'emploi PHP/MySQL

Offres d'emploi
 
    Editeur PHP
 
        Publicité