Jump to content

[SOLVED] Call a function inside a class and returning the result


Recommended Posts

Hi

 

I am very new to PHP as I usually use Coldfusion for all server side stuff, but constraints in a recent project have led us to using PHP as it is far more flexible when it comes to encryption.

 

Let me start by giving a breif overview of what I am doing, I have a Flash application that uses AMFPHP (a Flash Remoting gateway for PHP). So for this I have a PHP script sitting on the server that deals with all calls to the server, the PHP script does it stuff and returns data to the Flash Application.

 

This is all working fine I can call a function in the PHP script and return a result. The problem occurs when I call a function in the PHP script which then calls another function in the same class which is meant to return a value to the  original function which then returns the result to Flash

 

So in the example below I call the "autoUpdateEmail" function from Flash which makes its mySQL query, I was then hoping to call the  "doEncryption" which would return an Encrypted value back to the "autoUpdateEmail" function which then returns the encrypted value back to Flash. If I skip the encryption function and just return the query result back to Flash it works fine.

 

Both the function work on their own, just not together.  I cannot for the life of me get it to call the "doEncryption" function, I really cannot see why this won't work.

 

<?php
class FlashFunctions{
  function FlashFunctions(){
   
   $this->methodTable = array(
    "doEncryption" => array(
     "description" => "Do Encrypt",
     "access" => "remote"
    ),
    "autoUpdateEmail" => array(
     "description" => "autoUpdateEmail",
     "access" => "remote"
    )
    
   );
  }
  // ENCRYPTION FUNCTION
  function doEncryption($decryptedString){
   //
   if (!extension_loaded('mcrypt')){
    return "NO EXTENSION INSTALLED";
   }else{
    //
    $key = "********";
        // Convert the ASCII to Unicode by insert some 0 bytes 
            for ($i = 0 ; $i < strlen($decryptedString) ; $i++){ 
            $strUnicode .= $decryptedString[$i] . chr(0); 
         }  
     $td = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, '');   
        $iv = str_repeat(chr(0), ;   
         mcrypt_generic_init($td, $key, $iv);  
        $encrypted_data = mcrypt_generic($td, $strUnicode);  
        mcrypt_generic_deinit($td);  
        mcrypt_module_close($td);  
        // 
       return strtoupper(bin2hex($encrypted_data));
   }
  }
  
  //AUTO UPDATE EMAIL
  function autoUpdateEmail($UserID){
   $username = "********";
   $password = "*******";
   $hostname = "localhost"; 
   $dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
   $selected = mysql_select_db("CRM",$dbh) or die("Could not select first_test");
   $result = mysql_query("SELECT * FROM tblUser WHERE userID = '$UserID'");
   while ($row = mysql_fetch_assoc($result)) {
     $email = $row['Email'];
   }
   mysql_close($dbh);
   $returnStr = $email;
   //
   return(doEncryption($returnStr));
  }
   
}
?>

 

Any help would be greatly appeciated.

 

Regards

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.