login singolo utente

  • Creatore Discussione Creatore Discussione luigi777
  • Data di inizio Data di inizio

luigi777

Utente Attivo
14 Feb 2008
1.086
1
38
43
Massa, Italy
Ciao, perché questo listato che ho scritto mi da un notice al controllo per eseguire le sessioni:

PHP:
<html>
<head>
</head>
<style>
.tableheader {
background-color: #95BEE6;
color:white;
font-weight:bold;
}
.tablerow {
background-color: #A7D6F1;
color:white;
}
.message {
color: #FF0000;
font-weight: bold;
text-align: center;
width: 100%;
}</style>
<body>
<?php 
session_start ();    
$USERS["user"]['username'] = "luigi";
$USERS["user"]['password'] = "prova";

if (isset($_POST['submit'])) 
{ 
 if(empty($_POST["utente"]))
 {
  $message = "Non inserito utente";
 }elseif(empty($_POST["password"]))
 {
	$message= "Non inserito la password";
 }else
 {
// qui mi da errore e non fa il redirect alla pagina index.php
 if ($USERS[$_POST["utente"]]['username'] == $_POST["utente"] && $USERS[$_POST["utente"]]['password'] == $_POST["password"])
  {
	$_SESSION['utente']=$_POST['utente']; 
	$_SESSION['login']=true; 
	header("Location: index.php");
  }
	else { $message= "Login errato";} 
  }
}
?>

<form name="frmUser" method="post" action="">
<div class="message"><?php if(isset($message)) { echo $message; } ?></div>
<table border="0" cellpadding="10" cellspacing="1" width="500" align="center">
<tr class="tableheader">
<td align="center" colspan="2">Login</td>
</tr>
<tr class="tablerow">
<td align="right">Username</td>
<td><input type="text" name="utente"></td>
</tr>
<tr class="tablerow">
<td align="right">Password</td>
<td><input type="password" name="password"></td>
</tr>
<tr class="tableheader">
<td align="center" colspan="2"><input type="submit" name="submit" value="Submit"></td>
</tr>
</table>
</form>

come mai?

idee?
buona fine settimana.
 
<?php
session_start ();
$USERS["user"]['username'] = "luigi";
$USERS["user"]['password'] = "prova";

[.......] omissis [........]
if ($USERS[$_POST["utente"]]['username'] == $_POST["utente"] && $USERS[$_POST["utente"]]['password'] == $_POST["password"])
{
$_SESSION['utente']=$_POST['utente'];
$_SESSION['login']=true;
header("Location: index.php");
}
else { $message= "Login errato";}
}
}
?>

Ciao dando un occhiata velocissima dovresti prendere in considerazione che tu dopo il session_start(); hai dichiarato $USERS["user"]['username'] = "luigi"; ma poi nell'if metti $USERS["utente"]['username'] = "luigi";

Quindi dovresti mettere entrambi gli erray corretti.

prova questo:

PHP:
<?php
session_start();
$adm_username="luigi";
$adm_password="prova";

$username=htmlentities($_GET['username']);
$password=htmlentities($_GET['password']);

if ($username==$adm_username AND $password==$adm_password) {

$_SESSION['login'] = true;
$_SESSION['username'] = $adm_username;
echo "Login effettuato con successo, ciao " . htmlspecialchars($_SESSION['username']) . "";
// oppure il redirect
// header('Location:index.php');
} else {
echo "Errore, i dati non sono corretti";
}

?>
 
risolto:
PHP:
<html>
<head>
</head>
<style>
.tableheader {
background-color: #95BEE6;
color:white;
font-weight:bold;
}
.tablerow {
background-color: #A7D6F1;
color:white;
}
.message {
color: #FF0000;
font-weight: bold;
text-align: center;
width: 100%;
}</style>
<body>
<?php 
session_start ();    

$USERS = array(
    'user' => array(
        'luigi' => array(
            'username' => 'luigi',
            'password' => 'root')));


if (isset($_POST['submit'])) 
{ 
 if(empty($_POST["username"]))
 {
  $message = "Non inserito utente";
 }elseif(empty($_POST["password"]))
 {
	$message= "Non inserito la password";
 }else
 {
 if( array_key_exists( $_POST['username'], $USERS['user']) && $_POST['username'] === $USERS['user'][$_POST['username']]['username'] &&$_POST['password'] === $USERS['user'][$_POST['username']]['password'] )
	{
			$_SESSION['utente']=$_POST['username']; 
			$_SESSION['login']=true; 
			header("Location: index.php");
	}
			else { $message= "Login errato";} 
	
  }
}	
?>

<form name="frmUser" method="post" action="">
<div class="message"><?php if(isset($message)) { echo $message; } ?></div>
<table border="0" cellpadding="10" cellspacing="1" width="500" align="center">
<tr class="tableheader">
<td align="center" colspan="2">Login</td>
</tr>
<tr class="tablerow">
<td align="right">Username</td>
<td><input type="text" name="username"></td>
</tr>
<tr class="tablerow">
<td align="right">Password</td>
<td><input type="password" name="password"></td>
</tr>
<tr class="tableheader">
<td align="center" colspan="2"><input type="submit" name="submit" value="Submit"></td>
</tr>
</table>
</form>
ciao.
 

Discussioni simili