Salve a tutti....
come da titolo, ho problemi con la mia area privata.... premetto che nn sono un programmatore e mi diletto un po' con il php........ e il problema fondamentale è riprendere lavori vecchi e riadattarli...
tempo fa ho trovato un script per il login e relativa area privata e funziona benissimo, solo che adesso devo aggiungere pagine e mi da sempre errore.....
il form dove inserisco usr e psw mi rimanda alla pagina
autentica.php
Codice PHP:
<?php
session_start(); //..avviamo la sessione...
require_once('Connections/miaConnessione.php');
$username_post=mysql_escape_string($_POST['user']);
$password_post=mysql_escape_string($_POST['psw']);
//Controlliamo se tutti i campi sono compilati
if($_POST['user']== "" || $_POST['psw'] == "" )
//Se alcuni campi non sono compilati...
{
die("Alcuni campi non sono compilati.
<a href=\"javascript:history.back(1)\">Torna indietro</a>"); //...terminiamo lo script e mandiamo un errore all'utente
}
//Impostiamo la query...
mysql_select_db($database_miaConnessione, $miaConnessione);
$query = "SELECT * FROM clienti WHERE user = '$username_post' AND psw = '$password_post' ";
$risultato = mysql_query($query) //...e la eseguiamo
or die("Impossibile eseguire query.
".mysql_error()); //Oppure mandiamo il solito errore
$find = mysql_fetch_assoc($risultato); //Fissiamo la riga
$_SESSION['user'] = $username_post;
$_SESSION['psw'] = $password_post;
//se non c'è un utente con quei dati quindi login errata:
if ($find == 0)
{
header ("Location: error.php");
exit;
}
else {
header ("Location: area_riservata.php?utente=$find[id]");
exit;
}
?>
area_riservata.php
Codice PHP:
<?php
session_start ();
$username = $_SESSION['user'];
if ($_SESSION['user']=="")
header ("Location: error.php");
?>
<?php require_once('Connections/miaConnessione.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$colname_entra = "-1";
if (isset($_GET['utente'])) {
$colname_entra = $_GET['utente'];
}
mysql_select_db($database_miaConnessione, $miaConnessione);
$query_entra = sprintf("SELECT * FROM clienti WHERE id = %s", GetSQLValueString($colname_entra, "int"));
$entra = mysql_query($query_entra, $ConnFilab) or die(mysql_error());
$row_entra = mysql_fetch_assoc($entra);
$totalRows_entra = mysql_num_rows($entra);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
tutto il codice html
</html>
<?php
mysql_free_result($entra);
// Svuoto l'array $_SESSION
$_SESSION = array();
// distruggo la sessione
session_destroy();
?>
fin qui nn avevo nessun problema..... adesso devo fare un link alla pagina ordini.php e mi dice che l'utente nn è loggato.... dove sbaglio?!? Ho fatto un sacco di tentativi...... ma invani.... posto il codice
ordini.php
Codice PHP:
<?php
session_start ();
$username = $_SESSION['user'];
if ($_SESSION['user']=="")
header ("Location: error.php");
?>
<?php require_once('Connections/miaConnessione.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
tutto il codice html
</html>
<?php
// Svuoto l'array $_SESSION
$_SESSION = array();
// distruggo la sessione
session_destroy();
?>
dove sbaglio ?!