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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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 and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.
