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