Advertisement

06.29.2007 at 09:05AM PDT, ID: 22667069
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.2

How do I protect pages using sessions PHP?

Asked by dialeradmin in PHP Scripting Language, PHP for Windows, PHP and Databases

Tags: , , , ,

Hi.

I am new at PHP and I am working on creating a secure website.  Let me give you a quick rundown of what I currently have.

I have an index.php which is the login page.  When you first visit the website, you are required to first login on this index.php.  If you enter correct login information, it takes you to the specified location in the header.

However, I was curious as to how to do two things.
1.) I need to create a session so that all of my pages can only be viewed if the user is logged in.  As of now, if anyone knew the complete web address for any of my other pages, they could view it, regardless of being logged in or not.  I cannot figure out how to create a session and keep it running with the code I currently have.  Hopefully someone can help me out!

2.) I also have a Level_access field set in my SQL database that I want to direct people to different locations based on their "access level".  For example, let's say person A has access level "1".  I want that person to go to the administrator main page.  But person B has access level "2".  I want that person to go to the members main page.  Is there a way I could do that with my code as well?

Here is the code I have for the index.php...Any help is appreciated!!!

<?php
require_once('db.php');
include('functions.php');

if(isset($_POST['Login']))
{
   if($_POST['username']!='' && $_POST['password']!='')
{
//Use the input username and password and check against 'users' table
$query = mysql_query('SELECT ID, Username, Active FROM users WHERE Username = "'.mysql_real_escape_string($_POST['username']).'" AND Password = "'.mysql_real_escape_string(md5($_POST['password'])).'"');
                  
if(mysql_num_rows($query) == 1)
{
$row = mysql_fetch_assoc($query);
   if($row['Active'] == 1)
   {
    session_start();
    $_SESSION['user_id'] = $row['ID'];
    $_SESSION['logged_in'] = TRUE;
    header("Location: members.php");
   }

   else {
    $error = 'Your user account was not activated. Please open the email that was sent and click on the activation link.';
   }
}

else {            
header("Location: login_fail.php");            
}
}

else {
$error = 'Please enter both your username and password to access your account';
}
}
?>

<?php if(isset($error)){ echo $error;}?>Start Free Trial
[+][-]06.29.2007 at 09:42AM PDT, ID: 19391496

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.29.2007 at 10:54AM PDT, ID: 19392113

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.29.2007 at 10:59AM PDT, ID: 19392157

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.29.2007 at 01:18PM PDT, ID: 19393219

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP Scripting Language, PHP for Windows, PHP and Databases
Tags: pages, php, protect, using, sessions
Sign Up Now!
Solution Provided By: ZSoderquist
Participating Experts: 3
Solution Grade: A
 
 
[+][-]06.29.2007 at 01:43PM PDT, ID: 19393433

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.29.2007 at 04:40PM PDT, ID: 19394219

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.29.2007 at 04:42PM PDT, ID: 19394226

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.30.2007 at 12:31AM PDT, ID: 19395163

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.02.2007 at 07:09AM PDT, ID: 19403561

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.02.2007 at 07:28AM PDT, ID: 19403727

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.02.2007 at 07:41AM PDT, ID: 19403858

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.02.2007 at 07:42AM PDT, ID: 19403870

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.02.2007 at 07:44AM PDT, ID: 19403886

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.03.2007 at 12:45AM PDT, ID: 19409399

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.03.2007 at 08:02AM PDT, ID: 19411797

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32