Script Problem with PHP Checking Session

Asked

Viewed 64 times

1

I have a form but it is hidden only when clicking a button located on the Nav is called that function:

<script>
 function verifLog(){
 <?php 
 session_start(); 
 if (isset($_SESSION['user'])){
   echo "<script> 
   document.location.href ='logOn.php';
  </script>";
  } else {
   echo "<script> 
   document.getElementById('enter').style.display='block';
  </script>";
  }
 ?>
 }
 </script>

But this isn’t working. Someone knows the mistake that happens here?

1 answer

2


So it works cool, tip, try to keep your javascript in a separate php file.

<?php
session_start();
function verifLog() {
   if (isset($_SESSION['user'])) {
      header('Location: logOn.php');
   } else {
      ?>
      <script>
         document.getElementById('enter').style.display = 'block';
      </script>
      <?php

   }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.