Php-mysql Course

The openssl_encrypt() and openssl_decrypt() functions can be used to encrypt and decrypt text in PHP.
They are useful to encrypt and decrypt the user password in a register /login script.

- Here is a simple example with the openssl_encrypt() and openssl_decrypt() functions.
<?php
$password = 'user_pass'; //password added by user $_POST['password']
$key_enc = '1234'; //key for encrypt
$met_enc = 'aes256'; //method to encrypt: aes128, aes192, aes256, blowfish, cast-cbc
$iv = '16_characters_ok'; //a random string with 16 characters

//encrypts the password
$pass_enc = openssl_encrypt($password, $met_enc, $key_enc, 0, $iv);
echo $pass_enc; // "uw4QKRUsG+l17w5epb7nKw=="

//decrypts the encrypted password, it uses the same arguments: $met_enc, $key_enc, $opt=0, $iv
$pass_enc ='uw4QKRUsG+l17w5epb7nKw=='; //the encrypted password
$pass = openssl_decrypt($pass_enc, $met_enc, $key_enc, 0, $iv);
echo '<br>'.$pass; // "user_pass"
?>

Notice, the openssl_decrypt() must use the same arguments (here: $met_enc, $key_enc, $opt=0, $iv) to decrypt the string encrypted with openssl_encrypt().

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which tag is used in <table> to create table header cell?
<thead> <th> <td>
<table><tr>
  <th>Title 1</th>
  <th>Title 2</th>
</tr></table>
Which CSS property sets the distance between lines?
line-height word-spacing margin
.some_class {
  line-height: 150%;
}
Which function opens a new browser window.
alert() confirm() open()
document.getElementById("id_button").onclick = function(){
  window.open("http://coursesweb.net/");
}
Indicate the PHP function that returns an array with names of the files and folders inside a directory.
mkdir() scandir() readdir()
$ar_dir = scandir("dir_name");
var_export($ar_dir);
Using openssl_encrypt and openssl_decrypt in PHP

Last accessed pages

  1. $_GET, $_POST and $_REQUEST Variables (33892)
  2. Display multiple groups of images (5455)
  3. CSS Trapezoid Shape (11410)
  4. Simple Laravel MySQL CRUD Example (1814)
  5. CSS cursor property - Custom Cursors (6185)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (551)
  2. The Mastery of Love (67)
  3. CSS cursor property - Custom Cursors (64)
  4. Read Excel file data in PHP - PhpExcelReader (61)
  5. PHP-MySQL free course, online tutorials PHP MySQL code (44)