Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use a PHP Session variable in a dynamically loaded navbar?

Tags:

php

I have a series of pages that load a navbar from an external HTML file like so:

<head>
<script>
  $(function() {
  $("#navbar").load("navbar.html");
  });
</script>
</head>
<body>
<div id="navbar"></div>
<!--other stuff here-->

This is all in a PHP page. However, there's part of that navbar that I want to set to set to a PHP $_SESSION variable (a username). Is there a way to easily do this?

like image 590
Charles Byrne Avatar asked Dec 21 '25 23:12

Charles Byrne


1 Answers

Consider change navbar.html to navbar.php, then replace the username part by:

<?php echo($_SESSION["username"] ?>

then

$("#navbar").load("navbar.php");
like image 179
xdazz Avatar answered Dec 23 '25 14:12

xdazz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!