Ti posto quello che di solito uso per fare un log-in
Il primo file si chiama index.php::
<?php
include("Template/elementiHTML.php");
prima_riga("Log-in utente");
add_css("Stile/generale.css");
add_css("Stile/accesso.css");
close_prima_riga();
?>
<div class="box1">
<form name="datiRicerca" action="actionlogin.php" method="post">
<fieldset class="parametri">
<legend>Dati per l'accesso:</legend>
<table>
<tr>
<td class="ricercaTelefono"><label for="username" accesskey="n">Nome: </label></td>
<td class="ricercaTelefono"><input class="campiform" tabindex="1" type="text" id="username" name="username" size="10" maxlength="20"/></td>
</tr>
<tr>
<td class="ricercaTelefono"><label for="psw" accesskey="p">Password: </label></td>
<td class="ricercaTelefono"><input class="campiform" tabindex="2" type="password" id="psw" name="psw" size="10" maxlength="20"/></td>
</tr>
<tr>
<td colspan="2" ><input type="submit" value="Log-in" tabindex="3" /></td>
</tr>
</table>
</fieldset>
</form>
</div>
<?php
fine_pagina();
?>
Il secondo file l'ho chiamato actionlogin.php::
<?php
include ("crypta.php");
session_start();
if ((!empty ($_POST['username']))&&(!empty($_POST['psw']))&& (isset($_POST['username']))&&(isset($_POST['psw']))){
$username=$_POST['username'];
$psw=$_POST['psw'];
$pswCrypt=cripta($psw);
$link=db_connect();
if ($link){
select_db("mio",$link);
$result=mysql_query("SELECT idUser FROM anagrafica WHERE username='".$username."' and password='".$pswCrypt."';");
if (mysql_num_rows($result)==1) {
list($_SESSION['utente'])= mysql_fetch_row($result);
close_db ($link);
header("Location:menu.php");
}else{
close_db($link);
session_destroy();
header("Location:index.php");
}
}else{
session_destroy();
echo "problemi con collegamenti mysql!! O manca mysql o il firewall blocca o l\'antivirus rompe!";
}
}else{
session_destroy();
header ("Location:index.php");
}
?>
il terzo file invece l'ho chiamato menu.php::
<?php
session_start();
if(((isset($_SESSION['utente']))||(!empty($_SESSION['utente'])))||(is_numeric($_SESSION['utente']))){
include ("crypta.php");
$link=db_connect();
select_db("mio",$link);
$user=$_SESSION['utente'];
$query=mysql_query("SELECT tipouser.idtipo FROM anagrafica,tipouser,personatipo WHERE anagrafica.iduser='".$user."'and anagrafica.iduser=personatipo.iduser and tipouser.idtipo=personatipo.idtipo");
if (mysql_num_rows($query)==1) {
$utente=mysql_fetch_array($query,MYSQL_NUM);
close_db($link);
include("Template/elementiHTML.php");
prima_riga("Menu generale");
add_css("Stile/generale.css");
close_prima_riga();
echo "<div class=\"boxmenu\">";
switch ($utente[0]){
case $utente[0]==1://caso utente normale
break;
case $utente[0]==2://caso amministratore
break;
case $utente[0]==3://caso operatore
echo"
break;
default:
echo "
Problemi seri!!</p>";
}
echo"</div>";
fine_pagina();
}else{
session_destroy();
header("Location:index.php");
//echo "problemi in query!!";
}
}else{
header("Location:index.php");
}
?>

Rispondi quotando