1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect2 id="zend.validate.set.ip">
<title>Ip</title>
<para>
<classname>Zend_Validate_Ip</classname> allows you to validate if a given value is an IP
address. It supports the IPv4 and also the IPv6 standard.
</para>
<sect3 id="zend.validate.set.ip.options">
<title>Supported options for Zend_Validate_Ip</title>
<para>
The following options are supported for <classname>Zend_Validate_Ip</classname>:
</para>
<itemizedlist>
<listitem>
<para>
<emphasis><property>allowipv4</property></emphasis>: Defines if the validator
allows IPv4 adresses. This option defaults to <constant>TRUE</constant>.
</para>
</listitem>
<listitem>
<para>
<emphasis><property>allowipv6</property></emphasis>: Defines if the validator
allows IPv6 adresses. This option defaults to <constant>TRUE</constant>.
</para>
</listitem>
</itemizedlist>
</sect3>
<sect3 id="zend.validate.set.ip.basic">
<title>Basic usage</title>
<para>
A basic example of usage is below:
</para>
<programlisting language="php"><![CDATA[
$validator = new Zend_Validate_Ip();
if ($validator->isValid($ip)) {
// ip appears to be valid
} else {
// ip is invalid; print the reasons
}
]]></programlisting>
<note>
<title>Invalid IP addresses</title>
<para>
Keep in mind that <classname>Zend_Validate_Ip</classname> only validates IP
addresses. Addresses like '<filename>mydomain.com</filename>' or
'<filename>192.168.50.1/index.html</filename>' are no valid
IP addresses. They are either hostnames or valid <acronym>URL</acronym>s but not IP
addresses.
</para>
</note>
<note>
<title>IPv6 validation</title>
<para>
<classname>Zend_Validate_Ip</classname> validates IPv6 addresses with regex. The
reason is that the filters and methods from <acronym>PHP</acronym> itself don't
follow the <acronym>RFC</acronym>. Many other available classes also don't follow
it.
</para>
</note>
</sect3>
<sect3 id="zend.validate.set.ip.singletype">
<title>Validate IPv4 or IPV6 alone</title>
<para>
Sometimes it's useful to validate only one of the supported formats. For example when
your network only supports IPv4. In this case it would be useless to allow IPv6 within
this validator.
</para>
<para>
To limit <classname>Zend_Validate_Ip</classname> to one protocol you can set the options
<property>allowipv4</property> or <property>allowipv6</property> to
<constant>FALSE</constant>. You can do this either by giving the option to the
constructor or by using <methodname>setOptions()</methodname> afterwards.
</para>
<programlisting language="php"><![CDATA[
$validator = new Zend_Validate_Ip(array('allowipv6' => false);
if ($validator->isValid($ip)) {
// ip appears to be valid ipv4 address
} else {
// ip is no ipv4 address
}
]]></programlisting>
<note>
<title>Default behaviour</title>
<para>
The default behaviour which <classname>Zend_Validate_Ip</classname> follows is to
allow both standards.
</para>
</note>
</sect3>
</sect2>
<!--
vim:se ts=4 sw=4 et:
-->
|