Jump to content

Recommended Posts

I am trying to include a php header file to my page but it is not working.

 

<?php
	session_start();
	include("header.php");
	$the_email = $_GET['email'];
	$_SESSION['user_email'] = $the_email;
?>

and header have a navbar

header.php

<?php 
	session_start(); 
  	$authenticated = false;
  	$isadmin = false;	

  if ($_SESSION['user'])
  {
    $thename = $_SESSION['user_name'];
    $theimage = $_SESSION['user_photo'];
    $authenticated = true;
    $isadmin = false;
  }


  if ($_SESSION['admin'])
  {
    $thename = $_SESSION['admin_name'];
    $authenticated = true;
    $isadmin = true;
  }
?>


<!doctype html>
<html lang="en">

<head>
  <!-- Required Meta Tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <!-- Document Title, Description, and Author -->
  <title>Teacher License System</title>
  <meta name="description" content="Wave is a Bootstrap 5 One Page Template.">
  <meta name="author" content="BootstrapBrain">

  <!-- Favicon and Touch Icons -->
  <link rel="icon" type="image/png" sizes="512x512" href="./assets/favicon/favicon-512x512.png">

  <!-- Google Fonts Files -->
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Oswald:wght@200;300;400;500;600;700&family=Satisfy&display=swap" rel="stylesheet">

  <!-- CSS Files -->
  <link rel="stylesheet" href="./assets/css/wave-bsb.css">

  <!-- BSB Head -->
</head>

<body data-bs-spy="scroll" data-bs-target="#bsb-tpl-navbar" data-bs-smooth-scroll="true" tabindex="0">
  <!-- Header -->
  <header id="header" class="sticky-top bsb-tpl-header-sticky bsb-tpl-header-sticky-animationX">

    <!-- Navbar 1 - Bootstrap Brain Component -->

    <nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container">
    <a class="navbar-brand" href="index.php">
      <img src="/assets/img/logo.png" width="40" height="40" class="d-inline-block align-top" alt="">
      TLS CS C2&3
    </a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon">test</span>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">
          <a class="nav-link text-dark" href="index.php">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link text-dark" href="about.php">About</a>
        </li>
        <li class="nav-item">
          <a class="nav-link text-dark" href="services.php">Services</a>
        </li>
        <li class="nav-item">
          <a class="nav-link text-dark" href="pricing.php">Pricing</a>
        </li>
        <li class="nav-item">
          <a class="nav-link text-dark" href="contact.php">Contact US</a>
        </li>
       
      </ul>

      <?php 
        if ($isadmin) { 
      ?>
      <ul class="navbar-nav">
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle text-dark" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
            Hello, <?= $thename ?>
          </a>
          <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
            <li><a class="dropdown-item" href="main.php">TLS Materials</a></li>
            <li><hr class="dropdown-divider"></li>
            <li><a class="dropdown-item" href="logout.php">Logout</a></li>
          </ul>
        </li>
      </ul>
      <?php 
      } else if ($authenticated) {  
      ?>
      <img src='/files/<?=$theimage ?>' width="75px">
      <ul class="navbar-nav">
        
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle text-dark" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false"><?= $thename ?>
          </a>
          <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
	    <li><a class="dropdown-item" href="profile.php">My Profile</a></li>
            <li><a class="dropdown-item" href="main.php">TLS Materials</a></li>
            <li><hr class="dropdown-divider"></li>
            <li><a class="dropdown-item" href="logout.php">Logout</a></li>
          </ul>
        </li>
      </ul>
      <?php } else {?>
        <ul class="navbar-nav">
        <li class="navbar-item">
          <a href="register.php" class="btn btn-outline-primary me-2">Register</a>
        </li>
        <li class="navbar-item">
          <a href="login.php" class="btn btn-primary">Login</a>
        </li>
      </ul>
      <?php } ?>
    </div>
  </div>
</nav>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
    
  </header>

why is that? Am i missing something?

Link to comment
https://forums.phpfreaks.com/topic/327507-include-not-working/
Share on other sites

telling us that something doesn't work is pointless. we are not sitting next to you and didn't see what symptom or error you got that leads you to believe something didn't work. you must tell or show us what result you got and what the expected result should be.

do you have php's error_reporting set to E_ALL and display_errors set to ON, preferably in the php.ini on your system, so that php will help you by reporting and displaying all the errors it detects?

have you checked in the browser's developer tools, console tab for errors?

you should use 'require' for things your code must have. require/include are not functions. the () around the path/filename do nothing and should be removed.

$_GET['email'] is an input to your code. it may not exist. you need to use isset() to prevent errors when it doesn't exist and you must trim, then validate it before using it, when it does exist.

the two session variables are also inputs to your code. they may not exist. you need to use isset() to prevent errors when they don't exist.

 

Link to comment
https://forums.phpfreaks.com/topic/327507-include-not-working/#findComment-1653377
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.