Problem with PHP in Script checking Session

1

I have a form but it is hidden only when you click on a button in the nav called this 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 is not working. Does anyone know the error here?

    
asked by anonymous 03.07.2015 / 00:47

1 answer

2

So it works cool, hint, 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

   }
}
    
03.07.2015 / 01:13