FIX #97
[cl7.git] / php / connexion.php
1 <?php
2 /*
3 * Connexion à la base de donnée + résolutiondu participant.
4 * Produit une variable globale nommée '$le_participant'.
5 */
6
7 if (!file_exists("php/config_bd.php")) {
8 echo "Le fichier 'php/config_bd.php' n'existe pas, création en cours...\n";
9 if (!is_writable("."))
10 {
11 echo "Le dossier 'php' n'est pas accessible en écriture, veuillez changer les droits et recommencer.";
12 exit();
13 }
14 $f = fopen("php/config_bd.php", "w");
15 fwrite($f, '
16 <?php # encoding:utf-8
17 # Parametres de connexion MySQL
18 $SQL_HOTE = "localhost";
19 $SQL_LOGIN = "";
20 $SQL_PASS = "";
21 $NOM_BASE = "corcelles_lan7";
22 ?>');
23 fclose($f);
24 echo "Le fichier a été créé, veuillez le compléter et recommencer.";
25 exit();
26 }
27
28 include_once("config_bd.php");
29 include_once("class_participant.php");
30
31 $lien_mysql = mysql_connect($SQL_HOTE, $SQL_LOGIN, $SQL_PASS);
32 if (!$lien_mysql || !mysql_select_db($NOM_BASE))
33 {
34 echo "Connexion à la base de données impossible. Voir le fichier 'php/config_bd.php'";
35 exit();
36 }
37
38 mysql_set_charset("UTF8");
39 mysql_query('SET AUTOCOMMIT=0');
40
41 if (isset($_POST['effacer_cookie'])) # le membre se délogue
42 {
43 setcookie("COOKIE_INFO_PATICIPANT", "", time() - 100); # 'efface' le cookie membre
44 unset($HTTP_COOKIE_VARS["COOKIE_INFO_PATICIPANT"]);
45 unset($log);
46 }
47
48 if (isset($_POST['log'])) # le membre se logue
49 {
50 $le_participant = new Participant($_POST['pseudo'], $_POST['password']);
51 if ($le_participant->valide)
52 {
53 setcookie ("COOKIE_INFO_PATICIPANT", $le_participant->info->id, time() + 31104000);
54 }
55 }
56 else if (isset($HTTP_COOKIE_VARS["COOKIE_INFO_PATICIPANT"])) # le cookie existe deja chez le participant
57 {
58 $le_participant = new Participant($HTTP_COOKIE_VARS["COOKIE_INFO_PATICIPANT"]);
59 }
60 else
61 {
62 $le_participant = new Participant();
63 }
64
65 ?>