# redirection/3.4/matches/cookie.php

Redirection, version 3.4. 32 lines.

- Page: https://pluginprobe.com/plugins/redirection/3.4/code/matches/cookie.php
- Raw: https://pluginprobe.com/plugins/redirection/3.4/raw/matches/cookie.php
- Modified: 2018-02-11T15:35:32+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/redirection/3.4/code/matches/cookie.php#L10-L20`.

```php
<?php

include_once dirname( __FILE__).'/http-header.php';

class Cookie_Match extends Header_Match {
	function name() {
		return __( 'URL and cookie', 'redirection' );
	}

	function get_target( $url, $matched_url, $regex ) {
		$target = false;
		$matched = Redirection_Request::get_cookie( $this->name ) === $this->value;

		if ( $this->regex ) {
			$matched = preg_match( '@'.str_replace( '@', '\\@', $this->value ).'@', Redirection_Request::get_cookie( $this->name ), $matches ) > 0;
		}

		// Check if referrer matches
		if ( $matched && $this->url_from !== '' ) {
			$target = $this->url_from;
		} elseif ( ! $matched && $this->url_notfrom !== '' ) {
			$target = $this->url_notfrom;
		}

		if ( $regex && $target ) {
			$target = $this->get_target_regex_url( $matched_url, $target, $url );
		}

		return $target;
	}
}

```
