简体   繁体   中英

“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");
        }
}
?>

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();
    }        
}?>`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM