0

I have two navbars : one is included on login and another in guest situation. the if condition in javascript works well if user logged in or not but the condition in php dosen't.. it always gives the first condition whatever im logged in or not and gives me the logged in navbar. what seems to be the problem.

<?php
      $loginCheck = 0;
?>
<script type="text/javascript">
    firebase.auth().onAuthStateChanged((user) => {
        if (user) {
            // User is signed in, see docs for a list of available properties
            var uid = user.uid;
            currentUser = user;
            console.log(user.email + " has logged in");
            <?php $loginCheck = 1; ?>
            $( document ).ready(function() {
                console.log( "testing.." );
                console.log(user);
                console.log(user.displayName);
                document.getElementById('userName').innerHTML = user.displayName;
            });
            // ...
        } else {
            // User is signed out
            // ...
            console.log("signed Out")
        }
    });
</script>
<?php
if ($loginCheck == 1) {
     include "navbarOnLogin.php";
} else {
     include "guestNavbar.php";
}
?>
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149

0 Answers0