PHP array

Image
  An array stores multiple values in one single variable. In PHP, the array() function is used to create an array. Example: <?php $pets = array ( "dog" , "cat" , "rabbit" ); echo $pets [ 0 ] . "," . $pets [ 1 ] . "," . $pets [ 2 ]; ?> Output: dog,cat,rabbit An array is a special variable, which can hold more than one value at a time. If you have a list of student names, storing the names in single variables could like this, $name1 = "Peter" $name2 = "Mickle" $name2 = "Bravo" However, what if you want to loop through the names and find a specific one? And what if you had 3 names, but 1000? The solution is to create an array . An array can hold many values under a single name, and you can access the values by referring to an index number. There are three different kind of arrays. Numeric array – Arrays with a numeric index Associative array – Arrays with named keys

Generate Secure Password Hashes

Generate Secure Password Hashes

PHP 5.5 introduced a simple and secure method for hashing and verifying passwords across password_hash() and password_verify(), respectively. These activities allow you to easily generate a secure hash using the most secure algorithm available to PHP. By utilizing the PASSWORD_DEFAULT option, your code will take advantage of whatever current encryption algorithm is considered most secure in that version of PHP, so there’s no need to worry about future-proofing.

Syntax:
<?php 
// Raw password, as entered by user
$passwordOriginal = "leD4p?Qe5S";
/*
* Hash the password using the PASSWORD_DEFAULT algorithm.
* Currently using the crypt() algorithm, but using PASSWORD_DEFAULT
  ensures future compatibility.
* Database tables should accommodate a length of 255 characters
  for $passwordHash values
*/
$passwordHash = password_hash($passwordOriginal, PASSWORD_DEFAULT); 
// Store in database.
	
// Verify a password against the hash stored in the database with password_verify().
echo password_verify($passwordOriginal, $passwordHash); // True
echo password_verify("random password", $passwordHash); // False
?>	

Comments

Popular posts from this blog

PHP Code for get Client IP Address

PHP explode function

PHP Script for MySqli Database Connection