Ciao a tutti,
sto costruendo un area riservata in PHP che si interfaccia in MySql.
Il problema è che mi da sempre "Wrong Username or Password".
_______________________________________________________________
Ho un database MySql con una tabella "utenti" di 3 campi :
"id" , primary key, autoincrement, unica.
"user", varchar 32
"password", varchar 32 (md5).
user=admin e password=admin (per fare delle prove!)
_______________________________________________________________
ecco i file php :
config.php:
connect.php:
login.php:
checklogin.php:
login_success.php
logout.php:
______________________________________________________________________
Mi aiutate a risolvere???
Grazie Anticipatamente!
sto costruendo un area riservata in PHP che si interfaccia in MySql.
Il problema è che mi da sempre "Wrong Username or Password".
_______________________________________________________________
Ho un database MySql con una tabella "utenti" di 3 campi :
"id" , primary key, autoincrement, unica.
"user", varchar 32
"password", varchar 32 (md5).
user=admin e password=admin (per fare delle prove!)
_______________________________________________________________
ecco i file php :
config.php:
PHP:
<?php
$DB_host = 'localhost';
$DB_user = 'root';
$DB_password = '';
$DB_name = 'mio_db';
?>
connect.php:
PHP:
<?php
$link = mysql_connect($DB_host, $DB_user, $DB_password);
if (!$link) {
die ('Non riesco a connettermi: ' . mysql_error());
}
$db_selected = mysql_select_db($DB_name, $link);
if (!$db_selected) {
die ("Errore nella selezione del database: " . mysql_error());
}
?>
login.php:
PHP:
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Area Riservata</strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="user" type="text" id="user"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="password" type="password" id="password"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
checklogin.php:
PHP:
<?php
ob_start();
include("config.php");
include ("connect.php");
// Define $user and $password
$user=$_POST['user'];
$password=$_POST['password'];
// To protect MySQL injection (more detail about MySQL injection)
$user = stripslashes($user);
$password = stripslashes($password);
$user = mysql_real_escape_string($user);
$password = mysql_real_escape_string($password);
$sql="SELECT * FROM utenti WHERE user='$user' and password='$password'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $user and $password, table row must be 1 row
if($count==1){
// Register $user, $password and redirect to file "login_success.php"
session_register("user");
session_register("password");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
?>
login_success.php
PHP:
<?php
session_start();
if(!session_is_registered("user")){
header("location:main_login.php");
}
?>
<html>
<body>
Login Successful
</body>
</html>
logout.php:
PHP:
<?php
session_start();
session_destroy();
?>
______________________________________________________________________
Mi aiutate a risolvere???
Grazie Anticipatamente!