<?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:
-->
