Zend_Validate-Ip.xml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 'mydomain.com' or '192.168.50.1/index.html' are no valid
  47. IP addresses. They are either hostnames or valid <acronym>URL</acronym>s but not IP
  48. addresses.
  49. </para>
  50. </note>
  51. <note>
  52. <title>IPv6 validation</title>
  53. <para>
  54. <classname>Zend_Validate_Ip</classname> validates IPv6 addresses with regex. The
  55. reason is that the filters and methods from <acronym>PHP</acronym> itself don't
  56. follow the RFC. Many other available classes also don't follow it.
  57. </para>
  58. </note>
  59. </sect3>
  60. <sect3 id="zend.validate.set.ip.singletype">
  61. <title>Validate IPv4 or IPV6 alone</title>
  62. <para>
  63. Sometimes it's useful to validate only one of the supported formats. For example when
  64. your network only supports IPv4. In this case it would be useless to allow IPv6 within
  65. this validator.
  66. </para>
  67. <para>
  68. To limit <classname>Zend_Validate_Ip</classname> to one protocol you can set the options
  69. <property>allowipv4</property> or <property>allowipv6</property> to
  70. <constant>FALSE</constant>. You can do this either by giving the option to the
  71. constructor or by using <methodname>setOptions()</methodname> afterwards.
  72. </para>
  73. <programlisting language="php"><![CDATA[
  74. $validator = new Zend_Validate_Ip(array('allowipv6' => false);
  75. if ($validator->isValid($ip)) {
  76. // ip appears to be valid ipv4 address
  77. } else {
  78. // ip is no ipv4 address
  79. }
  80. ]]></programlisting>
  81. <note>
  82. <title>Default behaviour</title>
  83. <para>
  84. The default behaviour which <classname>Zend_Validate_Ip</classname> follows is to
  85. allow both standards.
  86. </para>
  87. </note>
  88. </sect3>
  89. </sect2>
  90. <!--
  91. vim:se ts=4 sw=4 et:
  92. -->