OpenCrypt - Membership Management
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.4)

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:

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'. This means you can offer 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.

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 images directory. login.php is the main PHP application, login_config.php is the configuration file, four template files are also included; php-login.tmpl, php-failed-login.tmpl, php-logout.tmpl and php-logged-in.tmpl.

OpenCrypt version 1.4 offers an automated configuration tool, to configure your 'PHP Login Interface' simply go to the 'PHP Login Interface' section of your administration panel configuration and follow the on-screen instructions.

Alternatively, to configure the 'PHP Login Interface' manually, open login_config.php in your favourite text editor (do not use NotePad), at the top of the file you will see the following lines:

$dbhost = "localhost";
$dbname = "DATABASENAME";
$login_cookie_name = "LOGINCOOKIE";
$login_cookie_time = "3600"; # 1 hour
$templates_dir = "/path/to/images/php";
$url_cgi = "";

We will go through these line by line, to find out what your correct inputs are please refer to the 'Central Configuration' section of your administration panel.

$dbhost = "localhost"; - The address for your mySQL database host.

$dbname = "DATABASENAME"; - The name of your mySQL database.

$dbuser = "DATABASEUSERNAME"; - Username used to access your mySQL database.

$dbpass = "DATABASEPASSWORD"; - Password used to access your mySQL database.

$login_cookie_name = "LOGINCOOKIE"; - Cookie name (best not to modify).

$login_cookie_time = "3600"; # 1 hour - Cookie length in seconds.

$url_cgi = ""; - URL of your OpenCrypt CGI directory (which contains register.cgi and manage.cgi).

$templates_dir = "/path/to/images/php"; - Absolute/full server path to your PHP directory containing the template files.

Once modified, simply re-upload login_config.php.

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

Place the following text in the PHP file:

require "login.php";

This will load the PHP login interface and will display the login prompt (php-login.tmpl). As a side note, if for whatever reason you wish to load login.php without the login prompt HTML being displayed, simply use the following text:

$hide_login = "1";
require "login.php";

If using the first example, 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:

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

This query is within it's own PHP area in the document, and would need the 'require ?login.php?' code to be elsewhere in the PHP document (before the conditional statement), you can include the statement with with the require line.

For example:

require "login.php";

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

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 once in the document.

Example of PHP document:

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

require "login.php";


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

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


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:


Or in the templates files:


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:


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


Article Details

Last Updated: 04 August 2007 00:00:00
Revision Number: 0
Article viewed 30573 times.
FAQ Index
Pre-Sales Questions
OpenCrypt Documentation
OpenCrypt System
E-Commerce Configuration
User Management
Database Management
OpenCrypt Installation
PHP Login Interface
OpenCrypt Plugins
OpenCrypt Add-Ons
Dictionary and Terms

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

Powered by OpenCrypt