Article Contents Related Articles Tags
  • No tags found.
Was This Helpful? Last Updated
  • 2012/09/17

Securing Individual PHP Files

You do not need to use this code on any file that is within a protected folder. That content is already secure!

To secure individual PHP files, you will need to place the following code at the top of the ".php" file you are securing:

Basic Authentication

<?php
require "/path/to/members/member_cp/user_data.php";

// User is logged in.
if ($logged_in == '1') {
  // Logged in!
}

// Not logged in: redirect to login page.
else {
  header('Location: http://www.yoursite.com/members/login.php');
  exit;
}
?>

Using User Groupings To Determine Access

You can take this a step further and validate that a user has access to specific protected folder or user grouping:

<?php
require "/path/to/members/member_cp/user_data.php";

// User is logged in.
if ($logged_in == '1') {
  // Logged in, but does the user have
  // access to our user grouping?
  if ($user['areas']['GROUP_ID_HERE'] == '1') {
    // Yes, he/she does!
  } else {
    header('Location: http://www.yoursite.com/members/login.php');
    exit;
  }
}

// Not logged in: redirect to login page.
else {
  header('Location: http://www.yoursite.com/members/login.php');
  exit;
}
?>

You will simply need to find the grouping ID from "Members » Protected Folders and User Groups" and replace the GROUP_ID_HERE above with the actual numerical ID of the grouping.