login singolo utente

luigi777

Utente Attivo
14 Feb 2008
1.086
1
38
42
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.
 

skoien

Nuovo Utente
30 Nov 2013
10
0
0
VA
<?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";
}

?>
 

luigi777

Utente Attivo
14 Feb 2008
1.086
1
38
42
Massa, Italy
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
Autore Titolo Forum Risposte Data
N Vba Maschera di login MS Access 1
Shyson Codice wp-login non funziona PHP 2
L Problemi con il login PHP 2
L login e session PHP 4
A Problema login con Safari PHP 14
R Reinderizzamento dopo login PHP 2
C finestra popup dopo login PHP 2
L login con solo un codice PHP 3
Web93 PROBLEMA SITO WEB WORDPRESS - LOGIN DASHBOARD Programmazione 3
M Login Autenticazione Sviluppo app per Android 0
M Effettuare Login con dati Json Sviluppo app per Android 0
S [PHP] Stampa a video Nome e Cognome in seguito a login PHP 1
M [PHP] header (location..) non funzionante dopo login PHP 3
L [PHP] Visualizzare utente dopo login PHP 0
L [PHP] login con password_verify PHP 3
A HTML issues with creating a register and login page + general questions HTML e CSS 1
L [PHP] login con varie entrate PHP 3
L [PHP] login con password_verify - password_hash PHP 5
M [PHP] Problemi con il riconoscimento login. PHP 21
F [PHP] Login senza database PHP 3
F [php] sicurezza password form login PHP 2
M [PHP] Metodo migliore per fare login a un DB Mysql PHP 1
F Problema con pagine login in PHP PHP 2
Y [PHP] Errore di login dopo aver inserito Codice AdSense PHP 0
M [PHP] Problemi con login facebook PHP 0
Shyson [WordPress] Nascondere link del Login WordPress 2
W [PHP] Login sicuro al web Service SOAP PHP 20
P [PHP] Limitare login ad un solo utente per volta PHP 12
L [PHP] login e protezione pagine con session PHP 3
L [PHP] login con la classe medoo.in PHP 5
I [PHP] [Javascript] login da smartphone a web PHP 3
P [PHP] Reindirizzamento post Login PHP 3
I [PHP] login con sessione singola PHP 1
AkenStyle Login per gioco online Database 6
bubino8 [WordPress] [PHP] Login diretto da bottone WordPress 4
D [PHP] Login Multiutente con pagina privata PHP 5
D problemi login php 5.6 mysql PHP 1
I [PHP] Login Facebook SDK returned an error: No URL set! PHP 0
G PHP Login PHP 1
Laskot Login php e redirect PHP 1
K [PHP] Unica sessione login forum/sito PHP 1
bubino8 [WordPress] Login a WP da bottone WordPress 0
bubino8 [PHP] Login Automatico PHP 1
R Filtro login tramite mac-address su apache2 SSL Apache 1
M [PHP] Sessione Login PHP 15
C [PHP] Aprire la pagina dopo aver fatto il login PHP 1
fabry1986 [PHP] login PHP 2
Punix pagine login-logout php principiante PHP 4
Fuego2806 [Joomla] Problema di login con il nuovo template Joomla 0
S [PHP] Problemi con Login e pagina Utente PHP 5

Discussioni simili