Zend_Validate-Ip.xml 3.7 KB

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