<?


Define(CONNEXION_EN_COURS,true);
session_start();
$login = $_SESSION['login'] = $_POST['login'];
$_SESSION['uni'] = "uni4";
function get_ip() {
    if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    elseif(isset($_SERVER['HTTP_CLIENT_IP'])) {
        $ip  = $_SERVER['HTTP_CLIENT_IP'];
    }
    else {
        $ip = $_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}
$_SESSION['ip'] = get_ip();
include 'config.php';

//$login=$_POST['login'];
$pass = $_POST['passs'];
$mail=$_POST['mail'];

$key = "8Z5q7?&Pu!?M!?5Xs";
$passs = md5($pass.$key);




$sql = "SELECT password FROM matgraph_users WHERE login = '".$login."' AND password != 'no' ";
$req = mysql_query($sql);
if( $data = mysql_fetch_array($req) ) {

} else {

	//essayons en stripslashant
	
	//attention la sécu 
	if ((preg_match("/union/i", $login)) || (preg_match("/select/i", $login)) || (preg_match("/update/i", $login)) )
	{
    echo '<script language=javascript> alert ("Mauvais login / password. Merci de recommencer.");</script>';

		echo '<script language="javascript" type="text/javascript">
		<!--
		window.location.replace("http://www.sg-univers.fr/");
		-->
		</script>';
		session_destroy();
		exit;
	}

	$login = stripslashes($login);
	$sql = "SELECT password FROM matgraph_users WHERE login = '".$login."' AND password != 'no' ";
	$req = mysql_query($sql);

	$data = mysql_fetch_array($req);
}

if( !$data ) {
echo '<script language=javascript> alert ("Mauvais login / password. Merci de recommencer.");</script>';

session_destroy();
exit;
}

if($data['password'] != $passs)
{
echo '<script language=javascript> alert ("Mauvais login / password. Merci de recommencer.");</script>';

session_destroy();
exit;
} 


//session_start();
session_register('login');
$_SESSION['login']="$login";
SetCookie("matgraph","1",mktime(0,0,0,1,1,2010),"$login","$passs","$mail");
//session_start ();
/*if ( !session_is_registered("login"))
{
header('location:index.php') ;
}
*/

$sql2 = "SELECT * FROM matgraph_users WHERE login='".$login."' AND id = idjoueur limit 1";
$res2 = mysql_query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
$row2 = mysql_fetch_array($res2);
$idlogin = $row2['id'] ;

	// panneau admin
$req = "SELECT * FROM matgraph_axxadmin WHERE idjoueur = $idlogin";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
if ( $num == 0 ) {
echo '<script language=javascript> alert ("Droit non suffisant !");</script>';

session_destroy();
exit;

}
session_register('logina');
$_SESSION['logina']="$login";


//idlogin deja ok grace a recompte_pts







echo '<script language="javascript" type="text/javascript">
<!--
window.location.replace("index.php");
-->
</script>';




?>
<style type="text/css">
<!--
body {
	background-color: #000000;
}
-->
</style>

