PDA

View Full Version : [php]Protezione pagina


gggggg
28-02-2009, 19:12
Ho provato, seguendo una guida online, a proteggere una pagina php, in cui si accede solo digitando user e psw, ma ho fatto qualche errore, perchè qualsiasi cosa digito, mi fa andare avanti, mentre solo Joe e Peter con psw hi ed hello dovrebbero poter entrare.
Qualche anima buona mi dice cosa ho sbagliato?
Il source è questo:

<html>
<body text="#000000" bgcolor="#00FFFF" link="#008000" vlink="#000000" alink="#000000">
<font face="arial black" size=3>

<?php if ($_POST["username"]=="") { ?>

<html>
<title>Our private pages</title>
<body>
In order to access this pages fill the form below:<BR>
<form method="post" action="a-anni90.php">
Username: <input type="text" name="username" size="20"><BR>
Password: <input type="password" name="password" size="15"><BR>
<input type="Submit" value="Submit">
</form>
</body>
</html>

<?php }else{
$username=$_POST["username"];
$password=$_POST["password"];
session_start();
if ($username=="Joe" AND $password=="hi"){ $permission="yes";}
if ($username=="Peter" AND $password=="hello"){ $permission="yes";}

$username=$_POST["username"];
session_register("permission");
session_register("username");

if ($permission=="yes"){
?>

<html>
<title>Our private pages</title>
<body>
Hi, you are allow to see these pages: <BR>
<font size="4"><center>ARCHIVIO DEL DISCO - DISCHI ANNI '90</font></center>
<br><br><br><br>
<ul>
<ul>
<li> <a href=/b-anni90-cataloghi.html> CATALOGHI </a>
<br> <p><br>
Sono elencate tutte le Etichette che hanno prodotto dischi negli anni '90, dal gennaio 1990 fino a dicembre 1999.
<p><br>
<li> <a href=/b-anni90-interpreti.html> INTERPRETI </a>
<p><br>
In questa sezione vogliamo elencare tutti gli Artisti che hanno inciso dischi negli anni '90. Gli Interpreti sono elencati in ordine alfabetico.
<br> <p><br>

</body>
</html>

<?php }else{ ?>

Error in username or password
<?php } ?>
<?php } ?>

</html>
<br> <p><br>

DanieleC88
01-03-2009, 01:36
L'operatore and in PHP non è &&? :mbe:

woomacoder
01-03-2009, 18:39
L'operatore and in PHP non è &&? :mbe:

Puoi usare entrambi, anche se è consigliato il && :)

kk3z
01-03-2009, 18:42
session_start() lo devi mettere prima di qualsiasi output:

<? session_start() ?>
<html>
<body text="#000000" bgcolor="#00FFFF" link="#008000" vlink="#000000" alink="#000000">
<font face="arial black" size=3>

<?php if ($_POST["username"]=="") { ?>

<html>
<title>Our private pages</title>
<body>
In order to access this pages fill the form below:<BR>
<form method="post" action="a-anni90.php">
Username: <input type="text" name="username" size="20"><BR>
Password: <input type="password" name="password" size="15"><BR>
<input type="Submit" value="Submit">
</form>
</body>
</html>

<?php }else{
$username=$_POST["username"];
$password=$_POST["password"];
if ($username=="Joe" AND $password=="hi"){ $permission="yes";}
if ($username=="Peter" AND $password=="hello"){ $permission="yes";}

//Ecc ecc

Non usare session_register, come da documentazione (http://it2.php.net/session_register):
This function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.
<?php }else{
$username=$_POST["username"];
$password=$_POST["password"];
if ($username=="Joe" AND $password=="hi")
$_SESSION['permission'] = "yes";
if ($username=="Peter" AND $password=="hello")
$_SESSION['permission'] = "yes";

if ($permission=="yes") {
$_SESSION['username'] = $username;
?>

gggggg
02-03-2009, 22:10
sembra che vada meglio però...
1) se digito user/psw giusti entro
2) se digito user/psw sbagliati non entro
3) se li digito sbagliati tre volte, al 4° tentativo entro lo stesso.
Why?
Dove è impostato un valore eguale a quattro?