Zend_Validate-Hostname.xml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <sect2 id="zend.validate.set.hostname">
  2. <title>Hostname</title>
  3. <para>
  4. Zend_Validate_Hostname pozwala ci na przeprowadzenie weryfikacji adresów
  5. serwerów w oparciu o zestaw znanych specyfikacji. Możliwe jest
  6. sprawdzenie trzech różnych typów adresów serwerów: adresu DNS (np.
  7. domain.com), adresu IP (np. 1.2.3.4), oraz adresu lokalnego (np.
  8. localhost). Domyślne będzie to sprawdzane jedynie w kontekście adresów
  9. DNS.
  10. </para>
  11. <para>
  12. <emphasis role="strong">Podstawowe użycie</emphasis>
  13. </para>
  14. <para>
  15. Poniżej podstawowy przykład użycia:
  16. <programlisting role="php"><![CDATA[
  17. $validator = new Zend_Validate_Hostname();
  18. if ($validator->isValid($hostname)) {
  19. // nazwa serwera wygląda na prawidłową
  20. } else {
  21. // nazwa jest nieprawidłowa; wyświetl powody
  22. foreach ($validator->getMessages() as $message) {
  23. echo "$message\n";
  24. }
  25. }
  26. ]]>
  27. </programlisting>
  28. Sprawdzi to nazwę serwera <code>$hostname</code> i w przypadku niepowodzenia
  29. wypełni <code>$validator->getMessages()</code> użytecznymi informacjami
  30. informującymi o błędach.
  31. </para>
  32. <para>
  33. <emphasis role="strong">Weryfikacja różnych typów adresów serwerów</emphasis>
  34. </para>
  35. <para>
  36. Może się okazać, że chcesz zezwolić na użycie adresów IP, adresów
  37. lokalnych lub kombinacji dozwolonych typów. Możesz to zrobić przekazując
  38. parametr do obiektu Zend_Validate_Hostname gdy tworzysz jego instancję.
  39. Parametr powinien być liczbą całkowitą określającą, ktorego typu adresy
  40. są dozwolone. Zalecamy użycie stałych klasy Zend_Validate_Hostname w
  41. tym celu.
  42. </para>
  43. <para>
  44. Stałe klasy Zend_Validate_Hostname to: <code>ALLOW_DNS</code> aby
  45. zezwalać tylko na adresy DNS, <code>ALLOW_IP</code> aby zezwalać tylko
  46. na adresy IP, <code>ALLOW_LOCAL</code> aby zezwalać tylko na adresy
  47. lokalne, oraz <code>ALLOW_ALL</code> aby zezwalać na wszystkie typy.
  48. Aby tylko sprawdzić adres dla adresów IP możesz użyć poniższego przykładu:
  49. <programlisting role="php"><![CDATA[
  50. $validator = new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_IP);
  51. if ($validator->isValid($hostname)) {
  52. // nazwa serwera wygląda na prawidłową
  53. } else {
  54. // nazwa jest nieprawidłowa; wyświetl powody
  55. foreach ($validator->getMessages() as $message) {
  56. echo "$message\n";
  57. }
  58. }
  59. ]]>
  60. </programlisting>
  61. </para>
  62. <para>
  63. Tak samo dobrze jak używając stałej <code>ALLOW_ALL</code> do określenia
  64. akceptacji adresów wszystkich typow, możesz użyć dowolnej kombinacji
  65. tych typów. Na przykład aby akceptować adresy DNS oraz adresy lokalne,
  66. uwtórz instancję obiektu Zend_Validate_Hostname w taki sposób:
  67. <programlisting role="php"><![CDATA[
  68. $validator = new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_DNS |
  69. Zend_Validate_Hostname::ALLOW_IP);
  70. ]]>
  71. </programlisting>
  72. </para>
  73. <para>
  74. <emphasis role="strong">Validating International Domains Names</emphasis>
  75. </para>
  76. <para>
  77. Some Country Code Top Level Domains (ccTLDs), such as 'de' (Germany), support international
  78. characters in domain names. These are known as International Domain Names (IDN). These domains
  79. can be matched by Zend_Validate_Hostname via extended characters that are used in the validation
  80. process.
  81. </para>
  82. <para>
  83. At present the list of supported ccTLDs include:
  84. <itemizedlist>
  85. <listitem>
  86. <para>at (Austria)</para>
  87. </listitem>
  88. <listitem>
  89. <para>ch (Switzerland)</para>
  90. </listitem>
  91. <listitem>
  92. <para>li (Liechtenstein)</para>
  93. </listitem>
  94. <listitem>
  95. <para>de (Germany)</para>
  96. </listitem>
  97. <listitem>
  98. <para>fi (Finland)</para>
  99. </listitem>
  100. <listitem>
  101. <para>hu (Hungary)</para>
  102. </listitem>
  103. <listitem>
  104. <para>no (Norway)</para>
  105. </listitem>
  106. <listitem>
  107. <para>se (Sweden)</para>
  108. </listitem>
  109. </itemizedlist>
  110. </para>
  111. <para>
  112. To match an IDN domain it's as simple as just using the standard Hostname validator since IDN
  113. matching is enabled by default. If you wish to disable IDN validation this can be done by
  114. by either passing a parameter to the Zend_Validate_Hostname constructor or via the
  115. <code>$validator->setValidateIdn()</code> method.
  116. </para>
  117. <para>
  118. You can disable IDN validation by passing a second parameter to the Zend_Validate_Hostname
  119. constructor in the following way.
  120. <programlisting role="php"><![CDATA[
  121. $validator =
  122. new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_DNS, false);
  123. ]]>
  124. </programlisting>
  125. Alternatively you can either pass TRUE or FALSE to
  126. <code>$validator->setValidateIdn()</code> to enable or disable IDN validation.
  127. If you are trying to match an IDN hostname which isn't currently supported it is likely
  128. it will fail validation if it has any international characters in it. Where a ccTLD file
  129. doesn't exist in Zend/Validate/Hostname specifying the additional characters a normal
  130. hostname validation is performed.
  131. </para>
  132. <para>
  133. Please note IDNs are only validated if you allow DNS hostnames to be validated.
  134. </para>
  135. <para>
  136. <emphasis role="strong">Validating Top Level Domains</emphasis>
  137. </para>
  138. <para>
  139. By default a hostname will be checked against a list of known TLDs. If this functionality
  140. is not required it can be disabled in much the same way as disabling IDN support.
  141. You can disable TLD validation by passing a third parameter to the Zend_Validate_Hostname constructor.
  142. In the example below we are supporting IDN validation via the second parameter.
  143. <programlisting role="php"><![CDATA[
  144. $validator =
  145. new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_DNS,
  146. true,
  147. false);
  148. ]]>
  149. </programlisting>
  150. Alternatively you can either pass TRUE or FALSE to
  151. <code>$validator->setValidateTld()</code> to enable or disable TLD validation.
  152. </para>
  153. <para>
  154. Please note TLDs are only validated if you allow DNS hostnames to be validated.
  155. </para>
  156. </sect2>