X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=php%2Fconnexion.php;h=0d337c148950be538b38f3fc13c0126bd9334b39;hb=23bc2016d5fbd8f7daa9b7ba5c7fa862709ff7a7;hp=fc3b050df767ca9a1ecf3d0e3e0abd0c11424f2f;hpb=ca33eb6a816b02a621896aa446cc9317e770993d;p=cl7.git diff --git a/php/connexion.php b/php/connexion.php index fc3b050..0d337c1 100644 --- a/php/connexion.php +++ b/php/connexion.php @@ -1,65 +1,78 @@ -'); - fclose($f); - echo "Le fichier a été créé, veuillez le compléter et recommencer."; - exit(); -} +include_once("participant.php"); -include_once("config_bd.php"); -include_once("class_participant.php"); - -$lien_mysql = mysql_connect($SQL_HOTE, $SQL_LOGIN, $SQL_PASS); -if (!$lien_mysql || !mysql_select_db($NOM_BASE)) +/* + * Connexion à la base de données et création du participant courant. + */ +class Connexion { - echo "Connexion à la base de données impossible. Voir le fichier 'php/config_bd.php'"; - exit(); -} + # Message à destination de l'utilisateur, par exemple pour lui indiquer une erreur. + public $message_utilisateur = NULL; -mysql_set_charset("UTF8"); -mysql_query('SET AUTOCOMMIT=0'); + public $participant; + + function Connexion() + { + if (!file_exists("php/config_bd.php")) + { + echo "Le fichier 'php/config_bd.php' n'existe pas, création en cours...\n"; + if (!is_writable(".")) + { + echo "Le dossier 'php' n'est pas accessible en écriture, veuillez changer les droits et recommencer."; + exit(); + } + $f = fopen("php/config_bd.php", "w"); + fwrite($f, '' + ); + fclose($f); + echo "Le fichier a été créé, veuillez le compléter et recommencer."; + exit(); + } + + include_once("config_bd.php"); + + $conn_bd = pg_connect(sprintf("host=%s dbname=%s user=%s password=%s", $SQL_HOTE, $NOM_BASE, $SQL_LOGIN, $SQL_PASS)); + if (!$conn_bd) + { + echo "Connexion à la base de données impossible. Voir le fichier 'php/config_bd.php'"; + exit(); + } -if (isset($_POST['effacer_cookie'])) # le membre se délogue -{ - setcookie("COOKIE_INFO_PATICIPANT", "", time() - 100); # 'efface' le cookie membre - unset($HTTP_COOKIE_VARS["COOKIE_INFO_PATICIPANT"]); - unset($log); -} + //mysql_set_charset("UTF8"); + //mysql_query('SET AUTOCOMMIT=0'); -if (isset($_POST['log'])) # le membre se logue -{ - $le_participant = new Participant($_POST['pseudo'], $_POST['password']); - if ($le_participant->valide) - { - setcookie ("COOKIE_INFO_PATICIPANT", $le_participant->info->id, time() + 31104000); + if (isset($_POST['effacer_cookie'])) # le membre se délogue + { + setcookie("COOKIE_INFO_PARTICIPANT", "", time() - 100); # 'efface' le cookie membre + unset($_COOKIE["COOKIE_INFO_PARTICIPANT"]); + } + + if (isset($_POST['log'])) # le membre se logue + { + $this->participant = new Participant($_POST['pseudo'], $_POST['password']); + if ($this->participant->existe()) + { + setcookie("COOKIE_INFO_PARTICIPANT", $this->participant->info->id, time() + 31104000); + $this->message_utilisateur = "Loggation ok"; + } + else + $this->message_utilisateur = "Erreur de loggation"; + } + else if (isset($_COOKIE["COOKIE_INFO_PARTICIPANT"])) # le cookie existe deja chez le participant + { + $this->participant = new Participant($_COOKIE["COOKIE_INFO_PARTICIPANT"]); + } + else + { + $this->participant = new Participant(); + } } } -else if (isset($HTTP_COOKIE_VARS["COOKIE_INFO_PATICIPANT"])) # le cookie existe deja chez le participant -{ - $le_participant = new Participant($HTTP_COOKIE_VARS["COOKIE_INFO_PATICIPANT"]); -} -else -{ - $le_participant = new Participant(); -} ?> \ No newline at end of file