wp_get_raw_referer()WP 4.5.0

Retrieves unvalidated referer from '_wp_http_referer' or HTTP referer.

If the value of the '_wp_http_referer' URL query variable is not a string then it will be ignored.

Do not use for redirects, use wp_get_referer() instead.

No Hooks.

Return

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

Usage

wp_get_raw_referer();

Examples

0

#1 Check if there is a referrer link

Suppose we were on page http://example.com/foo and went to page http://example.com/bar where the following code is triggered:

$referer = wp_get_raw_referer();

if( $referer ){
	echo $referer;
}

On the screen we will see the URL of the page we came from: http://example.com/foo.

Changelog

Since 4.5.0 Introduced.

wp_get_raw_referer() code WP 6.5.3

function wp_get_raw_referer() {
	if ( ! empty( $_REQUEST['_wp_http_referer'] ) && is_string( $_REQUEST['_wp_http_referer'] ) ) {
		return wp_unslash( $_REQUEST['_wp_http_referer'] );
	} elseif ( ! empty( $_SERVER['HTTP_REFERER'] ) ) {
		return wp_unslash( $_SERVER['HTTP_REFERER'] );
	}

	return false;
}