<?php
/***************************************************************************
                          login.php - Login Script
                             -------------------
    begin                : Mars  UTC 2001
    copyright            : (C) 2002 by NADAL Jean-Baptiste
    email                : jbnadal@ifrance.com
 ***************************************************************************
 *
 *
 *
 ***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************
 * $Id: login.php,v 1.7 2005/01/30 18:38:08 jb Exp $
 ***************************************************************************/

require "conf.php";
require "cadre.php";
require "ErreurConnect.php";

/* Get parameters. */
$pseudo = $_POST['pseudo'];
$password = $_POST['password'];

/* Connect the database. */
$db_link = jb_sql_connect (true);

/* Select the record which contain the login and the password. */
$requete = mysql_db_query ($sql_bdd,
                           "select * from $table_users ".
                           "where ".
                           "pseudo=\"$pseudo\" and password=\"$password\"",
                           $db_link);

/* Si aucun enregistrement ne correspond. */
if (mysql_num_rows ($requete) == 0) {
   /* Redirection vers lapage d'erreur. */
   header ("Location:$url_erreur");
}
else {

   $row = mysql_fetch_row($requete);
   $state = $row[5];
   $email = $row[4];
   $id_user = $row[0];
   
   /* D�marre la session. Sp�cifie une id de session. */
   session_start (); 
   /* On enregistre $login dans la session. */
   // deprecated session_register ("pseudo");
   $_SESSION["pseudo"] =  $pseudo;
   /* On enregistre the user ID dans la session. */
   // deprecated session_register ("id_user");
   $_SESSION["id_user"] = $id_user;
   /* On enregistre le type de l'utilisateur.*/
   // deprecated session_register ("state");
   $_SESSION["state"] = $state;


	/* Mise a jour de l'identifiant dans la table. */
/*
	$requete=mysql_db_query ($sql_bdd,"update $table_users set id=\"".
                            session_id()."where pseudo=\"$pseudo\" and ".
                            "password=\"$password\"", $db_link);*/

	header ("Location:$racine/index.php");
   exit ();
}

?>
