session.php 564 B

123456789101112131415161718192021
  1. <!--
  2. Include this file everywhere to check if there is a session. Like so:
  3. $root = $_SERVER['DOCUMENT_ROOT'];
  4. include('util/session.php');
  5. -->
  6. <?php
  7. include($root . "/util/config.php");//loads database stuff
  8. if(session_id() == '')
  9. {
  10. session_start();
  11. }
  12. if(!isset($_SESSION['login_user'])){
  13. header("Location: ../login.php");
  14. die();
  15. }
  16. $check_user=$_SESSION['login_user'];
  17. $sql = mysqli_query($db,"select username from users where username = '$check_user'");
  18. $row = mysqli_fetch_array($sql,MYSQLI_ASSOC);
  19. $login_session = $row['username'];
  20. ?>