Solved

how to create session handling in php?

Posted on 2002-04-02
2
186 Views
Last Modified: 2010-05-18
hai,

I want to restrict the users from directly accessing my other pages.ie they should go only thru my login page.
how to ensure this thru session handling in php.
can anyone solve me this issue.


thank you
manju
0
Comment
Question by:manju70
2 Comments
 
LVL 4

Expert Comment

by:lokeshv
Comment Utility
just register a SESSION veriable like SESSION_ID on ur login page and make entry of that in database. and now keep check that SESSION id on every page....



Hope this will help

LK

0
 
LVL 5

Accepted Solution

by:
andriv earned 30 total points
Comment Utility
It depends on what the content is. I think the easiest but efficient way of handling it is to create an error page with login form:

Access Denied, Please provide a valid username and password:



On all the pages you want to secure look for the session you set to validate access, if the session does not exist redirect them to the error page.

For example add this to the top of all the pages:

<?
session_start();

if(!isset($session_variable)) // if($session_variable != "whatever"
{
header("Location: path/to/error.php");
}
?>


If the session does was not set they will be immediately redirected to the error page.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now