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

Example: Create a Dedicated Protected Folder For New Users

The following guide will explain how to use custom actions to do the following after a user registers:

  • Create a folder on your server.
  • Secure the folder as a "Protected Folder".
  • Grant the new user access to his/her personal folder.

Initial Setup

Before you begin, you will need to create a folder into which all user folders will be created. This folder needs to be set to permissions "777" using a FTP client. Doing this will ensure that the program has the permissions it needs to create sub-folders on your server.

post_reg_folder_create.php

Create the following ".php" file using a text editor such as Notepad or Editpad. Note that you will need to change the "$folder_path" and "$folder_url" variables to reflect the full server path and URL to the custom folder you created in the "Initial Setup" section above.

<?php
 
// Input the path to the folder
// you created in the "Initial
// Setup" section above. Also
// input the URL to the folder.
 
$folder_path = '/full/server/path/to/custom_folder';
$folder_url = 'http://www.yoursite.com/custom_folder';
 
// Now let's start by making the
// user's dedicated folder. The folder
// will be created with the account's
// username as the name.
 
 
$group_path = $folder_path . '/' . $user;
if (mkdir($group_path)) {
 
	// Set up some basic settings
	$group_name = $user . "'s Folder";
	$group_url = $folder_url . "/" . $user;
 
	// Next create a protected folder
	// in the Member Guardian DB.
	$query = mysql_query("
		INSERT INTO `ppSD_groups` (`name`,`location`,`path`,`type`)
		VALUES ('" . addslashes($group_name) . "','" . addslashes($group_url) . "','" . addslashes($group_path) . "','mod_rewrite')
	");
 
	// Get the ID of the new group
	$group_id = mysql_insert_id();
 
	// Prepare the security file
	// for the directory.
	$mod_file = '<IfModule mod_rewrite.c>';
	$mod_file .= 'BrowserMatch "MSIE" force-no-vary';
	$mod_file .= 'RewriteEngine On';
	$mod_file .= 'RewriteCond %{HTTP_COOKIE} ppSD_session=([a-zA-Z0-9]+)';
	$mod_file .= 'RewriteCond ' . $options['ppsd_fsp'] . '/sessions/%1,8 -f';
	$mod_file .= 'RewriteRule ^(.*)$ - [L]';
	$mod_file .= 'RewriteCond %{HTTPS} on';
	$mod_file .= 'RewriteRule ^(.*)$ ' . $options['ppsd_sl'] . '/login.php?ssg=' . $group_id . '&no_access=1&url=%{HTTP_HOST}%{REQUEST_URI}?%{QUERY_STRING} [L,R]';
	$mod_file .= 'RewriteRule ^(.*)$ ' . $options['ppsd_sl'] . '/login.php?ssg=' . $group_id . '&no_access=1&url=%{HTTP_HOST}%{REQUEST_URI}?%{QUERY_STRING} [L,R]';
	$mod_file .= '</IfModule>';
 
	// Secure the folder
	$mod_file_path = $group_path . '/.htaccess';
	$fh = fopen($mod_file_path, 'w');
	fwrite($fh, $mod_file);
	fclose($fh);
 
}
 
?>

Create the Custom Action

From your Member Guardian admin control panel, click on "Settings » Add a Custom Action" and input the following settings:

FieldInputted Value
NamePost-Registration Folder Creation
TypePHP Code Inclusion
TriggerRegistration Complete
File LocationUpload the File
Upload FileSelect the post_reg_folder_create.php file created above
Upload ToN/A
Registration FormIf you only want to run the custom action when a specific registration form is used, select the registration form.
ProductIf you only want to run the custom action when a specific product is purchased, select the product.