Jump to content

Stopping non-logged in users viewing other pages


Smee

Recommended Posts

Hey,

 

I have a working site but realise i have not added enough security because users who are not logged in, if they know that /attending.php is a page to the site then they can access it even though they cannot use the functions of the page.

 

I cant find a lot on redirecting for non logged in users on the net so thought i would try here, has anyone got a tutorial or suggestions on how this can be implemented where if they try access these restricted pages they get taken to the /login.php.

 

Thanks in advance!

Link to comment
Share on other sites

If you use sessions to manage your users, you could add this to the very top of each page.

 

<?php
session_start();
if (!isset($_SESSION['username'])){
   header("location:login.php");
}
?>

 

It checks if there is a $_SESSION variable called 'username' and if there isn't, it redirects the user to login.php

 

 

Zagga

Link to comment
Share on other sites

A header() redirect tells a browser (or a script that has been told to follow redirects) to request the URL that is in the header statement. Without an exit; statement to stop the php script, the rest of the html/php code on the 'protected' page is still processed and output by the web server.

 

Most hackers use scripts to access your web pages. They have to specifically configure such a script to follow any header() redirect. If you don't and ignore the redirect and there is no exit; statement, the result is the same as if a logged in user accessed the 'protected' page.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.