Current location: Hot Scripts Forums » Programming Languages » PHP » Login system


Login system

Reply
  #1 (permalink)  
Old 06-09-07, 04:00 AM
pjking pjking is offline
Newbie Coder
 
Join Date: May 2007
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Login system

Hi all,

I'm creating a login system for an administrator section. All works fine, pulling in the admin details in from a database, with conditional statements to go to a secret page if true and redirect back to the login page if false.

What I want to know is how do I stop a user typing the url of the secret page directly into the browser and skipping the login altogether, gaining access to the page without first loging in?

Is there code that will recognise this has happened, and tell the browser to redirect back to the login page?

Cheers
Reply With Quote
  #2 (permalink)  
Old 06-09-07, 04:07 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Have a look at PHP sessions.

PHP Code:



session_start
();

if (
/* Condition to log in user */)
{
    
$_SESSION['logged_in'] = true;

    
header('Location: secret.php');
    exit();

And in secret.php:
PHP Code:

session_start();


if (!isset(
$_SESSION['logged_in']) OR $_SESSION['logged_in'] !== true)
{
    
header('HTTP/1.1 401 Unauthorized');
    exit(
'Unauthorized access');
}

// Secret content... 
Reply With Quote
  #3 (permalink)  
Old 06-09-07, 04:34 AM
pjking pjking is offline
Newbie Coder
 
Join Date: May 2007
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Nico,

Works a treat!

I've also amended the secret code to re-direct back to the login page.

secret page

PHP Code:

session_start();

    if (!isset(
$_SESSION['logged_in']) OR $_SESSION['logged_in'] !== true)
    {
        
header('Location:admin.php');
        exit();
    } 

Last edited by UnrealEd; 06-09-07 at 04:41 AM. Reason: please use the [php] wrapper when posting php code
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Login system w/ user rating + comments Anetra Script Requests 0 04-06-06 07:35 PM
Simple PHP login system dennell PHP 2 02-26-06 12:54 AM
Looking for a decent PHP script (login system) to handle clients and orders, ANY1? xero PHP 0 08-29-04 06:22 PM
question about simple login system magsec4 PHP 5 02-23-04 03:35 AM
Need Epinions-lite system in PHP & MYSQL wali001 Job Offers & Assistance 4 01-12-04 06:02 AM


All times are GMT -5. The time now is 06:03 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.