Probleme srcipt login

jupiler -  
graffx Messages postés 7513 Statut Contributeur -
Bonjour,

j ai une page de login me permet de m 'authentifier au niveau de la base tout est ok.

mon souci est que quand je met mon login et mon mot de pase il me renvoie vers la page de login "admin.php" donc que ca ne fonctionne pas j'ai testé la variable $username sur le deuxième fichier test.php la variable est vide j pense qu'il s'agit d'un probleme de cookie mais je ne vois pas ou merci de m'aider

page de login : admin.php

if (isset($_POST['submit'])) {
if(!$_POST['username'] | !$_POST['pass']) {
echo "<script language=\"JavaScript\">\n";
echo "window.location.href = 'admin3.php'";
echo "</script>";
}
checkck = mysql_query("SELECT * FROM matable WHERE username = '".$_POST['username']."'")or die(mysql_error());
//Gives error if user dosen't exist
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
echo "<script language=\"JavaScript\">\n";
echo "window.location.href = 'admin2.php'";
echo "</script>";
}
while($info = mysql_fetch_array( $check ))
{
$_POST['pass'] = stripslashes($_POST['pass']);
$info['password'] = stripslashes($info['password']);
$_POST['pass'] = md5($_POST['pass']);
//gives error if the password is wrong
if ($_POST['pass'] != $info['password']) {
echo "<script language=\"JavaScript\">\n";
echo "window.location.href = 'admin4.php'";
echo "</script>";
}
else
{
// if login is ok then we add a cookie
$_POST['username'] = stripslashes($_POST['username']);
$hour = time() + 3600;
setcookie(ID_my_site, $_POST['username'], $hour);
setcookie(Key_my_site, $_POST['pass'], $hour);
//then redirect them to the members area
echo "<script language=\"JavaScript\">\n";
echo "window.location.href = 'test.php'";
echo "</script>";
}
}
}
else
{
// if they are not logged in
?>


<?php
include("header2.php");
?>

<div id="page">


<div id="loginbox">
<h1>Se connecter</h1>

<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table style="padding-left: 20px;">
<tr>
<td style="color:white;">Nom d'utilisateur:</td>
<td style="height: 30px;" class="field"><input type="text" name="username" maxlength="40"></td>
</tr>
<tr>
<td style="color:white;">Mot de passe:</td>
<td style="height: 30px;" class="field"><input type="password" name="pass" maxlength="50"></td>
</tr>
<tr><td colspan="2" align="right">
<input style="margin-right: 65px; margin-top: 5px;" type="submit" name="submit" value="Connexion">
</td></tr>
</table>
</form>
</div>
</div>
<?php
?>
<?php
include("footer2.php");
}
?>

et le script2: test.php :

<?php
if(isset($_COOKIE['ID_my_site']))
{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM matable WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
if ($pass != $info['password'])
{
header("Location: admin.php");
}
else
{
include("header2.php");
?>
<div id="page">
<?php
echo '<a href="import.php">Importer un fichier</a>';
echo '<a href="supprimer.php">Supprimer un fichier</a>';
?>
</div>
<?php
include("footer2.php");
}
}
}
else
{

echo "<script language=\"JavaScript\">\n";
echo "alert('$username');";
echo "</script>";
}
?>

2 réponses

jupiler
 
Personne n'a une idée ?

merci
0
graffx Messages postés 7513 Statut Contributeur 1 975
 
ben vire ton cookie et essaie sans, tu seras fixé deja la dessus
0