fino a qui ci sono arrivato anch'io ma dopo non riesco a fare modificare la pagina all'utente per poi applicare le modifiche nel mio database mysql ti allego i miei file di login
access-denied.php
Codice PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Access Denied</title> <link href="loginmodule.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>Accesso negato </h1> <h1>Accesso negato </h1> <h1>Accesso negato </h1> <h1>Accesso negato </h1> <h1>Accesso negato </h1> <h1>Accesso negato </h1> <h1>Accesso negato </h1> <h1>Accesso negato </h1> <h1>Accesso negato </h1> <h1>Accesso negato </h1> <h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1> <p align="center"></p> <h4 align="center" class="err">Accesso negato
Non hai i permessi per accedere</h4> </body> </html>
auth.php
Codice PHP:
<?php
//Start session
session_start();
//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID']) == '')) {
header("location: access-denied.php");
exit();
}
?>
config.php
Codice PHP:
<?php
define('DB_HOST', 'xxxx');
define('DB_USER', 'xxxxx');
define('DB_PASSWORD', 'xxxxxxx');
define('DB_DATABASE', 'xxxxx');
?>
index.php
Codice PHP:
<style>
#loading{
position:absolute;
width:200px;
height:100px;
left:300px;
top:180px;
z-index:1;
background-color: #6B718B;
font:40px Times new roman, Helvetica, sans-serif;
color:#ffffff;
padding:20px;
}
</style>
<div id="loading">Caricamento...</div>
<script>
function finish(){
document.getElementById("loading").style.visibility = "hidden";
}
</script>
<body onload="finish()">
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
<h1>Benvenuto</h1>
<h4>login [url="login-form.php"]qui[/url]|registrati [url="register-form.php"]qui[/url]
login-exec.php
Codice PHP:
<?php
//Start session
session_start();
//Include database connection details
require_once('config.php');
//Array to store validation errors
$errmsg_arr = array();
//Validation error flag
$errflag = false;
//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
//Sanitize the POST values
$login = clean($_POST['login']);
$password = clean($_POST['password']);
//Input Validations
if($login == '') {
$errmsg_arr[] = 'Login ID persa';
$errflag = true;
}
if($password == '') {
$errmsg_arr[] = 'Password persa';
$errflag = true;
}
//If there are input validations, redirect back to the login form
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: login-form.php");
exit();
}
//Create query
$qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'";
$result=mysql_query($qry);
//Check whether the query was successful or not
if($result) {
if(mysql_num_rows($result) == 1) {
//Login Successful
session_regenerate_id();
$member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['member_id'];
$_SESSION['SESS_FIRST_NAME'] = $member['firstname'];
$_SESSION['SESS_LAST_NAME'] = $member['lastname'];
session_write_close();
header("location: member-index.php");
exit();
}else {
//Login failed
header("location: login-failed.php");
exit();
}
}else {
die("Query failed");
}
?>
login-failed.php
Codice PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Login Failed</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Login fallito</h1>
<p align="center"></p>
<h4 align="center" class="err">Login Fallito
Controlla la tua username e/o la tua password</h4>
</body>
</html>
loginmodule.css
Codice PHP:
body {
font: 11px Verdana, Arial, Helvetica, sans-serif;
color: FF0000;
margin: 0px;
padding: 20px 10px 0px;
}
.textfield {
font-size: 11px;
color: FF0000;
background: #F7F7F7;
border: 1px solid #CCCCCC;
padding-left: 1px;
}
h1 {
color: #99CC00;
margin: 0px 0px 5px;
padding: 0px 0px 3px;
font: bold 18px Verdana, Arial, Helvetica, sans-serif;
border-bottom: 1px dashed #E6E8ED;
}
a {
color: #2D3954;
font-size: 11px;
}
a:hover {
color: #99CC00;
}
.err {
color: #FF9900;
}
th {
font-weight: bold;
text-align: left;
}
logout.php
Codice PHP:
<?php
//Start session
session_start();
//Unset the variables stored in session
unset($_SESSION['SESS_MEMBER_ID']);
unset($_SESSION['SESS_FIRST_NAME']);
unset($_SESSION['SESS_LAST_NAME']);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Logged Out</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Logout </h1>
<p align="center"></p>
<h4 align="center" class="err">logout eseguito</h4>
<p align="center">clicca qui per il [url="login-form.php"]Login[/url]</p>
</body>
</html>
register-exec.php
Codice PHP:
<?php
//Start session
session_start();
//Include database connection details
require_once('config.php');
//Array to store validation errors
$errmsg_arr = array();
//Validation error flag
$errflag = false;
//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
//Sanitize the POST values
$fname = clean($_POST['fname']);
$lname = clean($_POST['lname']);
$login = clean($_POST['login']);
$password = clean($_POST['password']);
$cpassword = clean($_POST['cpassword']);
//Input Validations
if($fname == 'bill') {
$errmsg_arr[] = 'tu non ti chiami bill gates';
$errflag = true;
}
if($lname == 'gates') {
$errmsg_arr[] = 'sisi e io sono tua nonna XDDDD';
$errflag = true;
}
if($login == '') {
$errmsg_arr[] = 'Non hai inserito la tua login id';
$errflag = true;
}
if($password == '') {
$errmsg_arr[] = 'Non hai inserito la tua password';
$errflag = true;
}
if($cpassword == '') {
$errmsg_arr[] = 'Non hai la conferma password';
$errflag = true;
}
if( strcmp($password, $cpassword) != 0 ) {
$errmsg_arr[] = 'Le password non corrispondono';
$errflag = true;
}
//Check for duplicate login ID
if($login != '') {
$qry = "SELECT * FROM members WHERE login='$login'";
$result = mysql_query($qry);
if($result) {
if(mysql_num_rows($result) > 0) {
$errmsg_arr[] = 'Login ID already in use';
$errflag = true;
}
@mysql_free_result($result);
}
else {
die("Query failed");
}
}
//If there are input validations, redirect back to the registration form
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: register-form.php");
exit();
}
//Create INSERT query
$qry = "INSERT INTO members(firstname, lastname, login, passwd) VALUES('$fname','$lname','$login','".md5($_POST['password'])."')";
$result = @mysql_query($qry);
//Check whether the query was successful or not
if($result) {
header("location: register-success.php");
exit();
}else {
die("Query failed");
}
?>
register-form.php
Codice PHP:
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Login Form</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) {
echo '<ul class="err">';
foreach($_SESSION['ERRMSG_ARR'] as $msg) {
echo '[*]',$msg,'';
}
echo '[/list]';
unset($_SESSION['ERRMSG_ARR']);
}
?>
<form id="loginForm" name="loginForm" method="post" action="register-exec.php">
<table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
<tr>
<th>Nome (non obligatorio)</th>
<td><input name="fname" type="text" class="textfield" id="fname" /></td>
</tr>
<tr>
<th>cognome (non obligatorio)</th>
<td><input name="lname" type="text" class="textfield" id="lname" /></td>
</tr>
<tr>
<th width="124">Login id (username)</th>
<td width="168"><input name="login" type="text" class="textfield" id="login" /></td>
</tr>
<tr>
<th>Password</th>
<td><input name="password" type="password" class="textfield" id="password" /></td>
</tr>
<tr>
<th>Ripeti password </th>
<td><input name="cpassword" type="password" class="textfield" id="cpassword" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="Submit" value="Register" /></td>
</tr>
</table>
</form>
</body>
</html>
register-success.php
Codice PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Registration Successful</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Registrazione completata</h1>
[url="login-form.php"]Clicca qui[/url]per loggarti</p>
</body>
</html>
gli utenti che possiedo ora (per prova) sono seingh (con la rispettiva password) e leizaR (con la rispettiva password)