Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP redirect if not logged in [closed]

Tags:

redirect

php

I have been trying to make this following functionality work on my website, however I'm kinda struggling with it. Perhaps one of you can help me out?

I am developing a website which must be inaccessible (except the login of course) unless you are logged in. I was trying to make an automatic redirect to the login page if the user isn't logged in. I'm using HTML, CSS, and PHP at the moment.

If my remaining source is needed please tell me, I'll temporarily host the site online.

like image 415
J.I.N Kleiss Avatar asked May 24 '13 13:05

J.I.N Kleiss


1 Answers

If you're not using any frameworks, try simply:

if(!isset($_SESSION['login'])){ //if login in session is not set
    header("Location: http://www.example.com/login.php");
}

The session parameter and the redirect location depends on the architecture that you're using on your web project.

like image 181
Dropout Avatar answered Sep 20 '22 16:09

Dropout