Solved

how to create session handling in php?

Posted on 2002-04-02
2
192 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Expert Comment

by:lokeshv
ID: 6914859
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
ID: 6915031
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

738 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