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.5)

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 does 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.
%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.
$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.
$dbdate_opened - User's date of account opening.
$dbdate_expire - User's date of account expiration.
$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.

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.

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...

 
Article Details

Last Updated: 08 October 2008 00:06:40
Revision Number: 1
Article viewed 43735 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