String encryption function in admin section
It looks great, however, you can improve it as follows:


Break out the function into two - encrypt and decrypt. Your functions should do the least amount of things.
return on trim - no need to set $encryptedString.
In the encrypt, no need to have the second $string when you concat $iv. Just concat on the initial mcrypt call.


In the end, we're left with three functions. One setupCipher which creates the key, iv_size and iv. One encrypt and one decrypt to encrypt and decrypt, as follows:

private function setupCipher(){
    $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);

    return array(
        pack('H*', "bcb04b7e103a0cd8b54763051cef08bc55abe029fdebae5e1d417e2ffb2a00a3"),
        $iv_size, 
        mcrypt_create_iv($iv_size, MCRYPT_RAND)
    );
} 

public function decrypt($string){
    list($key, $iv_size) = $this-&gt;setupCipher();

    $string = base64_decode($string);
    $iv_dec = substr($string, 0, $iv_size);
    $ciphertext_dec = substr($string, $iv_size);
    return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $ciphertext_dec, MCRYPT_MODE_CBC, $iv_dec), "\0");
}

public function encrypt($string) {
    list($key, $iv_size, $iv) = $this-&gt;setupCipher();

    $string = $iv . mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $string, MCRYPT_MODE_CBC, $iv);
    return trim(base64_encode($string), "\0");
}


You would use them nearly identically to how you used them before, except no need to pass in the $method:

# Encrypt
$_SESSION['username'] = $backend-&gt;encrypt($username);

# Decrypt
echo $backend-&gt;decrypt($_SESSION['username']);