How to encrypt php
MD5 encryption:
string md5 ( string $str [, bool $raw_output = false ] )
1.md5() returns the hash value as a 32-character hexadecimal number by default, It accepts two parameters, the first is the string to be encrypted, and the second is the Boolean value of raw_output. The default is false. If set to true, md5() will return the original 16-bit binary format message digest.
2.md5() is a one-way encryption and does not have a reverse decryption algorithm, but it can still crack some common strings through collection, enumeration, collision and other methods.
Related recommendations: "PHP Tutorial"
$username='jellybool'; $password='abcd'; /*简单地对字符串进行md5加密*/ echo md5($username); echo " "; echo md5($password); echo " "; /*更推荐的做法是对重要的敏感数据进行多次加密,以防被轻易破解*/ echo md5(md5($password)); /*以上输出: username:4f5436e5d72608fb647b691e8edcf42e password:7bf02cf0f4af6da4accbc73d2a175476 password(两次加密):864704bb35754f8cd0232cba6b91521b string crypt ( string $str [, string $salt ] )
1.crypt() accepts two parameters, the first is the string that needs to be encrypted, and the second The second is the salt value (which is the encryption interference value, if not provided, it is automatically generated by PHP by default); returns a hashed string or a string of less than 13 characters, the latter is to distinguish the salt value.
2.crypt() is one-way encryption, the same as md5.
$password='jellybool.com'; echo crypt($password); echo " "; echo crypt($password,"jellybool"); //输出:je7fNiu1KNaEs /*当我们要加自定义的盐值时,如例子中的jellybool作为第二个参数直接加入,
Sha1 encryption:
string sha1 ( string $str [, bool $raw_output = false ]
1. It is very similar to md5, except that sha1() returns a 40-character hash value by default , the properties of the incoming parameters are the same, the first one is the encrypted string, the second one is the Boolean value of raw_output, the default is false, if set to true, sha1() will return the original 20-bit original format message digest.
2.sha1() is also one-way encryption and has no reverse decryption algorithm.
$my_intro="abc"; echo sha1($my_intro); //输出:c98885c04c1208fd4d0b1dadd3bd2a9ff4d042ca echo " "; //当然,可以将多种加密算法混合使用 echo md5(sha1($my_intro)); //输出:94f25bf9214f88b1ef065a3f9b5d9874
Urlencode encryption:
string urlencode ( string $str )
1. One parameter, pass in the string to be encrypted (usually used to encrypt URLs).
2. urlencode is two-way encryption and can be encrypted with urldecode (strictly speaking, it is not a real encryption).
3. Return a string. All non-alphanumeric characters in this string except -_. will be replaced with a percent sign (%) followed by two hexadecimal digits. , spaces are encoded as plus signs ( ).
$a = "http abc你好"; $b = urlencode($a); $c = urldecode($b); echo $b; echo ' '; echo $c; ?>
The above is the detailed content of How to encrypt php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

The following resources contain additional information on CakePHP. Please use them to get more in-depth knowledge on this.
