1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect2 id="zend.validate.set.ip">
7 <classname>Zend_Validate_Ip</classname> allows you to validate if a given value is an IP
8 address. It supports the IPv4 and also the IPv6 standard.
11 <sect3 id="zend.validate.set.ip.options">
12 <title>Supported options for Zend_Validate_Ip</title>
15 The following options are supported for <classname>Zend_Validate_Ip</classname>:
21 <emphasis><property>allowipv4</property></emphasis>: Defines if the validator
22 allows IPv4 adresses. This option defaults to <constant>TRUE</constant>.
28 <emphasis><property>allowipv6</property></emphasis>: Defines if the validator
29 allows IPv6 adresses. This option defaults to <constant>TRUE</constant>.
35 <sect3 id="zend.validate.set.ip.basic">
36 <title>Basic usage</title>
39 A basic example of usage is below:
42 <programlisting language="php"><![CDATA[
43 $validator = new Zend_Validate_Ip();
44 if ($validator->isValid($ip)) {
45 // ip appears to be valid
47 // ip is invalid; print the reasons
52 <title>Invalid IP addresses</title>
55 Keep in mind that <classname>Zend_Validate_Ip</classname> only validates IP
56 addresses. Addresses like '<filename>mydomain.com</filename>' or
57 '<filename>192.168.50.1/index.html</filename>' are no valid
58 IP addresses. They are either hostnames or valid <acronym>URL</acronym>s but not IP
64 <title>IPv6 validation</title>
67 <classname>Zend_Validate_Ip</classname> validates IPv6 addresses with regex. The
68 reason is that the filters and methods from <acronym>PHP</acronym> itself don't
69 follow the <acronym>RFC</acronym>. Many other available classes also don't follow
75 <sect3 id="zend.validate.set.ip.singletype">
76 <title>Validate IPv4 or IPV6 alone</title>
79 Sometimes it's useful to validate only one of the supported formats. For example when
80 your network only supports IPv4. In this case it would be useless to allow IPv6 within
85 To limit <classname>Zend_Validate_Ip</classname> to one protocol you can set the options
86 <property>allowipv4</property> or <property>allowipv6</property> to
87 <constant>FALSE</constant>. You can do this either by giving the option to the
88 constructor or by using <methodname>setOptions()</methodname> afterwards.
91 <programlisting language="php"><![CDATA[
92 $validator = new Zend_Validate_Ip(array('allowipv6' => false);
93 if ($validator->isValid($ip)) {
94 // ip appears to be valid ipv4 address
96 // ip is no ipv4 address
101 <title>Default behaviour</title>
104 The default behaviour which <classname>Zend_Validate_Ip</classname> follows is to
105 allow both standards.