PHP rmdir () function
Rmdir― Delete Empty Directory
Grammar:
BOOL RmDir (String $dirname [, Resource $context])
An attempt was made to delete the directory specified by DirName. The directory must be empty and have the appropriate permissions. Failure results in a e_warning level error.
Parameters:
1.dirname: The path to the directory.
2.context: Added support for context in PHP 5.0.0.
PHP rmdir () Delete a non-empty directory
As mentioned above, the RmDir () function can only delete empty directories, if the non-empty directories need to go to the directory first, use the unlink () function to delete each file in the directory, and then come back to delete the empty directory. If subdirectories exist in the directory, and the directory is not empty, you need to use recursive methods. The source code for the custom recursive function delete directory is as follows:
<?php
function Deldir ($directory) {//Custom function recursive functions entire directory
if (file_exists ($directory)) {//To determine if the directory exists, an error if no rmdir () function exists
if ([email protected] ($directory)) {//Open directory to return directory resources and determine if successful
while ($filename =readdir ($dir _handle)) {//Traverse directory, read out files or folders in directory
if ($filename! = '. ' && $filename! = ' ... ') {//Be sure to exclude two special directories
$subFile = $directory. " /". $filename;//Connect the file under the directory to the current directory
if (Is_dir ($subFile)) {//If the directory condition is Deldir ($subFile);//recursively call yourself to delete subdirectories
}
if (Is_file ($subFile)) {//If the file condition is set unlink ($subFile);//delete this file directly
}
}
}
Closedir ($dir _handle);//Close Directory Resource
RmDir ($directory);//Delete Empty directory
}
}
}
Deldir ("Mydir");//Call Deldir function
?>
<?php
$password = ' testtest.com ';
Echo Crypt ($password);
Output: $1$dz3. QX2. $CQZ 8I. Ofeepkyrwp0og8l1
/* The eight characters between the second $ and the third $ are generated by PHP and are changed once per refresh
*/
echo "
Echo Crypt ($password, "testtest");
Output: tesgeyalkym3a
When we want to add a custom salt value, such as the example of Testtest as the second parameter directly added, more than two characters will intercept the first two bits
echo "
Echo Crypt ($password, ' $1$testtest$ ');
Output: $1$testtest$dsirawgthivh3o0hshgol1
/*crypt encryption function has a variety of salt value encryption support, the above example shows the MD5 hash as the salt value, the way
The salt value is added in $1$$ form, as in the example of Testtest plus the latter two $ characters,
Exceeding eight characters will intercept the first eight bits, the total length is 12 bits; crypt is this form by default.
*/
echo "Crypt also has a variety of salt-valued encryption support, see the manual
SHA1 Encryption:
String SHA1 (String $str [, bool $raw _output = false]); Like MD5, the difference is SHA1 () returns a hash value of 40 characters by default, passing in a parameter, the first is an encrypted string, the second is a Boolean value of Raw_output, the default is False, and if set to TRUE,SHA1 () returns the original 20 Bit RAW Format Message summary
<?php
$my _intro= "Zhouxiaogang";
Echo SHA1 ($my _intro); b6773e8c180c693d9f875bcf77c1202a243e8594
echo "Of course, multiple encryption algorithms can be used in a mix
Echo MD5 (SHA1 ($my _intro));
Output: 54818bd624d69ac9a139bf92251e381d
This way of double encryption can also improve the security of data
Asymmetric encryption
The asymmetric encryption algorithm requires two keys for encryption and decryption, both of which are the public key (publicly key, the public key) and the private key, or the secret key (private key);
, the secure transmission of important information is accomplished by using asymmetric encryption between A and B.
Party B generates a pair of keys (public and private) and exposes the public key to other parties.
The party that obtains the public key uses the key to encrypt the confidential information before sending it to party B.
Party B decrypts the encrypted information with another private key (private key) that it saves. Party B can only use its private key (private key) to decrypt the information encrypted by the corresponding public key.
In the transmission process, even if the attacker intercepts the transmitted ciphertext and obtains the public key of B, the cipher cannot be cracked, because only the private key of B can decrypt the text.
Similarly, if B to reply to the encrypted information to a, then need to publish a public key to B for encryption, a self-preservation of a private key for decryption.
The main algorithms used in asymmetric cryptography are: RSA, Elgamal, knapsack algorithm, Rabin, D-h, ECC (elliptic curve encryption algorithm), etc. One of the most common algorithms we see is the RSA algorithm
Here is an excerpt from the Internet a PHP algorithm for asymmetric encryption via OpenSSL
PHP rmdir methods for removing non-empty directories using recursive functions