New file |
0,0 → 1,121 |
<?php |
/*vim: set expandtab tabstop=4 shiftwidth=4: */ |
// +------------------------------------------------------------------------------------------------------+ |
// | PHP version 4.1 | |
// +------------------------------------------------------------------------------------------------------+ |
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org) | |
// +------------------------------------------------------------------------------------------------------+ |
// | This library is free software; you can redistribute it and/or | |
// | modify it under the terms of the GNU Lesser General Public | |
// | License as published by the Free Software Foundation; either | |
// | version 2.1 of the License, or (at your option) any later version. | |
// | | |
// | This library is distributed in the hope that it will be useful, | |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
// | Lesser General Public License for more details. | |
// | | |
// | You should have received a copy of the GNU Lesser General Public | |
// | License along with this library; if not, write to the Free Software | |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
// +------------------------------------------------------------------------------------------------------+ |
// CVS : $Id: spip_cookie.php,v 1.1 2004/07/20 10:01:22 alex Exp $ |
/** |
* Envoie de cookie pour SPIP à partir d'une inscription |
* |
* Envoie de cookie pour SPIP à partir d'une inscription |
* |
*@package inscription |
//Auteur original : |
*@author Alexandre Granier <alexandre@tela-botanica.org> |
//Autres auteurs : |
*@author Aucun |
*@copyright Tela-Botanica 2000-2004 |
*@version $Revision: 1.1 $ $Date: 2004/07/20 10:01:22 $ |
// +------------------------------------------------------------------------------------------------------+ |
*/ |
// Ce fichier doit être placé à la racine de SPIP |
// Il doit être appellé dans chaque squelette |
// après l'ouverture d'une session, si on ouvre une session |
|
// Il faut récupérer une valeur userid, c'est à dire |
// loggué l'utilisateur par exemple avec PEAR |
define ('SPIP_CHEMIN', 'actu/') ; |
|
// Ajouter une session pour l'auteur specifie |
// Modifié pour éviter un Warning |
if (!defined ('CHEMIN_SPIP')) { |
define ('CHEMIN_SPIP', '') ; |
} |
|
function ajouter_session_($auteur, $id_session, $id_auteur, $alea) |
{ |
$fichier_session = CHEMIN_SPIP.'ecrire/data/session_'.$id_auteur.'_'.md5($id_session.' '.$alea).'.php3'; |
//$fichier_session = CHEMIN_SPIP.'ecrire/data/session_'.$id_auteur.'_'.$id_session.'.php3'; |
$vars = array('id_auteur', 'nom', 'login', 'email', 'statut', 'lang' /*, 'ip_change'*/, 'hash_env' ); |
$auteur['hash_env'] = hash_env_() ; |
$texte = "<"."?php\n"; |
reset($vars); |
while (list(, $var) = each($vars)) { |
$texte .= "\$GLOBALS['auteur_session']['$var'] = '".addslashes($auteur[$var])."';\n"; |
} |
$texte .= "?".">\n"; |
|
if ($f = fopen($fichier_session, "wb")) { |
fputs($f, $texte); |
fclose($f); |
} |
} |
|
function hash_env_() |
{ |
global $HTTP_SERVER_VARS; |
return md5($HTTP_SERVER_VARS['REMOTE_ADDR'] . $HTTP_SERVER_VARS['HTTP_USER_AGENT']); |
} |
|
|
// On recherche userid |
$userid = $GLOBALS['identification']->getAuthData('U_ID'); |
if ($userid != 0) { |
// recherche du login dans la table spip_auteur |
// Soit c'est l'email, soit c'est un nom wiki |
$l = mysql_connect(PAP_BDD_SERVEUR, PAP_BDD_UTILISATEUR, PAP_BDD_MOT_DE_PASSE) ; |
mysql_select_db(PAP_BDD_NOM) ; |
$resultat_mail = mysql_query ('SELECT U_MAIL, U_ID FROM annuaire_tela WHERE U_ID='.$userid) |
or die ("Echec requete<br />".mysql_error()); |
$ligne_mail = mysql_fetch_object ($resultat_mail) ; |
|
mysql_select_db('tela_prod_spip_actu', $l) ; |
|
$requete_login = 'SELECT login, id_auteur FROM tela_prod_spip_actu.spip_auteurs WHERE email = "'.$ligne_mail->U_MAIL.'"' ; |
$resultat_login = mysql_query($requete_login, $l) or die ('Echec'.mysql_error()) ; |
$ligne_login = mysql_fetch_object($resultat_login) ; |
|
setcookie('spip_admin', '@'.$ligne_login->login, (int)PAP_AUTH_SESSION_DUREE, '/actu/') ; |
$id = $ligne_login->id_auteur ; |
|
$query = 'SELECT * FROM spip_auteurs WHERE id_auteur = '.$ligne_login->id_auteur; |
$result = mysql_query($query, $l); |
$GLOBALS['auteur_session'] = @mysql_fetch_array($result) ; |
$GLOBALS['auteur_session']['statut'] = '1comite'; |
$GLOBALS['auteur_session']['lang'] = 'fr'; |
|
// recherche de l'alea éphémère dans spip_meta |
$requete_meta = 'SELECT nom,valeur FROM spip_meta' ; |
$resultat_meta = mysql_query($requete_meta) or die ('echec') ; |
while ($ligne_meta = mysql_fetch_object($resultat_meta) ) { |
if ($ligne_meta->nom == 'alea_ephemere') { |
$alea = $ligne_meta->valeur ; |
} |
} |
|
if (!isset ($HTTP_COOKIE_VARS['spip_session'])) { |
$id_session = $id.'_'.(md5 (uniqid (rand ()))); |
setcookie('spip_session', $id_session, (int)PAP_AUTH_SESSION_DUREE, '/actu/') ; |
} else { |
$id_session = preg_replace('/[0-9]+_/', $id.'_', $HTTP_COOKIE_VARS['spip_session']) ; |
setcookie('spip_session', $id_session, (int)PAP_AUTH_SESSION_DUREE, '/actu/') ; |
} |
ajouter_session_($GLOBALS['auteur_session'], $id_session, $ligne_login->id_auteur, $alea) ; |
} |
?> |