Created
January 10, 2012 04:52
-
-
Save dmuth/1587034 to your computer and use it in GitHub Desktop.
How to secure a Drupal site
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
* From my blog post at: | |
* | |
* http://www.dmuth.org/node/1202/how-secure-drupal-site | |
* | |
*/ | |
$path = getenv("SCRIPT_URL"); | |
// | |
// If a user is not logged in, they can only access certain unrestricted pages. | |
// | |
if ($user->uid == 0) { | |
if ( | |
// | |
// strstr() is called for efficiency. Keep in mind that ANY path that matches | |
// these strings will be allowed to anonymous users. So if you have something | |
// like "/userlist", an anonymous user can view that. I warned ya! | |
// | |
!strstr($path, "user") | |
&& !strstr($path, "how-to-join") | |
&& !strstr($path, "contact") | |
) { | |
form_set_error("", "You must be logged in first."); | |
drupal_goto("user"); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment