Zend_Validate-Ip.xml 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.basic">
  10. <title>Basic usage</title>
  11. <para>
  12. A basic example of usage is below:
  13. </para>
  14. <programlisting language="php"><![CDATA[
  15. $validator = new Zend_Validate_Ip();
  16. if ($validator->isValid($ip)) {
  17. // ip appears to be valid
  18. } else {
  19. // ip is invalid; print the reasons
  20. }
  21. ]]></programlisting>
  22. <note>
  23. <title>Invalid IP addresses</title>
  24. <para>
  25. Keep in mind that <classname>Zend_Validate_Ip</classname> only validates IP
  26. addresses. Addresses like 'mydomain.com' or '192.168.50.1/index.html' are no valid
  27. IP addresses. They are either hostnames or valid <acronym>URL</acronym>s but not IP
  28. addresses.
  29. </para>
  30. </note>
  31. <note>
  32. <title>IPv6 validation</title>
  33. <para>
  34. <classname>Zend_Validate_Ip</classname> validates IPv6 addresses with regex. The
  35. reason is that the filters and methods from PHP itself don't follow the RFC. Many
  36. other available classes also don't follow it.
  37. </para>
  38. </note>
  39. </sect3>
  40. <sect3 id="zend.validate.set.ip.singletype">
  41. <title>Validate IPv4 or IPV6 alone</title>
  42. <para>
  43. Sometimes it's useful to validate only one of the supported formats. For example when
  44. your network only supports IPv4. In this case it would be useless to allow IPv6 within
  45. this validator.
  46. </para>
  47. <para>
  48. To limit <classname>Zend_Validate_Ip</classname> to one protocol you can set the options
  49. <property>allowipv4</property> or <property>allowipv6</property> to
  50. <constant>FALSE</constant>. You can do this either by giving the option to the
  51. constructor or by using <methodname>setOptions()</methodname> afterwards.
  52. </para>
  53. <programlisting language="php"><![CDATA[
  54. $validator = new Zend_Validate_Ip(array('allowipv6' => false);
  55. if ($validator->isValid($ip)) {
  56. // ip appears to be valid ipv4 address
  57. } else {
  58. // ip is no ipv4 address
  59. }
  60. ]]></programlisting>
  61. <note>
  62. <title>Default behaviour</title>
  63. <para>
  64. The default behaviour which <classname>Zend_Validate_Ip</classname> follows is to
  65. allow both standards.
  66. </para>
  67. </note>
  68. </sect3>
  69. </sect2>
  70. <!--
  71. vim:se ts=4 sw=4 et:
  72. -->