Abdul Waheed Abdul Waheed - 2 months ago 11
HTML Question

Session Values are not coming

I have a homepage.php and messages.php page for both common "menu.php" is there so I have started a session in homepage.php as well as messages.php And I have not started any session in menu page.
i am trying to get these values here is my menu code:

HTML CODE:

<a href="#" class="dropdown-toggle dropdown-at" data-toggle="dropdown"><span class=" name-caret"><?= $_SESSION['name'] ?><i class="caret"></i></span><img src="../images/user/<?= $_SESSION['image'] ?>" style="width:100px; height: 61px;"></a>


HOME PAGE.PHP

<?php
ob_start();
session_start();
if (!isset($_SESSION['id'])) { header('location:index.php'); }
include_once('includes/config.php');
include_once('includes/header.php');
include_once('includes/menu.php');
?>


so I can I show login user data of name and image on the menu for both homepage and messages page.

Answer

You need to use echo in PHP to show values. Like this:

<a href="#" class="dropdown-toggle dropdown-at" data-toggle="dropdown">
  <span class=" name-caret"><?php echo $_SESSION[name]; ?>
    <i class="caret"></i>
  </span>
  <img src="../images/user/<?php echo $_SESSION[image]; ?>" />
</a>