OpenCrypt - Membership Management
Username:
Password:
My Account / Forgotten Password?
 Home  my.OpenCrypt 
 Home  My Account  Helpdesk  FAQ and Documentation  Download OpenCrypt  Manage Licenses  OpenCrypt APIs  Upgrade Release Notes 

Frequently Asked Questions and Documentation
 
TopOpenCrypt DocumentationPHP Login Interface

Guidance relating to the PHP login interface and it's usage.

PHP Login Interface Tutorial and Guidance (version 1.8)

This documentation is updated with each new version of the software, please check you are viewing the correct documentation for your installation of OpenCrypt by going to: http://www.opencrypt.com/faq.php?c=25

The PHP login interface enables you to integrate user login with the content of your web site and use an HTML login interface embedded in your web pages rather than using the traditional pop-up login prompt. The system offers full anti-hack protection as with the usual pop-up login method, and also includes support for the 'OpenCrypt Points System'.

The PHP login interface offers seamless integration between your public and secure content, allowing new content areas in an HTML document to open when a user logs in, and because the interface is written in PHP, you have unlimited control over your content and the structure of your web site. Within minutes you can create sophisticated content structures, for example opening additional content in the web site for each additional month or day a user is registered, this is ideal for e-book's and online courses.

Note, the 'PHP Login Interface' is used instead of the standard pop-up prompt, it does not work with the pop-up login prompt as a method of providing an HTML login form!

Configuration
Setting up the PHP login interface does require some knowledge of PHP, if you have some experience with PHP you should not have any trouble. If you are a novice computer user you may find this complicated, please feel free to contact us with your questions, however please keep in mind that our technical support team is not here to teach your to program PHP and can only offer basic guidance and advice.

login.php is located in the 'php' directory which you will find in your OpenCrypt 'Path to HTTPDocs' directory. login.php is the main PHP application, login_config.php is the configuration file, login_html.php is used to display the login prompt, four template files are also included for use with login.php; php-login.tmpl, php-failed-login.tmpl, php-logout.tmpl and php-logged-in.tmpl.

OpenCrypt version 1.5 and above do not require that you configure the 'PHP Login Interface' like previous versions, the system should be automatically configured. The configuration is updated whenever you adjust your 'Central Configuration', 'Register and Manage', 'Styles and Colours', 'Anti-Hack', 'OpenCrypt Robot' or 'E-Commerce Integration' configuration using the OpenCrypt administration panel.

Basic Usage
To create a login interface, simply create a PHP file for your member's area content, this can simply be an HTML file which you have renamed as a '.php' file.

Place the following text in the PHP file at the very top of the file:

<?PHP
require "login.php";
?>

It is critical that this is at the top of the file, their must be no HTML, text or blank lines above this text.

This code will load the PHP login interface and associated functions including the shopping cart.

Note, in the require statements you may wish to use a full/absolute server path. To do this, look in your 'Central Configuration' and take the 'Path to HTTPDocs', then simply add '/php/' to the end of the path. e.g. /path/to/httpdocs/oc/php/ and place this before the file name in the require statement. For example:

<?PHP
require "/path/to/httpdocs/oc/php/login.php";
?>

As explained earlier, login.php does not display the login prompt, to do this we use login_html.php. Simply include the following code anywhere in the PHP document (after the login.php code):

<?PHP
require "login_html.php";
?>

If you now load your PHP document on the web server, you will see a login prompt in the HTML/PHP document. You will see you can login, logout and so fourth, but at this stage it does not unlock any secure content. We do this using conditional statements based around the '$login_successful' variable. If a user is logged in, '$login_successful' will equal '1', if they have failed to login it will equal '0'.

An example of a basic query follows:

<?PHP
if ("$login_successful" == "1") {
print <<<END
logged in
END;
} else {
print <<<END
not logged in
END;
}
?>

This query is within it's own PHP area in the document, and would need the 'require "login_html.php";' code to be elsewhere in the PHP document, you can include the statement with the require line.

For example:

<?PHP
require "login_html.php";

if ("$login_successful" == "1") {
print <<<END
logged in
END;
} else {
print <<<END
not logged in
END;
}
?>

The above two examples show a 'logged in' message when the user is logged in, and a 'not logged in' message when they are not.

These conditional statements form the basis for the login interface and these are what must be used to setup the secure and public content. You may place as many of these statements in a document as you wish, though you should only 'require' login.php and login_html.php once in each document.

Example of PHP document:

<?PHP
require "login.php";
?>
<html>
<head><title>Document</title></head>
<body bgcolor="#ffffff" text="#000080" link="#800000">
<center><table width=650 cellpadding=5 cellspacing=0 border=0>
<tr><td bgcolor="#000080"><font face="Arial" size="3" color="#eeeeee"><b>An Example PHP Login Interface</b></font></td></tr>
<tr><td valign=top><font face="Arial">Introduction Text<p>
Here is an example, below you will see a login prompt.<P>

<?PHP
require "login_html.php";
?>
<p><hr><p>

<?PHP
if ("$login_successful" == "1") {
print <<<END
<font color="#ff0000">You have now logged in and opened the secure content in this document.</font>
END;
} else {
print <<<END
Here is some content for non registered users.
END;
}
?>
<p><hr><p>

<?PHP
if ("$login_successful" == "1") {
print <<<END
<font color="#ff0000">Second secure content area
END;
} else {
print <<<END
Here is some more content for non registered users.
END;
}
?>

<p></td></tr></table></center></body></html>

This example includes two areas of secure content which will open when logged in.

Data Import
The following user data tags may be used in any .tmpl file.

%self% - Location of self, e.g. The file being called via the browser.
%url_cgi% - URL to directory containing OpenCrypt.
%username% - Logged in username.
%email% - User's email address.
%fname% - User's first name.
%lname%- User's last name.
%sub_id% - User's subscription id.
%sub_name% - User's subscription name.
%language% - User's language.
%date_opened% - User's date of account opening.
%date_expire%- User's data of account expiration.
%points% - User's points count.
%session% - Session id, used for PHP login and User Account Manager login.

The following user data may be displayed in any secure content (values will be blank if not logged in), document must be PHP and must 'require' login.php.

$envself - Location of self, e.g. The file being called via the browser.
$url_cgi - URL to directory containing OpenCrypt.
$dbusername - Logged in username.
$dbemail - User's email address.
$dbfname - User's first name.
$dblname - User's last name.
$dbsub_id - User's subscription id.
$dbsub_name - User's subscription name.
$dblanguage - User's language.
$dbvcode - User's validation code (if account not active).
$dbstage - User's account stage (if account not active, or being renewed).
$dbactive - User's account status. 1 equals active, 0 equals inactive.
$dbdate_opened - User's date of account opening. Format: YYYY-MM-DD HH:MM:SS
$dbdate_expire - User's date of account expiration. Format: YYYY-MM-DD
$dbpoints - User's points count.
$session - Session id, used for PHP login and User Account Manager login.
$envip - User's IP address.
$envref - User's referrer.
$envbrow - User's web browser.

Custom form fields are available using the PHP array $dbfield, the keys are field1 to field50.

$dbfield['field1'] - Custom form field 1.
$dbfield['field25'] - Custom form field 25.

A handy tip, users can move between the PHP login interface and any User Account Manager function thanks to the sessions system. Simply use the following link in your PHP documents:

$url_cgi/manage.cgi?s=$session&a=home

Or in the templates files:

%url_cgi%/manage.cgi?s=%session%&a=home

You can replace 'home' with other functions such as 'modify' or 'renew', to link directly to update account details or renew the account.

Search Engine Optimisation
If you wish to allow search engines to crawl your secure content, you can enable the SEO functionality of the PHP Login interface. This will enable crawler bots from all the major search engines (including Google, Searchme, Yahoo, Live and MSN) to access your secure content.

Firstly, setup an account in OpenCrypt called 'googlebot'. This will enable you to track the traffic from the bots directly from the OpenCrypt administration panel, enabling you to get a more detailed understanding of the traffic passing through your site.

To enable the search engine features of login.php, the following variable must be set before login.php is included in your page.

$login_seo = "1";
require "/path/to/login.php";

We recommend also printing the $header_html variable in your headers, as this prevents the bots from archiving your secure content (for example Google's cache feature) and therefore making it available to anyone. Alternatively, simply place the following tag in your HTML header:
 

<meta name="googlebot" content="noarchive">

Using login.php and the .htaccess Login Prompt Simultaneously
If you are using both PHP and .htaccess options for user logins to the OpenCrypt system, then it is possible to setup login.php within a .htaccess member's area so the standard features of login.php are available even when it's not being used to manage user login. To do this, the following variable must be set before login.php is included in your page.

$login_popup = "1";
require "/path/to/login.php";

Points System
To deduct points from an account, use the following code:

$points = charge_points("10");
if ("$points" == "0") {
print "error";
} else {
print "ok";
}

This example will charge the logged in user, 10 points. If they do not have enough points, 'error' is displayed, otherwise 'ok' is displayed.

Logging System
login.php will automatically log all accesses to the frontend statistics database, this includes the location of the file being loaded. If for some reason you wish to add additional logging, use the following code:

frontend_log("action");

Replace 'action' with the action id you wish to log. An example that is already is use in the software is:

frontend_log("php_logged_in($envself)");

Shopping Basket
login.php will automatically detect and display a summary of the users shopping basket/cart, to display the cart summary, simply use the following code:

print "$shopping_basket";

Or, if for example you wish to place a table around the shopping basket summary, simply use the following code:

if ("$shopping_basket") {
print <<<END
<form action="basket.php" method="get">
<table cellpadding="8" cellspacing="0" border="0">
<tr><td nowrap>
<font face="Verdana" size="1">
$shopping_basket
</font>
</td></tr></table>
</form>
END;
}

'Add to Cart' Buttons
To create an 'Add to Cart' button, simply use the 'buybutton' function. Firstly we create a 'lookup_string' which specifies the details of the product/item. For example:

$lookup_string ="exampleID---Example Product NAME---This is an example product description.---5.00---0---0---0---0";

Simply replace, 'exampleID' with a product ID, this is used to identify the product within the system so it important you use different IDs for each product. Try to keep them short and simple. Then add your 'Product Name' and a 'Description' replacing the text in the example but making sure to leave the groups of three hypens intact. These are used as seperators/delimiters. Replace '5.00' with the price of the product/item. Ignore the following four zeros, these are reserved for future use when the system supports tax, shipping and recurring payments.

Then to display the 'Add to Cart' button, simply use the following line:

buybutton($lookup_string);

For example:

<?PHP
$lookup_string ="exampleID---Example Product NAME---This is an example product description.---5.00---0---0---0---0";
buybutton($lookup_string);
?>

Note, the $lookup_string line should be on one line without any line returns. The example has line returns so it fits in the pop-up faq used on our web site...

If you want to display a quantity input box next to the 'Add to Cart' button, set the variable $show_quantity to '1' before loading the buybutton function. You can also return the output from the buybutton function to a string rather than having the function print the button by setting the variable $return_button to '1', this enables you to include the button in your HTML with less complicated source code.

For example:

<?PHP
$show_quantity = "1";
$return_button = "1";
$lookup_string ="exampleID---Example Product NAME---This is an example product description.---5.00---0---0---0---0";
$button = buybutton($lookup_string);
print $button;
?>

Detect If Product Has Been Purchased
OpenCrypt version 1.7 includes a function for detecting if the logged in user has purchased a product before. This is used as follows:

require "$path_php/purchases.php";
$product_qty = lookup_purchases("product-ID");

Want to learn more about PHP?
If you are interested in learning more about PHP we would recommend the following resources:


We would also recommend the following book:

 
Article Details

Last Updated: 04 September 2009 06:31:41
Revision Number: 0
Article viewed 45528 times.
FAQ Index
Pre-Sales Questions
OpenCrypt Documentation
OpenCrypt System
Communicate
Statistics
Administrators
Configuration
E-Commerce Configuration
User Management
Database Management
OpenCrypt Installation
Register.cgi
Manage.cgi
PHP Login Interface
OpenCrypt Plugins
OpenCrypt Add-Ons
Dictionary and Terms

Copyright © 1999 - 2016 ionix Limited. All Rights Reserved.

Powered by OpenCrypt