| 
<?php
//Sample code for operational remote key generation
 
 //Settings
 //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
 require_once('../imagekey.class.php');
 $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
 $ikey->createKey($src,'',$usecurl,$verify);
 
 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';
 }
 }
 }else{
 //declare and set default values used in the form
 $src = '';
 $msg = '';
 $msgtext = '';
 }
 ?>
 <!DOCTYPE html>
 <html>
 <head>
 <meta charset="UTF-8">
 <title>Image Key Encryption</title>
 </head>
 <style>
 .form-label, .form-submit, .msg-result, .msg-return{
 margin-top: 20px;
 }
 input[type="text"]{
 width: 600px;
 }
 textarea{
 width: 600px;
 height: 150px;
 }
 a{
 color: blue;
 text-decoration: none;
 }
 a:hover{
 color: red;
 }
 .error-text{
 border: thin solid red;
 padding: 20px;
 }
 .msg-result{
 border: thin solid black;
 padding: 20px;
 }
 </style>
 <body>
 <?php
 if( !empty($errortext) ){
 //error text exists so display it
 ?>
 <div class="error-text"><?php echo $errortext;?></div>
 <?php
 }
 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">
 </div>
 </form>
 <?php
 }else{
 //we have message text so display it
 ?>
 <div class="msg-result"><?php echo $msgtext;?></div>
 <div class="msg-return"><a href="">Return</a></div>
 <?php
 }
 ?>
 </body>
 </html>
 |