[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[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 and Databases, PHP for Windows

Tags: pages, php, protect, using, sessions

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;}?>
[+][-]06/29/07 01:18 PM, ID: 19393219Accepted Solution

View this solution now by starting your 30-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 and Databases, PHP for Windows
Tags: pages, php, protect, using, sessions
Sign Up Now!
Solution Provided By: ZSoderquist
Participating Experts: 3
Solution Grade: A
 
[+][-]06/29/07 09:42 AM, ID: 19391496Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/29/07 10:54 AM, ID: 19392113Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/29/07 10:59 AM, ID: 19392157Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/29/07 01:43 PM, ID: 19393433Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/29/07 04:40 PM, ID: 19394219Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/29/07 04:42 PM, ID: 19394226Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/30/07 12:31 AM, ID: 19395163Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/02/07 07:09 AM, ID: 19403561Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/02/07 07:28 AM, ID: 19403727Assisted Solution

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

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

 
[+][-]07/02/07 07:41 AM, ID: 19403858Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/02/07 07:42 AM, ID: 19403870Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/02/07 07:44 AM, ID: 19403886Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/03/07 12:45 AM, ID: 19409399Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/03/07 08:02 AM, ID: 19411797Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92