Class PHP API SparkAngels
Utilisation
Voici comment utiliser la classe :
$help = new SparkAngels();
$help->openHTML();
$help->setRole();
$help->getRole();
$help->closeHTML();
Codes sources
Voici le code source de la class "SparkAngels" que j'ai créé pour utiliser l'API SparkAngels.
<?php
error_reporting(E_ALL);
/***
Use-it as :
$help = new SparkAngels();
$help->openHTML();
$help->setRole();
$help->getRole();
$help->closeHTML();
***/
/***
Don't Touch this define !!!
***/
define ('Command', 'S');
define ('CrossReference', 'azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN1234567890_');
define ('ENCODING', $_SERVER["HTTP_ACCEPT_ENCODING"]);
define ('HOST', $_SERVER['HTTP_HOST']);
define ('REQUEST', $_SERVER['REQUEST_URI']);
define ('ROOT', $_SERVER['DOCUMENT_ROOT'].'/');
define ('Separator', '-');
define ('URL', 'http://dnld0.sparkom.com/sparkangels/sangels/sparkangels.jnlp?sapi2=');
define ('Version', 2);
define ('WEBAGENT', $_SERVER['HTTP_USER_AGENT']);
class SparkAngels {
public $html='';
private $control=array(); // variable for different control
private $a=array(); // a: code HTML
private $file=array();
private $img=array(); // img : code HTML
private $INI=array(); // define variable ini to session
private $apiUrl=array(); // API URL : URL + Value
private $apiValue=array(); // API Value
private $length= array(); // to define length
private $txt=array(); // to define text in HTML
private $xref=''; // cross reference
function __construct() {
/*** possible to modify value ***/
$this->txt = array (
'title' => "SparkAngels || Page d'entraide",
'a' => array (
'role' => array (
'e' => array (
'title' => 'Accompagné',
'txt' => 'Être accompagné',
),
'r' => array (
'title' => 'Accompagnateur',
'txt' => "Être l'accompagnateur",
),
),
'sparkangels' => array (
'e' => array (
'title' => 'Je lance SparkAngels pour me faire télé-accompagner',
),
'r' => array (
'title' => 'Je lance SparkAngels pour télé-accompagner',
),
),
),
'h1' => 'Accompagnement SparkAngels',
'h2' => array (
'role' => 'Choisissez votre rôle !',
),
'form' => array (
'e' => array (
'legend' => "Choix du service d'accompagnement",
'label4select' => "Choisissez un service :",
'label4option' => 'Service de ',
'label4input' => 'Envoyez : ',
'input2envoy' => 'Envoi !',
),
'r'=> array (
'legend' => "Informations d'authentification à envoyer !",
'p' => 'Votre accompagné a choisi le service suivant : ',
'label4code' => "Code d'authentification de l'accompagné : ",
'label4id' => 'ID : ',
'label4pass' => 'Pass : ',
'label4input' => 'Envoyez : ',
'input2envoy' => 'Envoi !',
),
),
'various' => array (
'charLength' => 'caractères',
'code' => "Code d'authentification : ",
'service' => array (
'c' => 'chat actif',
'p' => "partage interactif de l'écran",
'v' => "simple vision de l'écran",
'cp' => "partage interactif de l'écran avec chat actif",
'cv' => "simple vision de l'écran avec chat actif",
),
'error' => array (
'bad_hash' => "ERREUR : L'algorithme de hashage que vous avez choisi n'est pas supporté !\n<br />Veuillez vous réferer à : http://fr3.php.net/manual/fr/function.hash-algos.php",
'IdPass' => 'Veuillez fournir un ID et Pass correct ... autrement vous ne pourrez utiliser le module accompagnateur !',
'JS' => "ERREUR : La gestion de Javascript est désactivée ... veuillez l'activez !",
'JS_toggle' => 'ATTENTION : Vous n\'allez pas pouvoir être aidé. Vous n\'avez pas de machine Java installée !\nVous allez être redirigé vers le site d\'installation de la machine Java sur Java.com afin d\'installer celle-ci en premier ...\nQuand celle-ci sera installée, revenez sur ',
'not_define' => "ERREUR : Vous n'avez pas définie la variable constante : ",
),
'browser' => array (
'activate' => "Pour l'activer dans votre navigateur, lisez ce qui suit ci-dessous selon le navigateur internet que vous utilisez : ",
'name' => array ( 'Firefox', 'Konqueror', 'MSIE', 'Opera', 'Safari'),
'Firefox' => array (
'Menu Éditio<u>n</u> > Pré<u>f</u>érences',
"Onglet 'Contenu'",
"Cliquez sur 'Activer Javascript'",
'Cliquez sur le bouton [ x Fermer ]',
),
'Konqueror' => array (
'<u>C</u>onfiguration > <u>C</u>onfigurer Konqueror',
"Section 'Navigation Internet'",
"Sous-section 'Java & Javascript'",
"Onglet 'Java<u>S</u>cript'",
"Cliquez sur '<u>T</u>oujours activer JavaScript'",
"Cliquez sur le bouton [ <u>O</u>k ]",
),
'MSIE' => array (
'Menu Outils > Options Internet',
"Onglet 'Sécurité'",
'Bouton [ Personnaliser le niveau ]',
"Allez jusqu'à la section nommée 'Script' ou 'Scripting'",
"Cliquez sur 'Activer' dans la sous-section nommée 'Active Scripting' ou 'Script ASP'",
"Cliquez sur les boutons [ OK ]",
),
'Opera' => array (
'Menu <u>O</u>utils > <u>P</u>références rapides F12',
"Cliquez sur 'Activer Javascript'",
),
'Safari' => array (
'Menu Édition > Préférence',
"Onglet 'Sécurité'",
"Cliquez sur 'Autoriser Javascript'",
),
'Autre' => array (
"Veuillez vous renseigner pour la configuration de votre navigateur !",
),
),
),
);
/*** don't touch theses values ***/
$this->control = array (
'role' => array ('e','r'),
'service' => array ('c','p','v','cp','cv'),
);
$this->length = array (
'min' => 8,
'max' => 24,
);
$this->seconds=600;
// appel to internal method
$this->createSession(); // place absolutly this before $this->declareVariable ;-)
$this->verifyDefine();
$this->randomCrossReference();
$this->declareVariable();
$this->File_Separate();
$this->get_timer_modif_file();
}
function __destruct() {
if(constant('useSession') == TRUE) {
session_unset();
session_destroy();
}
}
/***
Public methods
***/
public function openHTML() {
$this->buffering();
$this->flush_header();
$this->HTML_HEAD();
$this->HTML_BodyOpener();
$this->HTML_no_JS();
}
public function getRole() {
foreach($this->control['role'] as $v) {
$this->role = $v;
$this->HTML_GetRole();
}
}
public function setRole() {
$this->HTML_SetRole();
}
public function closeHTML() {
$this->HTML_BodyCloser();
$this->empty_out();
}
/***
****
Privates methods
****
***/
private function buffering() {
if(eregi("gzip,deflate", ENCODING)) {
ini_set('output_buffering', 'On');
ini_set('implict_flush', 'Off');
ob_start('ob_gzhandler');
ob_start(array('SparkAngels','data_compressor'));
}
}
private function createSession() {
if(constant('useSession') == TRUE) {
$this->file = array ( '/dev/random', '/dev/urandom' );
$this->INI['lifetime'] = ini_get('session.cookie_lifetime');
$this->INI['path'] = ini_get('session.cookie_path');
$this->INI['domain'] = ini_get('session.cookie_domain');
$this->INI['secure'] = ini_get('session.cookie_secure');
$this->INI['httponly'] = ini_get('session.cookie_httponly');
$this->INI['entropy_file'] = ini_get('session.entropy_file');
if(empty($this->INI['domain'])) $this->INI['domain'] = $_SERVER['SERVER_NAME'];
if($this->INI['httponly'] != 1) $this->INI['httponly'] = 1;
// initialize sessions variables
ini_set('session.cookie_httponly', $this->INI['httponly']);
if(isset($this->INI['entropy_file'])) {
if(file_exists($this->file[0])) ini_set('session.entropy_file', $this->file[0]);
elseif(file_exists($this->file[1])) ini_set('session.entropy_file', $this->file[1]);
else ini_set('session.entropy_file', $this->INI['entropy_file']);
if(ini_get('session.entropy_file') != '') ini_set('session.entropy_length', 1024);
}
ini_set('session.hash_function', 1);
ini_set('session.hash_bits_per_character', 6);
ini_set('session.name', nameSession);
ini_set('session.referer_check', refererSession);
ini_set('session.use_cookies', 1);
ini_set('session.use_only_cookies', 1);
ini_set('session.use_trans_sid', 0);
ini_set('session.url_rewriter_tags', '');
session_id(hash(algo,mt_rand()));
session_set_cookie_params($this->INI['lifetime'],$this->INI['path'],$this->INI['domain'],$this->INI['secure'],$this->INI['httponly']);
session_start();
//$_SESSION['AuthCode'] = '';
$_SESSION['ID'] = ID;
$_SESSION['Pass'] = Pass;
$_SESSION['ServiceType'] = $this->control['service'][1];
}
}
private function data_compressor($buffer) {
/* remove comments */
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
/* remove tabs, spaces, newlines, etc. */
$buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer);
return $buffer;
}
/***
declare all variables necessary
***/
private function declareVariable() {
foreach($this->control['role'] as $v) {
$this->apiValue[$v] = 'a'.AUTH.',v'.Version.',c'.Command.',r'.$v;
$this->apiValue[$v] .= ',x';
if(strcmp($v, $this->control['role'][1]) == 0) { // if role r !
if(constant('useSession') == TRUE && !empty($_POST['code'])) $this->apiValue[$v] .= strip_tags($_POST['code']);
elseif(!empty($_COOKIE['AuthCode'])) $this->apiValue[$v] .= strip_tags($_COOKIE['AuthCode']);
}
else $this->apiValue[$v] .= $this->xref;
$this->apiValue[$v] .=',u'.Pseudo.',s'.$this->getServiceType();
$this->apiUrl[$v] = URL.rawurlencode($this->apiValue[$v]);
$this->img[$v] = '<img src="/img/sparkAngels_'.$v.'-mini.gif" border="0" alt="'.$this->txt['a']['sparkangels'][$v]['title'].'"/>';
$this->a['sparkangels'][$v] = '<a href="'.$this->apiUrl[$v].'" title="'.$this->txt['a']['sparkangels'][$v]['title'].'">'.$this->img[$v].'</a>';
$this->a['role'][$v] = '<a href="javascript: toggle(\''.$v.'\');" title="'.$this->txt['a']['role'][$v]['title'].'">'.$this->txt['a']['role'][$v]['txt'].'</a>'."\n";
}
}
private function empty_out() {
if(eregi("gzip,deflate", ENCODING)) {
ob_get_contents();
ob_flush();
ob_end_flush();
}
}
private function flush_header() {
header('Expires: '.strftime('%c',$this->timer+$this->seconds));
header('Last-Modified: '.strftime('%c',$this->timer));
header('Cache-Control: '.$this->seconds);
}
private function get_timer_modif_file() {
//$this->timer = filectime('index.php');
$this->timer = time();
}
/***
separate css in file .css and code javascript in file .js
***/
private function File_Separate() {
if(constant('CSS_file_separate') == TRUE) {
$this->file['name']['css'] = CSS_file_name;
$this->file[CSS_file_name] = $this->Script_CSS();
}
else {
if(file_exists(CSS_file_name) && is_file(CSS_file_name)) unlink(CSS_file_name);
}
if(constant('JS_file_separate') == TRUE) {
$this->file['name']['js'] = JS_file_name;
$this->file[JS_file_name] = $this->Script_JS();
}
else {
if(file_exists(JS_file_name) && is_file(JS_file_name)) unlink(JS_file_name);
}
if(!empty($this->file['name']) && !empty($this->file['name'])) {
foreach($this->file['name'] as $k => $v) {
if(!file_exists($v)) {
$handle = fopen($v, 'w');
fwrite($handle, $this->data_compressor($this->file[$v]));
fclose($handle);
umask(000);
chmod(ROOT.$v, 0705);
}
}
}
unset($this->file);
}
/***
obtain service type
***/
private function getServiceType() {
if(constant('useSession') == TRUE) {
if(!empty($_POST['service'])
&& in_array($_POST['service'],$this->control['service'])) {
$this->serviceType = $_POST['service'];
}
else $this->serviceType = $_SESSION['ServiceType'];
}
elseif(!empty($_COOKIE['ServiceType']) && in_array($_COOKIE['ServiceType'],$this->control['service'])) {
$this->serviceType = $_COOKIE['ServiceType'];
}
else $this->serviceType = $this->control['service'][1];
return $this->serviceType;
}
/***
Privates methods to display html
***/
private function HTML_HEAD() {
$buffer = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
$buffer .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">'."\n";
$buffer .= '<head>'."\n";
$buffer .= "\t".'<base href="http://'.HOST.'/"/>'."\n";
$buffer .= "\t".'<title>'.$this->txt['title'].'</title>'."\n";
$buffer .= "\t".'<link rel="icon" type="image/vnd.microsoft.icon" href="/img/favicon.ico" />'."\n";
$buffer .= "\t".'<link rel="shortcut icon" type="image/vnd.microsoft.icon" href="/img/favicon.ico" />'."\n";
$buffer .= "\t".'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'."\n";
$buffer .= "\t".'<meta http-equiv="Expires" content="'.strftime('%c',$this->timer+$this->seconds).'"/>'."\n";
$buffer .= "\t".'<meta http-equiv="Last-Modified" content="'.strftime('%c',$this->timer).'"/>'."\n";
$buffer .= "\t".'<meta http-equiv="Cache-Control" content="public, max-age=600"/>'."\n";
$buffer .= "\t".'<meta http-equiv="Pragma" content="no-cache"/>'."\n";
if(constant('CSS_file_separate') == TRUE) $buffer .= "\t".'<link rel="stylesheet" type="text/css" href="'.CSS_file_name.'" media="all" title="Default" />'."\n";
else $buffer .= $this->HTML_Script('css');
$buffer .= "\t".'<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>'."\n";
if(constant('JS_file_separate') == TRUE) $buffer .= "\t".'<script type="text/javascript" src="'.JS_file_name.'"></script>'."\n";
else $buffer .= $this->HTML_Script('js');
$buffer .= '</head>'."\n";
echo $buffer;
}
private function HTML_BodyOpener() {
$buffer = '<body>'."\n";
$buffer .= ' <h1>'.$this->txt['h1'].'</h1>'."\n";
echo $buffer;
}
private function HTML_BodyCloser() {
$buffer = '</body>'."\n";
$buffer .= '</html>'."\n";
echo $buffer;
}
private function HTML_AuthCode() {
if(constant('useSession') == TRUE) {
if(!empty($_POST['code'])) $this->code = strip_tags($_POST['code']);
else $this->code = $this->xref;
}
elseif(!empty($_COOKIE['AuthCode'])) $this->code = strip_tags($_COOKIE['AuthCode']);
else $this->code = $this->xref;
$buffer = '<p>'.$this->txt['various']['code'].'<strong>'.$this->code.'</strong> (<em>'.$this->strlen_xref.' caractères</em>)</p>'."\n";
return $buffer;
}
private function HTML_Browser_Active_JS() {
$buffer = '<p class="error">'.$this->txt['various']['browser']['activate'].'</p>'."\n";
$buffer .= '<dl class="error">'."\n";
foreach($this->txt['various']['browser']['name'] as $v) {
if(stristr(WEBAGENT, $v)) {
$buffer .= '<dt>'.$v.'</dt>'."\n";
foreach($this->txt['various']['browser'][$v] as $v1) {
$buffer .= '<dd>'.$v1.'</dd>'."\n";
}
$agent=1;
}
}
if($agent != 1) $buffer = '<p class="error">'.$this->txt['various']['browser']['autre'].'</p>'."\n";
$buffer .= '</dl>'."\n";
return $buffer;
}
private function HTML_ErrorIdPass() {
$buffer = '<div id="error" class="error">'."\n";
$buffer .= '<p>'.$this->txt['various']['error']['IdPass'].'</p>'."\n";
$buffer .= '</div>'."\n";
return $buffer;
}
private function HTML_GetRole() {
if(constant('useSession') == TRUE) $this->form_action = '/';
else $this->form_action = 'service.php';
$buffer = '<div id="'.$this->role.'" style="display: none;">'."\n";
if(strcmp($this->role,$this->control['role'][0]) == 0) {
$buffer .= $this->HTML_Form_Role_E();
$buffer .= $this->HTML_AuthCode();
$buffer .= $this->HTML_ImgSparkAngels();
}
else {
$buffer .= $this->HTML_Form_Role_R();
$buffer .= $this->VerifyCode();
}
$buffer .= '</div>'."\n";
unset($this->form_action);
echo $buffer;
}
private function HTML_Form_Role_E() {
$buffer = '<div id="form_role_e">'."\n";
$buffer .= '<form action="'.$this->form_action.'" method="post">'."\n";
$buffer .= '<fieldset>'."\n";
$buffer .= '<legend>'.$this->txt['form']['e']['legend'].'</legend>'."\n";
$buffer .= '<label for="service">'.$this->txt['form']['e']['label4select'].'</label>'."\n";
$buffer .= '<select name="service" id="service">'."\n";
$buffer .= '<optgroup label="choix">'."\n";
foreach($this->control['service'] as $k => $v) {
if(strcmp($this->serviceType,$v) == 0) {
$buffer .= '<option label="'.$this->txt['form']['e']['label4option'].$this->txt['various']['service'][$v].'" value="'.$v.'" selected="selected">'.ucfirst($this->txt['various']['service'][$v]).'</option>'."\n";
}
else {
$buffer .= '<option label="'.$this->txt['form']['e']['label4option'].$this->txt['various']['service'][$v].'" value="'.$v.'">'.ucfirst($this->txt['various']['service'][$v]).'</option>'."\n";
}
}
$buffer .= '</optgroup>'."\n";
$buffer .= '</select>'."\n";
$buffer .= '<p><input type="hidden" name="uri" id="uri" value="http://'.HOST.REQUEST.'" />'."\n";
$buffer .= '<label for="pagine">'.$this->txt['form']['e']['label4input'].'</label>'."\n";
$buffer .= '<input type="submit" name="pagine" id="pagine" value="'.$this->txt['form']['e']['input2envoy'].'"/></p>'."\n";
$buffer .= '</fieldset>'."\n";
$buffer .= '</form>'."\n";
$buffer .= '</div>'."\n";
return $buffer;
}
private function HTML_Form_Role_R() {
$buffer = '<div id="form_role_r">'."\n";
$buffer .= '<form action="'.$this->form_action.'" method="post">'."\n";
$buffer .= '<fieldset>'."\n";
$buffer .= '<legend>'.$this->txt['form']['e']['legend'].'</legend>'."\n";
//$buffer .= '<p>'.$this->txt['form']['r']['p'].'<strong>'.$this->txt['various']['service'][$this->serviceType].'</strong> !</p>'."\n";
$buffer .= '<label for="service">'.$this->txt['form']['e']['label4select'].'</label>'."\n";
$buffer .= '<select name="service" id="service">'."\n";
$buffer .= '<optgroup label="choix">'."\n";
foreach($this->control['service'] as $k => $v) {
if(strcmp($this->serviceType,$v) == 0) {
$buffer .= '<option label="'.$this->txt['form']['e']['label4option'].$this->txt['various']['service'][$v].'" value="'.$v.'" selected="selected">'.ucfirst($this->txt['various']['service'][$v]).'</option>'."\n";
}
else {
$buffer .= '<option label="'.$this->txt['form']['e']['label4option'].$this->txt['various']['service'][$v].'" value="'.$v.'">'.ucfirst($this->txt['various']['service'][$v]).'</option>'."\n";
}
}
$buffer .= '</optgroup>'."\n";
$buffer .= '</select>'."\n";
$buffer .= '</fieldset>'."\n";
$buffer .= '<fieldset>'."\n";
$buffer .= '<legend>'.$this->txt['form']['r']['legend'].'</legend>'."\n";
$buffer .= '<p><label for="code">'.$this->txt['form']['r']['label4code'].' </label>'."\n";
$buffer .= '<input type="text" name="code" id="code" value="" maxlength="'.$this->maxlength.'" /> ';
$buffer .= '<em>(<span id="charLength"></span> '.$this->txt['various']['charLength'].')</em></p>'."\n";
$buffer .= '<p><label for="id">'.$this->txt['form']['r']['label4id'].' </label>'."\n";
$buffer .= '<input type="text" name="id" id="id" value="" />'."\n";
$buffer .= '<br /><label for="pass">'.$this->txt['form']['r']['label4pass'].' </label>'."\n";
$buffer .= '<input type="password" name="pass" id="pass" value="" /></p>'."\n";
$buffer .= '<p><input type="hidden" name="uri" id="uri" value="http://'.HOST.REQUEST.'" />'."\n";
$buffer .= '<label for="ok_code">'.$this->txt['form']['r']['label4input'].'</label>'."\n";
$buffer .= '<input type="submit" name="ok_code" id="ok_code" value="'.$this->txt['form']['r']['input2envoy'].'"/></p>'."\n";
$buffer .= '</fieldset>'."\n";
$buffer .= '</form>'."\n";
$buffer .= '</div>'."\n";
return $buffer;
}
private function HTML_ImgSparkAngels() {
$buffer = '<p>'.$this->a['sparkangels'][$this->role].'</p>'."\n";
return $buffer;
}
private function HTML_Script($script) {
switch($script) {
case 'css' :
$buffer = "\t".'<style type="text/css">';
$buffer .= $this->Script_CSS();
$buffer .= '</style>'."\n";
break;
case 'js' :
$buffer = "\t".'<script type="text/javascript">';
$buffer .= $this->Script_JS();
$buffer .= '</script>'."\n";
break;
}
unset($script);
return $buffer;
}
private function HTML_no_JS() {
$buffer = '<noscript>'."\n";
$buffer .= '<p class="error">'.$this->txt['various']['error']['JS'].'</p>'."\n";
$buffer .= $this->HTML_Browser_Active_JS();
$buffer .= '</noscript>'."\n";
echo $buffer;
}
private function HTML_SetRole() {
$buffer = '<h2>'.$this->txt['h2']['role'].'</h2>'."\n";
$buffer .= '<p>';
foreach($this->a['role'] as $k => $v) {
if($k == 'e') $buffer .= $v.'<span> | </span>';
else $buffer .= $v;
}
$buffer .= '</p>'."\n";
echo $buffer;
}
private function Script_CSS() {
$buffer = "
.error {
border: 1px solid #000;
background-color: #900;
color: #fff;
font-weight: bold;
padding: 1em;
}
.hidden {
visibility: hidden;
}
";
return $buffer;
}
private function Script_JS() {
$buffer = "
$(document).ready(function(){
$('#charLength').html($('#code').val().length);
$('#code').keyup(function(){
$('#charLength').html($(this).val().length);
});
});
function toggle(role) {
if(role=='e') {
$('#r').slideUp('fast', function() {
$('#'+role).slideToggle('slow');
});
}
if(role=='r') {
$('#e').slideUp('fast', function() {
$('#'+role).slideToggle('slow');
});
}
}
if(!navigator.javaEnabled()) {
var url = 'http://java.com/fr/download/index.jsp';
var mssg = \"".$this->txt['various']['error']['JS_toggle']."\" + ".HOST." + ' !';
window.alert(mssg);
location.replace(url);
}";
return $buffer;
}
/***
Create a key randomized
***/
private function randomCrossReference() {
$len = rand($this->length['min'],$this->length['max']);
$buffer = substr(str_shuffle(str_repeat(CrossReference,$len)),0,$len);
$this->xref = wordwrap($buffer,4,Separator,1);
$this->strlen_xref = strlen($this->xref);
$this->maxlength = $this->length['max']+($this->length['max']/4-1);
unset($buffer,$len);
}
/***
Verify ID and Pass in Cookies
***/
private function VerifyCode() {
$buffer = '';
if(constant('useSession') == TRUE) {
if( !empty($_POST['id']) && !empty($_POST['pass'])
&& hash(algo,$_POST['id']) == $_SESSION['ID'] && hash(algo,$_POST['pass']) == Pass ) {
$buffer .= $this->HTML_ImgSparkAngels($this->control['role'][1]);
}
else $buffer .= $this->HTML_ErrorIdPass();
}
elseif( !empty($_COOKIE['ID']) && !empty($_COOKIE['Pass'])
&& hash(algo,$_COOKIE['ID']) == ID && hash(algo,$_COOKIE['Pass']) == Pass ) {
$buffer .= $this->HTML_ImgSparkAngels($this->control['role'][1]);
}
else $buffer .= $this->HTML_ErrorIdPass();
return $buffer;
}
/***
Verify if Define is ...
***/
private function verifyDefine() {
if(constant('AUTH') == NULL) die($this->txt['various']['error']['not_define'].'AUTH');
if(constant('Pseudo') == NULL) die($this->txt['various']['error']['not_define'].'Pseudo');
if(constant('ID') == NULL) die($this->txt['various']['error']['not_define'].'ID');
if(constant('Pass') == NULL) die($this->txt['various']['error']['not_define'].'Pass');
if(constant('algo') == NULL) die($this->txt['various']['error']['not_define'].'algo');
if(constant('useSession') == TRUE && constant('nameSession') == NULL)
die($this->txt['various']['error']['not_define'].'nameSession');
if(constant('CSS_file_separate') == TRUE && constant('CSS_file_name') == NULL)
die($this->txt['various']['error']['not_define'].'CSS_file_name');
if(constant('JS_file_separate') == TRUE && constant('JS_file_name') == NULL)
die($this->txt['various']['error']['not_define'].'JS_file_name');
if(constant('algo') == TRUE) {
$hash = hash_algos();
if(!in_array(algo,$hash)) die($this->txt['various']['error']['bad_hash']);
unset($hash);
}
}
}
?>
Le fichier de configuration qui va avec :
<?php
// Your code API SparkAngels
define ('AUTH', '');
// Your Pseudo SparkAngels
define ('Pseudo', '');
// Your Identifiant (Hash-it with the script hash-it.php and past-in here)
define ('ID', '');
// Your Password (Hash-it with the script hash-it.php and past-in here)
define ('Pass', '');
// define the algo to hash *** may be carefull, the ID and PASS could be to hashing before with same algo !
define ('algo', 'sha512');
// use PHP sessions if you want
define ('useSession', 0);
// change the name session as you desire
define ('nameSession', 'API_SparkAngels_PHP');
// define session.referer_check ... modify this if you know !
define ('refererSession', '');
// define if file css is separate of the class
define ('CSS_file_separate', 0);
define ('CSS_file_name', 'aide.css');
// define if file aide.js is separate of the class
define ('JS_file_separate', 0);
define ('JS_file_name', 'aide.js');
?>
Démonstration
Vous pouvez voir le fonctionnement de la classe "SparkAngels" sur mon site d'aide.
Obtenir la classe
Vous pouvez avoir plus d'explications sur mon blog et avoir l'archive contenant tous les fichiers.
<<| Page : PHP : class : SparkAngels : |>>