PHP Classes

File: msg-crypt/index.php

Recommend this page to a friend!
  Classes of Dave Smith   Image Key Cypher   msg-crypt/index.php   Download  
File: msg-crypt/index.php
Role: Example script
Content type: text/plain
Description: Sample for remote images
Class: Image Key Cypher
Encrypt and decrypt text using images for the key
Author: By
Last change:
Date: 5 years ago
Size: 3,576 bytes


Class file image Download
//Sample code for operational remote key generation

//use curl to get remote image
$usecurl = true;

//have curl verify ssl peer
//to verify, certificates must be properly set up for curl
$verify = false;

$errortext = '';
if( isset(
$_REQUEST['submitted']) ){
//the form has been submitted so include and instantiate class
$ikey = new imageKey();

//read request into variables
$src = $_REQUEST['img_src'];
$msg = $_REQUEST['msg_text'];

//check for errors
if( empty($src) ){
$errortext .= 'You must enter a URL to the source image<br>';
    if( empty(
$msg) ){
$errortext .= 'You must enter a message<br>';

    if( empty(
$errortext) ){
//no errors found so process image
$ikey->imgPath = ''; //<-- since we are supplying the full URL, we need to remove any default paths

        if( !empty(
$ikey->errorText) ){
//problem creating key
$errortext .= $ikey->errorText;

//determine if we are processing an encrypted message or not and launch appropriate method
$pattern = "/{$ikey->msgDelim}[0-9]+{$ikey->msgDelim}/";
$msgtext = ( preg_match($pattern,$msg) ) ? trim($ikey->decryptMsg($msg)) : trim($ikey->encryptMsg($msg));

        if( empty(
$msgtext) ){
//class did not return a message
$errortext .= 'There was a problem processing your request';
//declare and set default values used in the form
$src = '';
$msg = '';
$msgtext = '';
<!DOCTYPE html>
        <meta charset="UTF-8">
        <title>Image Key Encryption</title>
        .form-label, .form-submit, .msg-result, .msg-return{
            margin-top: 20px;
            width: 600px;
            width: 600px;
            height: 150px;
            color: blue;
            text-decoration: none;
            color: red;
            border: thin solid red;
            padding: 20px;
            border: thin solid black;
            padding: 20px;
if( !empty($errortext) ){
//error text exists so display it
<div class="error-text"><?php echo $errortext;?></div>
if( empty(
$msgtext) ){
//no message text so show the form
<form method="POST">
            <div class="form-label"><label for="img_src">Enter full URL to the image</label></div>
            <div class="form-input"><input type="text" name="img_src" id="img_src" value="<?php echo $src;?>" autocomplete="off"></div>
            <div class="form-label"><label for="msg_text">Enter message</label></div>
            <div class="form-input"><textarea name="msg_text" id="msg_text"><?php echo $msg;?></textarea></div>
            <div class="form-submit">
                <input type="hidden" name="submitted" value="1">
                <input type="submit" name="form_submit" value="Go">
//we have message text so display it
<div class="msg-result"><?php echo $msgtext;?></div>
        <div class="msg-return"><a href="">Return</a></div>