0

Notice: A session had already been started - ignoring session_start() in /home/user/public_html/finalweb/header.php on line 3

the session was started in my login file as seen below

<?php
ini_set("session.save_path", "/home/unn_w22016721/sessionData");
session_start();

the session variable was created in the same login file after login checks were complete as seen below

if (!array_filter($errors)) {

        $Username = mysqli_real_escape_string($conn, $_POST['username']);
        $pwd = mysqli_real_escape_string($conn, $_POST['Password']);
        $_SESSION['logged-in'] = true;
        if ($_SESSION['logged-in']) {
            # code...
            $_SESSION['username'] = $Username;
            // echo "session has been set";
            // echo $_SESSION['username'];
            header("location: index.php");
          
        }
       

    }

the session variable is called in the header/navbar file as seen below

<?php
ini_set("session.save_path", "/home/unn_w22016721/sessionData");
    session_start();

?>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Home</title>
<!-- css -->
    <link rel="stylesheet" type="text/css" href="style.css">
    <!-- Google fonts -->
 
    <link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Montserrat&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,400;0,500;0,600;1,500&display=swap" rel="stylesheet">      
      <!-- font awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" integrity="sha512-xh6O/CkQoPOWDdYTDqeRdPCVd1SpvCA9XXcUnZS2FmJNp1coAFzvtCN9BmamE+4aHK8yyUHUSCcJHgXloTyT2A==" crossorigin="anonymous" referrerpolicy="no-referrer">

    </head>
<body>

    <header>

        <nav class="nav-bar">
            <div class="logo">
                <h1 ><a class="Company" href="index.html">East Experience</a></h1>
                <!-- closing tag for Company -->
            </div>
        
        
           
                <ul class="nav-items">
                    <li><a href="index.php">Home</a></li>
                    <li><a href="about.php">About</a></li>
                    <li><a href="Design-Notes.pdf" target="_blank">Wireframes</a></li>
                    <li><a href="CREDITS.pdf">Credits</a></li>
                    <li><a href="destinations.php">Destination</a></li>
                    <?php 

                        if (isset($_SESSION['logged-in])) {
                            # code...
                            echo "<li><a href='book.php'>Book</a></li>";
                            echo " <li><a href='logout.php'>Log out</a></li>";
                        } else{
                            echo "<li><a href='signup.php'>Sign up</a></li>";
                            echo " <li><a href='login.php'>Log in</a></li>";
                        }

                    ?>
                    <!-- <li><a href='signup.php'>Signup</a></li>
                    <li><a href="login.php">login</a></li> -->
                    <!-- <li><a href="details.html"><Details></Details></a></li> -->

                </ul>
        
        
        <!-- closing tag for nav section -->
        </nav>
            </header>

I tried to remove the session_start() in the header file but then my dynamic changes were'nt taking effect. i'm not sure how to fix this error because i know the session has to be called in any page i'm going to use it. Please i'll appreciate any suggestions as i'm very new to php, thanks!

Jindu
  • 1
  • 1
    Probable [duplicate](https://stackoverflow.com/questions/6249707/check-if-php-session-has-already-started) – berend Dec 16 '22 at 19:50

0 Answers0