PHP Classes
elePHPant
Icontem

File: iDealCerts_example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Richard Nijmeijer  >  iDealCerts  >  iDealCerts_example.php  >  Download  
File: iDealCerts_example.php
Role: Example script
Content type: text/plain
Description: PHP Class example
Class: iDealCerts
Generate cryptographic certificate files
Author: By
Last change: Class call to right class name (file) updated.
Date: 6 years ago
Size: 5,131 bytes
 

Contents

Class file image Download
<?php
// ========================================================================= //
// **** Copyright (C)2008 by EasyStar Software (www.easystar.nl) **** //
// ========================================================================= //

/***
* File : iDealCerts_example.php
* Version : 1.0
* Written by : Richard Nijmeijer (EasyStar Software)
*
* This file demonstrates the use of the iDealCerts class ('iDealCerts_class.php')
*
* This file is licensed under the GNU General Public License.
* You may use and/or alter this file and the example for your own use, either as
* a private person or commercial, but it may not be sold. Also you have to leave
* the above copyright as it is and also this message has to remain when you alter
* the base for your own use or re-deployment.
*
* No warranty, express or implied, is given for the use of this file.
*/

/**
* Call the class, adjust with the path if needed
*/
require_once('iDealCerts_class.php');

/**
* Set the path where the certificates should be saved, adjust if needed
*
* @var Certificate_path example: 'security/certificates/' (end with a 'slash')
*/
$Certificate_path = './';

/**
* Define the class to your variable
*
* @class iDealCerts
*/
$iDealCerts = new iDealCerts();

/**
* Set the classes variable 'path' to your defined path variable
*
* @var iDealCerts->path
*/
$iDealCerts->path = $Certificate_path;

/**
* Set the classes variable 'distinguished_name' to your predefined variables
* Make sure that before setting this variable, your '$country', '$state', etc. are defined!
*
* @function iDealCerts->distinguished_name(vars)
*/
$iDealCerts->set_distinguished_name($country, $state, $city, $organization_name, $organization_dept, $name, $email);

/**
* Set the classes variable 'numberOfDays' to your predefined variable
* Make sure that before setting this variable, your '$valid_days' is defined or set it to an Integer value!
*
* @var iDealCerts->numberOfDays
*/
$iDealCerts->numberOfDays = $valid_days;

/**
* Set the classes variable 'privateKeyPass' to your predefined variable
* Make sure that before setting this variable, your '$password' is defined or set it to a STRONG string value!
*
* @var iDealCerts->privateKeyPass
*/
$iDealCerts->privateKeyPass = $password;

/**
* Set the classes variable 'publicCertFile', 'localCertFile' and 'privateKeyFile' to your predefined variable
* Make sure that before setting this variable, your '$filename' is defined!
* The '$filename' ONLY holds the name of the certificate files, NO extensions!
*
* @var iDealCerts->publicCertFile
* @var iDealCerts->localCertFile
* @var iDealCerts->privateKeyFile
*/
$iDealCerts->publicCertFile = $filename . ".cer";
$iDealCerts->localCertFile = $filename . ".crt";
$iDealCerts->privateKeyFile = $filename . ".pem";

/**
* Set the classes variable 'certReqFile' to false when you do not want the certificate request saved as a file
* To save the certificate request use this code: $iDealCerts->certReqFile = $filename . ".csr";
* The handle acts the same as the other declarations above.
*
* @var iDealCerts->certReqFile
*/
//$iDealCerts->certReqFile = $filename . ".csr";
$iDealCerts->certReqFile = false;

/**
* Create the certificates and save those if these options are set accordingly
* Depending on the variable switch 'export_to_files' the certificates are saved
* Depending on the variable switch 'return_public_code' the return of the function holds:
* 'false' :There was an error, please call '$iDealCerts->error' to view/print the error
* 'true' :The function completed succesfully ('return_public_code' set to 'false')
* '@var text' :The function returns the Public Certificate code in text format ('return_public_code' set to 'true')
*
* @function iDealCerts->certReqFile(var1, var2)
* @var1 'export_to_files' value: true or false
* @var2 'return_public_code' value: true or false
*/
$PublicCertCode = $iDealCerts->generate_certificates(true, true);

if (!
$PublicCertCode) { // Received 'false'
   
echo "ERROR: ".$iDealCerts->error."<br />";
    exit();
}

/**
* The variable '$PublicCertCode' holds the certificate code (.cer) which has to be uploaded to your iDEAL supplier.
* It is saved, when you optioned for that, to your path as '$filename'.cer and you can select this for your upload.
* For security it is wise to save the certificates outside of the website. If you've done so and want to save the
* public certificate to your local harddrive, show the returned variable '$PublicCertCode' in a textarea where you
* can select the complete text from and save this text in a file 'filename.cer' on your drive. You can use this to
* upload to your iDEAL supplier (based on ING/Postbank iDEAL Advanced! Please see your own suppliers requirements).
*
* See the example below:
*/

if ($PublicCertCode === true) {
    echo
"Certificates are created!";
} else {
    echo
'<textarea cols="100" rows="15" name="public_cert">' . $PublicCertCode . '</textarea>';
}

?>