wp_get_referer(): string|false

Retrieves referer from ‘_wp_http_referer’ or HTTP referer.

Description

If it’s the same as the current request URL, will return false.

Return

string|false Referer URL on success, false on failure.

More Information

HTTP referer is a server variable. ‘referer’ is deliberately misspelled.

If page “refered” (form posted) to itself, returns false (because $_SERVER[‘HTTP_REFERER’] == $_REQUEST[‘_wp_http_referer’])

Source

function wp_get_referer() {
	// Return early if called before wp_validate_redirect() is defined.
	if ( ! function_exists( 'wp_validate_redirect' ) ) {
		return false;
	}

	$ref = wp_get_raw_referer();

	if ( $ref && wp_unslash( $_SERVER['REQUEST_URI'] ) !== $ref
		&& home_url() . wp_unslash( $_SERVER['REQUEST_URI'] ) !== $ref
	) {
		return wp_validate_redirect( $ref, false );
	}

	return false;
}

Changelog

VersionDescription
2.0.4Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.