Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    Apr 2014
    Messaggi
    323

    Problema con le sessioni in alcune pagine

    Salve, ho questi due file:
    admin.php
    codice:
    <?php
    if(!isset($_SESSION['login']))
    {
        header("location: login.php");    
    }else
    {    
        if($_SESSION["level_access"] == 1)
        {
        
        }else
        {
         header("location: index.php");
        }
    }?>
    e questa e la pagina che non vuole fungere con il controllo della sessione.

    ma in tutte le altre pagine funziona tranquillamente..

    ma solo in questa:

    post_del.php
    codice:
    <?php
    session_start();
    include("inc.php"); 
    include("admin.php"); 
    include("layout/template.php");
    layout_header();
    ?>
    <?php
    if(empty($_GET["id"]))
    {
        echo '403';
    }else
    {
    ?>
    <?php
    try {
    
    
        
        $query = "select * from post where id =:id";
        $stmt = $db->prepare( $query );
        
        
        $stmt->bindParam(':id', $_GET['id'], PDO::PARAM_INT);
        
        
        $stmt->execute();
        
        $row = $stmt->fetch(PDO::FETCH_ASSOC);
        
        
        if($row > 0)
        {
            $id = $row['id'];
        
        }else
        {
            $msg = "404";
        }
        
    }catch(PDOException $exception){ 
        echo "Error: " . $exception->getMessage();
    }
        
    
    
    ?>
    <?php
    if(isset($error)){ echo "<p class=\"info_error\">".$error."</p>";}
    if(isset($msg)){ echo $msg;} else {
    ?>
    <?php
        try {
    
    
            
            $query = "DELETE FROM post WHERE id = :id";
            $stmt = $db->prepare( $query );
        
            $stmt->bindParam(':id', $_GET['id'], PDO::PARAM_INT);  
            
            if($stmt->execute())
            {
                    header("location: post.php");
            }
            else
            {
                echo 'Error';
            }
            
        }catch(PDOException $exception){ 
            echo "Error: " . $exception->getMessage();
        }
    ?>
    <?php
        }
    }
    layout_footer();
    ?>
    idea perché questa pagina non prende bene il controllo dell'admin?

    grazie mille,
    e buona serata.

  2. #2
    Cosa dovrebbe fare lo script? Reindirizzarti alle pagine? Prova a mettere "exit;" dopo gli header

  3. #3
    Utente di HTML.it
    Registrato dal
    Apr 2014
    Messaggi
    323
    dovrebbe non far cancellare il record se l'utente ha il ruolo 2.

    ma come dicevo .. le altre pagine con lo stesso codice:
    codice:
    <?php
    session_start();
    include("inc.php"); 
    include("admin.php"); 
    include("layout/template.php");
    layout_header();
    ?>
    funziona.. e solamente nelle pagine del .. dove forse arriva prima il parametro $_GET.

    ma non posso usare la funzione exit(); perché mi bloccherebbe tutto..

    ripeto le altre pagine con lo stesso codice funziona..

    idea come mai?


    grazie mille. e buona serata.

  4. #4
    Utente di HTML.it
    Registrato dal
    Apr 2014
    Messaggi
    323
    questo è il login:

    uso il sistema PDO.
    codice:
    <?php    
        include("inc.php");
        session_start();
        if(isset($_POST['login'])){
    
    
        $password = $_POST["password"];
    
    
        
        $username =  $_POST['username'];
        
        if(empty($username))
        {
            $error = "Username non inserito";
            
        }elseif(empty($password))
        {
            $error = "Password non inserita";
        }
        else
        {
            $md5_password = md5($_POST["password"]);
            $query = $db->prepare("SELECT * FROM users WHERE username=:username AND password=:password");
            $query->bindParam(':username', $_POST['username']);
            $query->bindParam(':password', $md5_password);
    
    
           $query->execute();
    
    
            if($row = $query->fetch()){
                $_SESSION['username'] = $row['username'];
                $_SESSION['level_access'] = $row['level_access'];
                $_SESSION["login"] =true;
                header("Location: index.php");
            }else
            {
                echo 'ERROR';
            }
        }
    }
    ?>
    <!DOCTYPE html>
    <html>
    <meta charset="utf-8">
    <head>
    <title>Login</title>
    </head>
    <link href="css/admin.css" rel="stylesheet" type="text/css">
    <body>
    <div id="admin">
    <h2>Amministratore</h2>
    <img src="img/login.png">
    <br /><br />
    <?php
      if(isset($error)){ echo "<p class=\"info_error\">".$error."</p>";}
    if(isset($msg)){ echo $msg;} else {
    ?>
    <form method="POST">
    <table align="center">
    <tr>
    <td>Username</td>
    <td><input type="text" name="username" value="<?php if(isset($_POST['username'])){echo htmlspecialchars($_POST['username']);}?>"></td>
    </tr>
    <tr>
    <td>Password</td>
    <td><input type="password" name="password" value="<?php if(isset($_POST['password'])){echo htmlspecialchars($_POST['password']);}?>"></td>
    </tr>
    <tr>
    <td></td>
    <td><input type="submit" name="login" value="Accedi"></td>
    </tr>
    </table>
    </form>
    <?php
    }
    ?>
    <p><a href="forgot.php">Recupera Password</a></p>
    </div>
    </body>
    </html>
    non so se c'entra questo.....

    grazie mille.

  5. #5
    Utente di HTML.it
    Registrato dal
    Apr 2014
    Messaggi
    323
    questo è il file che può entrare l'1 e il 2.

    codice:
    <?php 
    if(!isset($_SESSION['login'])){
        header("location: login.php");    
    }else
    {    
        if($_SESSION["level_access"] == 1 or $_SESSION["level_access"] == 2)
        {
        
        }else
        {
         header("location: index.php");
        }
    }?>

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.