PHP Hash Functions

Beginner
3 min read
Updated: Nov 2026
15 function guides
Function index

About This Index

This page is the PHP Hash Functions index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs.

Learn what a hash is and which function to pick on /php/hash. Use this page when you need a specific helper such as hash(), hash_hmac(), or hash_equals().

Beginner path.

Start with hash() and hash_hmac()—then learn hash_equals() for safe comparison and hash_init() for large data.

How to Call a Hash Function

Hash helpers are global functions—pass an algorithm name and your data:

PHP
$digest = hash('sha256', 'hello');
$mac    = hash_hmac('sha256', 'hello', $secretKey);
$file   = hash_file('sha256', $path);

$ctx = hash_init('sha256');
hash_update($ctx, 'Hello, ');
hash_update($ctx, 'World');
$digest = hash_final($ctx);

if (hash_equals($expected, $received)) {
    echo 'Valid';
}

PHP Hash Functions Table

All function guides in this PHP tutorial series (15 tutorials in 5 categories).

Hash data

2 functions

Create a hash from a string or from the contents of a file.

FunctionDescriptionTutorial
hash()Generate a hash value of a string, such as sha256 or md5.Try it
hash_file()Generate a hash value of a file's contents.Try it

HMAC (keyed hashes)

2 functions

Sign data with a secret key so it cannot be forged or changed.

FunctionDescriptionTutorial
hash_hmac()Generate a keyed hash value using the HMAC method.Try it
hash_hmac_file()Generate a keyed hash value of a file using the HMAC method.Try it

Incremental hashing

6 functions

Build a hash in pieces from strings, files or streams.

FunctionDescriptionTutorial
hash_init()Initialize an incremental hashing context.Try it
hash_update()Pump data into an active hashing context.Try it
hash_update_file()Pump data into an active hashing context from a file.Try it
hash_update_stream()Pump data into an active hashing context from an open stream.Try it
hash_copy()Copy a hashing context so it can be reused in two directions.Try it
hash_final()Finalize an incremental hash and return the result.Try it

Keys & safe comparison

3 functions

Derive keys from secrets and compare hashes without timing leaks.

FunctionDescriptionTutorial
hash_pbkdf2()Generate a PBKDF2 key derivation of a supplied password.Try it
hash_hkdf()Generate an HKDF key derivation of a supplied key input.Try it
hash_equals()Compare two strings in constant time to avoid timing attacks.Try it

Algorithm lists

2 functions

See which algorithms your PHP supports.

FunctionDescriptionTutorial
hash_algos()Return a list of the hashing algorithms registered in PHP.Try it
hash_hmac_algos()Return a list of the algorithms that can be used with HMAC.Try it

Frequently Asked Questions

They are the built-in hash_* functions that create fingerprints of data, sign data with a key, hash files, hash data in pieces, derive keys and compare hashes safely. They need no extra library.
The Hash page teaches the ideas: what a hash is, which algorithm to pick and what not to use hashes for. This index lists every function tutorial.
Use hash('sha256', $data) for a fingerprint, hash_hmac() when you need a secret key, and hash_equals() to compare results safely.
No. Plain hashes are fast, so guesses are cheap. Use password_hash() and password_verify() for passwords.
sha256 is a good default. Avoid md5 and sha1 for security. Use crc32b only for simple checksums.
If you are new, read PHP Hash first. Then open hash(), hash_hmac() and hash_equals() from the tables below.

Start with hash()

Open the first guide—syntax, examples, and FAQs.

hash() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful