Search code examples
phpcookiesheaderincludesentence

"include" does not work in "if / else" PHP


I'm trying to include the header for logged in users if they have an active session, if not, show the header for unregistered users! But the problem is that this code does not work, in the browser inspector does not appear any code other than , and the screen is all white. This code is in index.php

<?php
include("db.php");
if (isset($_COOKIE["login"]) && isset($_COOKIE["login2"])) {
        $user_id = $_COOKIE["id"];
        $email = $_COOKIE["login"];
        $password = $_COOKIE["login2"];
        $verify = mysqli_query($connect, "SELECT * FROM users WHERE email='$email' AND password='$password'");
        if (mysqli_num_rows($verify)>=1) {
            include("header_logged.php");
        }else{
            include("header.php");
        }
}
?>

Solution

  • I solved my problem! I had made cookies instead of sessions, now I created sessions and I put the following code and it worked! But thanks to all the answers! `

    session_start();
    
    if ( !isset( $_SESSION['email'] ) ) {
      include( 'header.php' );
      exit();
    }else {
        if ( isset( $_SESSION['email'] ) ) {
            include( 'header_logged.php' );
            exit();
        }        
    }?>`