# redirection/5.5.2/models/ip.php

Redirection, version 5.5.2. 26 lines.

- Page: https://pluginprobe.com/plugins/redirection/5.5.2/code/models/ip.php
- Raw: https://pluginprobe.com/plugins/redirection/5.5.2/raw/models/ip.php
- Modified: 2024-01-01T15:24:06+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/5.5.2/code/models/ip.php#L10-L20`.

```php
<?php

class Redirection_IP {
	private $ip;

	public function __construct( $ip = '' ) {
		$this->ip = '';

		$ip = sanitize_text_field( $ip );
		$ip = explode( ',', $ip );
		$ip = array_shift( $ip );
		$ip = filter_var( $ip, FILTER_VALIDATE_IP );

		// Convert to binary
		// phpcs:ignore
		$ip = @inet_pton( trim( $ip ) );
		if ( $ip !== false ) {
			// phpcs:ignore
			$this->ip = @inet_ntop( $ip );  // Convert back to string
		}
	}

	public function get() {
		return $this->ip;
	}
}
```
