Sessioni???

MikiProgrammer

Utente Attivo
9 Mag 2015
63
2
8
Ho queste due pagine e, anche se creo la sessione "login_effettuato", non me la legge!

Login:

Codice:
<?php
session_start();
ob_start();
error_reporting(E_ALL);
echo "
<html>
<head>
<title>Login Chatter</title>
</head>
<body>";
$username = $_POST['usrlog'];
$password = $_POST['pswlog'];
$ricordami = isset($_POST['ricordami']) ? $_POST['ricordami'] : 'no';
if (!preg_match("/^[a-z0-9]{4,12}$/i", $username)) {
    header('location: index.php?error=1');
    exit;
}
if (!preg_match("/^[a-z0-9]{4,12}$/i", $password)) {
    header('location: index.php?error=2');
    exit;
}
include('db_conn.php');
$sql = "SELECT * FROM users WHERE username = '" . $username . "'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
if ($row['username'] !== $username){
    header('location: index.php?error=3');
    exit;
}
if ($row['password'] !== sha1($password)){
    header('location: index.php?error=4');
    exit;
}
if ($ricordami == 'si'){
    setcookie('ricordami', $username . " " . sha1($password), time()+13405824000);
}
$_SESSION['login_effettuato'] = $row['username'];
$_SESSION['id_login'] = $row['id'];
header('location: https://www.chatternetwork.it/users/' . $username . '/');
?>
</body>
</html>

Pagina:

Codice:
<?php
session_start();
ob_start();
error_reporting(E_ALL);
function get_current_url() {
  $url  = 'http' . ($_SERVER['HTTPS'] == 'on' ? 's' : '') . '://'
        . $_SERVER['SERVER_NAME']
        . $_SERVER['REQUEST_URI'];
  return $url;
}
function paginaErrore(){
    $username = sha1(str_replace('/customers/a/2/9/chatternetwork.it//httpd.www/users/', '', __DIR__));
    header('location: https://www.chatternetwork.it/log.php?next=' . get_current_url() . "&username=" . $username);
    exit;
}
if (!isset($_SESSION['login_effettuato'])){
        echo $_SESSION['login_effettuato'];
    exit;
    paginaErrore();
}
if ($username !== $_SESSION['login_effettuato']){
    paginaErrore();
}
include('../../pagina_utente.php');
?>
 
Visto che ci sono:
Nella directory principale del mio sito ho la pagina "login.php" e "logout.php".
Nella login.php creo un cookie per l'accesso automatico.
Invece nella logout.php dovrei eliminarlo, ma non me lo cancella!
Lo creo così:

PHP:
setcookie('ricordami', $username, time()+13405824000);

Ecco il codice della Logout.php:

PHP:
<?php
session_start();
ob_start();
error_reporting(0);
date_default_timezone_set('Europe/Rome');
?>
<html>
    <head>
        <title>Logout</title>
        <link rel=stylesheet href=stili/logout.css type=text/css>
    </head>
    <body>
<div class=load><img src=immagini/caricamento2.gif alt=Caricamento...></div>
<?php
include('db_conn.php');
$ora_ult_acc= date("H:i");
$data_ult_acc = date("Y:m:d");
$query="UPDATE `users` SET `online` = '0', `ora_ult_acc` = '$ora_ult_acc', `data_ult_acc` = '$data_ult_acc' WHERE `username`='$_SESSION[login_effettuato]'";
mysql_query($query);
if (isset($_COOKIE['ricordami'])){
    $_COOKIE['ricordami'] == null;
}
$_SESSION = array();
header('location: https://www.chatternetwork.it/');
?>
    </body>
</html>
 

Discussioni simili