-1
    <?php
  session_start();
  if (empty($_SESSION['id'])) {
    $_SESSION['errMsg'] = '<div class="alert alert-danger" role="alert">
    <strong>Post:</strong> You must be logged in `enter code here`in order to post.
    </div>';
    header('Location: ../../index.php');
    exit;
  }
?>

It just doesn't redirect me to index.php, which is in the proper place, even though the session doesn't exist.

3 Answers3

0

I understand your redirect problem

From the above code

header('Location: ../../index.php');

Your project is example.com/testfolder/view.php

Make change the Path and If your index.php is in previous folder means simply add

../index.php

Likewise monitor and set your path in the header.

Sankar Smith
  • 338
  • 1
  • 5
  • 14
0

Just Try :-

header('Location: http://myhost.com/mypage.php');

PHP header()

Aman Kumar
  • 4,533
  • 3
  • 18
  • 40
0
    <?php
  session_start();
  if (!isset($_SESSION['id'])) {
    header('Location: ../../index.php');
    exit;
  }
?>

I fixed it, I don't know how, but it works now. This is the code I use now

  • please read here http://stackoverflow.com/questions/7191626/isset-and-empty-what-to-use then you will understand why does it work now – Masivuye Cokile Feb 21 '17 at 08:24