Accesso riservato

  • Creatore Discussione Creatore Discussione Trapano
  • Data di inizio Data di inizio

Trapano

Utente Attivo
27 Set 2012
238
0
16
49
Ciao a tutti e già che ci sono buone feste...

Avrei un quesito da esporre.
5 File per un accesso riservato in php
1File Index.htm
Codice HTML:
HTML:
<html>
<head>
<title>Accesso riservato</title>
</head>

<body bgcolor="#42FFF9">

<br><br><br><br><br>
<table align="center" bgcolor="red" border="0" height="" width="500" cellpadding="0" cellspacing="0">
<tr align="center">
<td align="center">
<p style="margin-top: 0pt; margin-bottom: 0pt;" align="center">
<font color="yellow" size="6"><b>AREA PERSONALE</b></font><br>
<font color="yellow" size="3">utilizza le password assegnate<br><br><br><br>

<form method=POST action=login.php>
<input type=password name=user  size=20>
<input type=password name=pass  size=20>
<input type=submit value=Login>
<input type=reset value=Reset></form></font></p><br>
</td>
</tr>
</table>

</body>
</html>
2 file login.php
Codice PHP:
PHP:
<php? 

session_start(); 
include 'conf.php'; 
$user= $_POST['user']; 
$pass= $_POST['pass']; 

if((!$user) || (!$pass)){ 
echo "Inserire tutte le informazioni!"; 
header("Location: index.htm"); 
}else{ 
if($user==$usern && $pass==$passw){  
$_SESSION['username'] = $usern; 
header("Location: situazione.php"); 
}else{  
header("Location: index.htm"); 
} 
} 
?>
3 file conf.php
Codice PHP:
PHP:
<php? 
$usern= 'username' ; 
$passw= 'password' ; 
?>
4 file situazione.php che non sto a inserire
5 file logout che non sto a inserire.

Tutto funziona se nei campi inserisco i dati che scrivo in conf.php
ma se io volessi che quei dati, venissero da un db?
il db lo vorrei tipo questo....
campo id = 1
campo psw = a
campo id = 2
campo psw = b
campo id = 3
campo psw = c
ecc...
in modo che tutte e tre le persone possano entrare con i loro dati.
Spero di essermi spiegato.
 
Ultima modifica di un moderatore:
ciao
se non ho capito male, ti fai una tabella utenti (immagino che tu usi mysql) tipo
id int(12) autoincrement primary key
user warchar(50)
pass warchar(50)
... e altri campi che ti possono servire
e poi la interroghi
PHP:
<?php 
session_start();
//dati di connessione al database
include 'conf.php'; 
$user= $_POST['user']; 
$pass= $_POST['pass']; 
if((!$user) || (!$pass)){ 
	header("Location: index.htm");
	exit(); 
}else{
	//fai la query alla tabella
	$q=mysql_query("SELECT * FROM utenti WHERE user='$user' AND pass='$pass'");
	if(mysql_num_rows($q)){// verifichi che esistano
 		$_SESSION['username'] = $usern; 
		header("Location: situazione.php");
		exit();
	}
	header("Location: index.htm"); 
	exit();
} 
?>
ricorda che la password andrebbe salvata criptata per motivi di sicurezza
 
ciao
scusa errore di copy/paste
se nel file config hai le vecchie/a user e pass non serve più user e pass sono in tabella db
eventualmente usalo per inserire i dati di connessione al db che forse ti servono anche in altre pagine
 
Provato e con i dati giusti, indirizza alla pagina situazione.php

Ma resta bianca....
PHP:
<?php
include 'conf.php';
session_start();
if ($_SESSION['username']==$usern) ;
else{ 
header("Location: index.htm");
}

 { ?>
 <html>
<head>
<title>Situazione cliente</title>
</head>
<body bgcolor="#42FFF9">

<?php 
include_once ("../config.php");  
include_once ("../connect.php");  

$id= $_POST['id'];

$result = mysql_query("SELECT * FROM oggetti WHERE id LIKE '$id' OR id_venditore LIKE '$id' OR venduto_a LIKE '$id' ORDER BY venduto_a='$id' , id_venditore='$id' , id='$id'");
$num=mysql_numrows($result);
$diff=($num-1);
$giorno=date('j/m/Y');
ecc...
Questo non va bene? $id= $_POST['id'];
 
ciao
così a occhio ci sono diverse cose che non mi tornano, a parte quel $_POST che non si sa da dove viene.
comunque domani ci do un occhio
 
Oggi, quando l'ho provato... Mi indirizzava alla pagina però bianca. Adesso non funziona nemmeno più. Mi manda alla index di nuovo.
 
Riposto le pagine originali per chiarezza
index.html
PHP:
<html>
<head>
<title>Accesso riservato</title>
</head>

<body bgcolor="#42FFF9">

<br><br><br><br><br>
<table align="center" bgcolor="red" border="0" height="" width="500" cellpadding="0" cellspacing="0">
<tr align="center">
<td align="center">
<p style="margin-top: 0pt; margin-bottom: 0pt;" align="center">
<font color="yellow" size="6"><b>AREA PERSONALE</b></font><br>
<font color="yellow" size="3">utilizza le password assegnate<br><br><br><br>

<form method=POST action=login.php>
<input type=password name=user  size=20>
<input type=password name=pass  size=20>
<input type=submit value=Login>
<input type=reset value=Reset></form></font></p><br>
</td>
</tr>
</table>

</body>
</html>

login.php
PHP:
<?

session_start();
include 'conf.php';
$user= $_POST['user'];
$pass= $_POST['pass'];

if((!$user) || (!$pass)){
echo "Inserire tutte le informazioni!";
header("Location: index.htm");
}else{
if($user==$usern && $pass==$passw){ 
$_SESSION['username'] = $usern;
header("Location: situazione.php");
}else{ 
header("Location: index.htm");
}
}
?>

conf.php
PHP:
<?
$usern= '1667' ;
$passw= 'gTn3tt' ;
?>

situazione.php
PHP:
<?php
include 'conf.php';
session_start();
if ($_SESSION['username']==$usern) ;
else{ 
header("Location: index.htm");
}

 { ?>
 <html>
<head>
<title>Situazione cliente</title>
</head>
<body bgcolor="#42FFF9">

<?php 
include_once ("../config.php");  
include_once ("../connect.php");  

$txt = $usern;
$result = mysql_query("SELECT * FROM oggetti WHERE id LIKE '$txt' OR id_venditore LIKE '$txt' OR venduto_a LIKE '$txt' ORDER BY venduto_a='$txt' , id_venditore='$txt' , id='$txt'");
$num=mysql_numrows($result);
$diff=($num-1);
$giorno=date('j/m/Y');

...

logout.php
PHP:
<?php
include 'conf.php';
session_start();
if ($_SESSION['username']==$usern) { 
session_unset();
session_destroy(); 
echo "Hai effettuato il log out!!";

} ?>
<html>
<head>
<title>GESTIONE DATABASE</title>
<meta http-equiv="refresh" content="2;url=index.htm" />
</head>
</html>
 

Discussioni simili