We help IT Professionals succeed at work.
Get Started

PHP Page Redirection (user logged in test)

edhasted asked
Last Modified: 2012-05-12
Having written a load of web pages I want to put a test at the start of each page to check that the user is logged in. If not take them to the start page.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<?php include("../includes/logged_in_test.php"); ?>

[rest of page follows on...]

with the code for "logged_in_test.php" looking like:

      if (!isset($login_session)) {
            header("Location: ../pages/start.php");
           else {
             return 0; }

The logic clearly works as with the exit(); line in place it blanks the screen but doesn't redirect me to start.php.

Am I doing something wrong or can this be done...

Watch Question
Senior Developer
This problem has been solved!
Unlock 2 Answers and 7 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE