PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/class/validation_class.php

https://bitbucket.org/itoxable/chiron-gaming
PHP | 1845 lines | 1428 code | 198 blank | 219 comment | 185 complexity | ab8d7b94724d5d7d2279f6185637ba62 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. Validator 1.2 1999/03/05 CDI
  4. A class for validating common data from forms
  5. Copyright (c) 1999 CDI, cdi@thewebmasters.net All Rights Reserved
  6. */
  7. class Validator
  8. {
  9. var $ERROR = "";
  10. var $CLEAR = false;
  11. function Validator ()
  12. {
  13. return;
  14. }
  15. function clear_error ()
  16. {
  17. $this->ERROR = "";
  18. }
  19. function Validate($param,$param_name,$emp,$type="",$css_class="red")
  20. {
  21. $param=trim($param);
  22. if($emp=="EMP")
  23. {
  24. if(empty($param))
  25. {
  26. $err_msgs = "<li>Field <span class=$css_class>$param_name</span> is left empty.</li>";
  27. }
  28. else
  29. {
  30. if(!empty($type))
  31. {
  32. if($type=="IMAGE")
  33. {
  34. if(!$param)
  35. {
  36. $err_msgs="<li>Field <span class=$css_class>$param_name</span> should be filled properly</li>";
  37. }
  38. }
  39. if($type=="EMAIL")
  40. {
  41. if(!$this->is_email($param))
  42. {
  43. $err_msgs="<li>Field <span class=$css_class>$param_name</span> should be filled properly</li>";
  44. }
  45. }
  46. if($type=="NUM")
  47. {
  48. if(!$this->is_allnumbers($param))
  49. {
  50. $err_msgs="<li>Field <span class=$css_class>$param_name</span> should be filled properly</li>";
  51. }
  52. }
  53. if($type=="DOUBLE")
  54. {
  55. if(!$this->chk_double($param))
  56. {
  57. $err_msgs="<li>Field <span class=$css_class>$param_name</span> should be filled properly</li>";
  58. }
  59. }
  60. if($type=="URL")
  61. {
  62. if(!$this->is_url($param))
  63. {
  64. $err_msgs="<li>Field <span class=$css_class>$param_name</span> should be filled properly</li>";
  65. }
  66. }
  67. if($type=="PHONE")
  68. {
  69. if(!$this->is_phone($param))
  70. {
  71. $err_msgs="<li>Field <span class=$css_class>$param_name</span> should be filled properly</li>";
  72. }
  73. }
  74. if($type=="NAME")
  75. {
  76. if(!$this->is_name($param))
  77. {
  78. $err_msgs="<li>Field <span class=$css_class>$param_name</span> should be filled properly</li>";
  79. }
  80. }
  81. if($type=="LETTER")
  82. {
  83. if(!$this->is_allletters($param))
  84. {
  85. $err_msgs="<li>Field <span class=$css_class>$param_name</span> should be filled properly</li>";
  86. }
  87. }
  88. if($type=="ALNUM")
  89. {
  90. if(ereg('[^A-Za-z0-9-]', $param))
  91. {
  92. $err_msgs="<li>Field <span class=$css_class>$param_name</span> should be filled properly</li>";
  93. }
  94. }
  95. if($type=="NEWURL")
  96. {
  97. if(!$this->is_youtube($param))
  98. {
  99. $err_msgs="<li>Field <span class=$css_class>$param_name</span> should be filled properly</li>";
  100. }
  101. }
  102. if($type=="UTUBE")
  103. {
  104. if(!$this->is_youtube($param))
  105. {
  106. $err_msgs="<li>Field <span class=$css_class>$param_name</span> should be filled properly</li>";
  107. }
  108. }
  109. }//type checking
  110. }//param else
  111. }//EMP else
  112. else
  113. {
  114. if(!empty($param))
  115. {
  116. if(!empty($type))
  117. {
  118. if($type=="EMAIL")
  119. {
  120. if(!$this->is_email($param))
  121. {
  122. $err_msgs="<li>Field <span class=$css_class>$param_name</span> should be filled properly</li>";
  123. }
  124. }
  125. if($type=="ALLNUM")
  126. {
  127. if(!$this->is_allnumbers($param))
  128. {
  129. $err_msgs="<li>Field <span class=$css_class>$param_name</span> should be filled properly</li>";
  130. }
  131. }
  132. if($type=="URL")
  133. {
  134. if(!$this->is_url($param))
  135. {
  136. $err_msgs="<li>Field <span class=$css_class>$param_name</span> should be filled properly</li>";
  137. }
  138. }
  139. if($type=="PHONE")
  140. {
  141. if(!$this->is_phone($param))
  142. {
  143. $err_msgs="<li>Field <span class=$css_class>$param_name</span> should be filled properly</li>";
  144. }
  145. }
  146. if($type=="DOUBLE")
  147. {
  148. if(!$this->chk_double($param))
  149. {
  150. $err_msgs="<li>Field <span class=$css_class>$param_name</span> should be filled properly</li>";
  151. }
  152. }
  153. if($type=="NAME")
  154. {
  155. if(!$this->is_name($param))
  156. {
  157. $err_msgs="<li>Field <span class=$css_class>$param_name</span> should be filled properly</li>";
  158. }
  159. }
  160. if($type=="LETTER")
  161. {
  162. if(!$this->is_allletters($param))
  163. {
  164. $err_msgs="<li>Field <span class=$css_class>$param_name</span> should be filled properly</li>";
  165. }
  166. }
  167. if($type=="NEWURL")
  168. {
  169. if(!$this->is_youtube($param))
  170. {
  171. $err_msgs="<li>Field <span class=$css_class>$param_name</span> should be filled properly</li>";
  172. }
  173. }
  174. if($type=="UTUBE")
  175. {
  176. if(!$this->is_youtube($param))
  177. {
  178. $err_msgs="<li>Field <span class=$css_class>$param_name</span> should be filled properly</li>";
  179. }
  180. }
  181. }//type checking
  182. }//param else
  183. }//empty checking
  184. return $err_msgs;
  185. }
  186. /* DuplicateCheck function starts */
  187. function DuplicateCheck($table_name,$table_field,$param,$param_name,$param_id_name,$param_id="",$category_id_name="",$category_id="",$other_id_name="",$other_id="",$css_class="red")
  188. {
  189. $param=trim($param);
  190. if(empty($param))
  191. {
  192. $err_msgs = "<li>Field <span class=$css_class>$param_name</span> is left empty.</li>";
  193. }
  194. else
  195. {
  196. if(empty($param_id))
  197. {
  198. $chkduplicate="SELECT $table_field
  199. FROM $table_name
  200. WHERE $table_field=".$this->sql_value($param);
  201. if(!empty($category_id))
  202. $chkduplicate.=" AND $category_id_name=".$this->sql_value($category_id);
  203. if($other_id_name != '' && $other_id != '')
  204. $chkduplicate.=" AND $other_id_name=".$this->sql_value($other_id);
  205. }
  206. elseif(!empty($param_id))
  207. {
  208. $chkduplicate="SELECT $table_field
  209. FROM $table_name
  210. WHERE $table_field=".$this->sql_value($param)." AND $param_id_name!=".$param_id;
  211. if(!empty($category_id))
  212. $chkduplicate.=" AND $category_id_name=".$this->sql_value($category_id);
  213. if($other_id_name != '' && $other_id != '')
  214. $chkduplicate.=" AND $other_id_name=".$this->sql_value($other_id);
  215. }
  216. #echo $chkduplicate;
  217. $sql_result_duplicate = mysql_query($chkduplicate);
  218. if(mysql_num_rows($sql_result_duplicate)>0)
  219. {
  220. $err_msgs= "<li><span class=$css_class>Duplicate $param_name found.</span></li>";
  221. }
  222. }
  223. return $err_msgs;
  224. }
  225. /* DuplicateCheck function ends */
  226. /* DuplicateCheck Multiple Category function starts */
  227. function DuplicateCheckMultipleCat($table_name,$category_name_value_arr,$category_lebel_name_arr,$param_id_name,$param_id="")
  228. {
  229. $err_msgs="";
  230. if(is_array($category_name_value_arr))
  231. {
  232. $i=0;
  233. foreach($category_name_value_arr as $category_name => $category_val)
  234. {
  235. $category_val=trim($category_val);
  236. if(empty($category_val))
  237. {
  238. $err_msgs .= "<li>Field <span class=$css_class>$category_lebel_name_arr[$i]</span> is left empty.</li>";
  239. }
  240. $lebel_text .=" $category_lebel_name_arr[$i] -";
  241. $i++;
  242. }
  243. }
  244. if(empty($err_msgs))
  245. {
  246. if(empty($param_id))
  247. {
  248. $chkduplicate="SELECT *
  249. FROM $table_name
  250. WHERE ";
  251. if(is_array($category_name_value_arr))
  252. {
  253. $i=0;
  254. foreach($category_name_value_arr as $category_name => $category_val)
  255. {
  256. if($i!=0)
  257. $chkduplicate.=" AND ";
  258. $chkduplicate.=" $category_name=".$this->sql_value($category_val);
  259. $i++;
  260. }
  261. }
  262. }
  263. elseif(!empty($param_id))
  264. {
  265. $chkduplicate="SELECT *
  266. FROM $table_name
  267. WHERE $param_id_name!=".$param_id;
  268. if(is_array($category_name_value_arr))
  269. {
  270. foreach($category_name_value_arr as $category_name => $category_val)
  271. {
  272. $chkduplicate.=" AND $category_name=".$this->sql_value($category_val);
  273. }
  274. }
  275. }
  276. $sql_result_duplicate = mysql_query($chkduplicate);
  277. if(mysql_num_rows($sql_result_duplicate)>0)
  278. {
  279. // $lebel_text=substr($lebel_text,0,-1);
  280. $err_msgs= "<li><span class=$css_class>Duplicate combination of $lebel_text found.</span></li>";
  281. }
  282. }
  283. return $err_msgs;
  284. }
  285. /* DuplicateCheck Multiple Category function ends */
  286. /* DuplicateCheck Nolist function starts */
  287. function DuplicateCheckNolist($table_name,$table_field,$param,$param_name,$param_id_name,$param_id="",$category_id_name="",$category_id="",$css_class="red")
  288. {
  289. $param=trim($param);
  290. if(empty($param))
  291. {
  292. $err_msgs = "Field <font color=#FF0000>$param_name</font> is left empty.<br>";
  293. }
  294. else
  295. {
  296. if(empty($param_id))
  297. {
  298. $chkduplicate="SELECT $table_field
  299. FROM $table_name
  300. WHERE $table_field=".$this->sql_value($param);
  301. if(!empty($category_id))
  302. $chkduplicate.=" AND $category_id_name=".$this->sql_value($category_id);
  303. }
  304. elseif(!empty($param_id))
  305. {
  306. $chkduplicate="SELECT $table_field
  307. FROM $table_name
  308. WHERE $table_field=".$this->sql_value($param)." AND $param_id_name!=".$param_id;
  309. if(!empty($category_id))
  310. $chkduplicate.=" AND $category_id_name=".$this->sql_value($category_id);
  311. }
  312. $sql_result_duplicate = mysql_query($chkduplicate);
  313. if(mysql_num_rows($sql_result_duplicate)>0)
  314. {
  315. $err_msgs= "<font color=#FF0000>Duplicate $param_name found.</font><br>";
  316. }
  317. }
  318. return $err_msgs;
  319. }
  320. /* DuplicateCheck Nolist function ends */
  321. ////////////////////////////////////////////////////
  322. function sql_value($value)
  323. {
  324. $value = trim($value);
  325. if($value == null || $value == "")
  326. {
  327. return "NULL";
  328. }
  329. $magic_on=get_magic_quotes_gpc();
  330. //news_name
  331. //return "'$value'";
  332. return "'".str_replace("'", "\'", str_replace("\n", "\\n", $value))."'";
  333. }
  334. // ************************************************************
  335. // Checks a string for whitespace. True or false
  336. function has_space ($text)
  337. {
  338. if( ereg("[ ]",$text) )
  339. {
  340. return true;
  341. }
  342. return false;
  343. }
  344. // ************************************************************
  345. function is_youtube ($text)
  346. {
  347. if(preg_match("/^http\:\/\/(www|).[0-9A-Za-z_].[A-Za-z_]/", strip_tags(trim($text))))
  348. {
  349. return true;
  350. }
  351. return false;
  352. }
  353. function chconvert ($fragment)
  354. {
  355. if ($fragment == 7) { $result = "rwx"; }
  356. elseif ($fragment == 6) { $result = "rw-"; }
  357. elseif ($fragment == 5) { $result = "r-x"; }
  358. elseif ($fragment == 4) { $result = "r--"; }
  359. elseif ($fragment == 3) { $result = "-wx"; }
  360. elseif ($fragment == 2) { $result = "-w-"; }
  361. elseif ($fragment == 1) { $result = "--x"; }
  362. elseif ($fragment == 0) { $result = "---"; }
  363. else { $result = "unk"; }
  364. return($result);
  365. }
  366. // ************************************************************
  367. function get_perms ($fileName )
  368. {
  369. if($this->CLEAR) { $this->clear_error(); }
  370. $atrib = array();
  371. $perms = fileperms($fileName);
  372. if(!$perms)
  373. {
  374. $this->ERROR = "get_perms: Unable to obtain file perms on [$fileName]";
  375. return false;
  376. }
  377. $octal = sprintf("%lo", ($perms & 07777) );
  378. $one = substr($octal,0,1);
  379. $two = substr($octal,1,1);
  380. $three = substr($octal,2,1);
  381. $user = $this->chconvert($one);
  382. $group = $this->chconvert($two);
  383. $other = $this->chconvert($three);
  384. if(is_dir($fileName))
  385. {
  386. $user = "d$user";
  387. }
  388. $atrib = array(
  389. "octal" => $octal,
  390. "user" => $user,
  391. "group" => $group,
  392. "other" => $other
  393. );
  394. return $atrib;
  395. }
  396. // ************************************************************
  397. function is_sane ($filename)
  398. {
  399. if($this->CLEAR) { $this->clear_error(); }
  400. if (!file_exists($filename))
  401. {
  402. $this->ERROR = "File does not exist";
  403. return false;
  404. }
  405. if (!is_readable($filename))
  406. {
  407. $this->ERROR = "File is not readable";
  408. return false;
  409. }
  410. if(!is_writeable($filename))
  411. {
  412. $this->ERROR = "File is not writeable";
  413. return false;
  414. }
  415. if(is_dir($filename))
  416. {
  417. $this->ERROR = "File is a directory";
  418. return false;
  419. }
  420. if(is_link($filename))
  421. {
  422. $this->ERROR = "File is a symlink";
  423. return false;
  424. }
  425. return true;
  426. }
  427. // ************************************************************
  428. // Strips whitespace (tab or space) from a string
  429. function strip_space ($text)
  430. {
  431. $Return = ereg_replace("([ ]+)","",$text);
  432. return ($Return);
  433. }
  434. // ************************************************************
  435. // Returns true if string contains float/double numbers
  436. function chk_double ($text)
  437. {
  438. $REG_EXPRESSION = "^[-+]?[0-9]*\.?[0-9]+$";
  439. if( ereg($REG_EXPRESSION, $text) )
  440. return true;
  441. else
  442. return false;
  443. }
  444. // ************************************************************
  445. // ************************************************************
  446. // Returns true if string contains only numbers
  447. function is_allnumbers ($text)
  448. {
  449. if( (gettype($text)) == "integer") { return true; }
  450. $Bad = $this->strip_numbers($text);
  451. if(empty($Bad))
  452. {
  453. return true;
  454. }
  455. return false;
  456. }
  457. // ************************************************************
  458. // Strip numbers from a string
  459. function strip_numbers ($text)
  460. {
  461. $Stripped = eregi_replace("([0-9])","",$text);
  462. return ($Stripped);
  463. }
  464. // ************************************************************
  465. // Returns true if string contains only letters
  466. function is_allletters ($text)
  467. {
  468. $Bad = $this->strip_letters($text);
  469. if(empty($Bad))
  470. {
  471. return true;
  472. }
  473. return false;
  474. }
  475. // ************************************************************
  476. // Returns true if string contains only Name
  477. function is_name ($text)
  478. {
  479. $Bad = $this->strip_name($text);
  480. if(empty($Bad))
  481. {
  482. return true;
  483. }
  484. return false;
  485. }
  486. function strip_name($text)
  487. {
  488. $Stripped = eregi_replace("([A-Za-z\.\ ]+)","",$text);
  489. return $Stripped;
  490. }
  491. // ***************************************************************
  492. // For field length checking. (Anirban)
  493. function is_length($text)
  494. {
  495. if(strlen($text) < 10)
  496. return false;
  497. else
  498. return true;
  499. }
  500. // ************************************************************
  501. // Strips letters from a string
  502. function strip_letters ($text)
  503. {
  504. $Stripped = eregi_replace("([A-Z]+)","",$text);
  505. return $Stripped;
  506. }
  507. // ************************************************************
  508. // Checks for HTML entities in submitted text.
  509. // If found returns true, otherwise false. HTML specials are:
  510. //
  511. // " => &quot;
  512. // < => &lt;
  513. // > => &gt;
  514. // & => &amp;
  515. //
  516. // The presence of ",<,>,& will force this method to return true.
  517. //
  518. function has_html ($text = "")
  519. {
  520. if(empty($text))
  521. {
  522. return false;
  523. }
  524. $New = htmlspecialchars($text);
  525. if($New == $text)
  526. {
  527. return false;
  528. }
  529. return true;
  530. }
  531. // ************************************************************
  532. // strip_html()
  533. //
  534. // Strips all html entities, attributes, elements and tags from
  535. // the submitted string data and returns the results.
  536. //
  537. // Can't use a regex here because there's no way to know
  538. // how the data is laid out. We have to examine every character
  539. // that's been submitted. Consequently, this is not a very
  540. // efficient method. It works, it's very good at removing
  541. // all html from the data, but don't send gobs of data
  542. // at it or your program will slow to a crawl.
  543. // If you're stripping HTML from a file, use PHP's fgetss()
  544. // and NOT this method, as fgetss() does the same thing
  545. // about 100x faster.
  546. function strip_html ($text = "")
  547. {
  548. if( (!$text) or (empty($text)) )
  549. {
  550. return "";
  551. }
  552. $outside = true;
  553. $rawText = "";
  554. $length = strlen($text);
  555. $count = 0;
  556. for($count=0; $count < $length; $count++)
  557. {
  558. $digit = substr($text,$count,1);
  559. if(!empty($digit))
  560. {
  561. if( ($outside) and ($digit != "<") and ($digit != ">") )
  562. {
  563. $rawText .= $digit;
  564. }
  565. if($digit == "<")
  566. {
  567. $outside = false;
  568. }
  569. if($digit == ">")
  570. {
  571. $outside = true;
  572. }
  573. }
  574. }
  575. return $rawText;
  576. }
  577. // ************************************************************
  578. // Returns true of the submitted text has meta characters in it
  579. // . \\ + * ? [ ^ ] ( $ )
  580. //
  581. //
  582. function has_metas ($text = "")
  583. {
  584. if(empty($text))
  585. {
  586. return false;
  587. }
  588. $New = quotemeta($text);
  589. if($New == $text)
  590. {
  591. return false;
  592. }
  593. return true;
  594. }
  595. // ************************************************************
  596. // Strips " . \\ + * ? [ ^ ] ( $ ) " from submitted string
  597. //
  598. // Metas are a virtual MINE FIELD for regular expressions,
  599. // see custom_strip() for how they are removed
  600. function strip_metas ($text = "")
  601. {
  602. if(empty($text))
  603. {
  604. return false;
  605. }
  606. $Metas = array( '.','+','*','?','[','^',']','(','$',')' );
  607. $text = stripslashes($text);
  608. $New = $this->custom_strip($Metas,$text);
  609. return $New;
  610. }
  611. // ************************************************************
  612. // $Chars must be an array of characters to remove.
  613. // This method is meta-character safe.
  614. function custom_strip ($Chars, $text = "")
  615. {
  616. if($this->CLEAR) { $this->clear_error(); }
  617. if(empty($text))
  618. {
  619. return false;
  620. }
  621. if( (gettype($Chars)) != "array")
  622. {
  623. $this->ERROR = "custom_strip: [$Chars] is not an array";
  624. return false;
  625. }
  626. while ( list ( $key,$val) = each ($Chars) )
  627. {
  628. if(!empty($val))
  629. {
  630. // str_replace is meta-safe, ereg_replace is not
  631. $text = str_replace($val,"",$text);
  632. }
  633. }
  634. return $text;
  635. }
  636. // ************************************************************
  637. // Array_Echo will walk through an array,
  638. // continuously printing out key value pairs.
  639. //
  640. // Multi dimensional arrays are handled recursively.
  641. function array_echo ($MyArray, $Name = "Array")
  642. {
  643. if($this->CLEAR) { $this->clear_error(); }
  644. if( (gettype($MyArray)) != "array") { return; }
  645. $count = 0;
  646. while ( list ($key,$val) = each ($MyArray) )
  647. {
  648. if($count == 0)
  649. {
  650. echo "\n\n<P><TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 COLS=8\n";
  651. echo "><TR><TD VALIGN=TOP COLSPAN=4><B>$Name Contents:</B></TD\n";
  652. echo "><TD COLSPAN=2><B>KEY</B></TD><TD COLSPAN=2><B>VAL</B></TD></TR\n>";
  653. }
  654. if( (gettype($val)) == "array")
  655. {
  656. $NewName = "$key [$Name $count]";
  657. $NewArray = $MyArray[$key];
  658. echo "</TD></TR></TABLE\n\n>";
  659. $this->array_echo($NewArray,$NewName);
  660. echo "\n\n<P><TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 COLS=8\n";
  661. echo "><TR><TD VALIGN=TOP COLSPAN=4><B>$Name Continued:</B></TD\n";
  662. echo "><TD COLSPAN=2><B>KEY</B></TD><TD COLSPAN=2><B>VAL</B></TD></TR\n>";
  663. }
  664. else
  665. {
  666. echo "<TR>";
  667. $Col1 = sprintf("[%s][%0d]",$Name,$count);
  668. $Col2 = $key;
  669. if(empty($val)) { $val = '&nbsp;'; }
  670. $Col3 = $val;
  671. echo "<TD COLSPAN=4>$Col1</TD>";
  672. echo "<TD COLSPAN=2>$Col2</TD\n>";
  673. echo "<TD COLSPAN=2>$Col3</TD></TR\n\n>";
  674. }
  675. $count++;
  676. }
  677. echo "<TR><TD COLSPAN=8><B>Array [$Name] complete.</B></TD></TR\n>";
  678. echo "</TD></TR></TABLE\n\n>";
  679. return;
  680. }
  681. // ************************************************************
  682. // Valid email format? true or false
  683. // This checks the raw address, not RFC 822 addresses.
  684. // Looks for [something]@[valid hostname with DNS record]
  685. function is_email($Address = "")
  686. {
  687. $pattern = "/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/";
  688. if(preg_match($pattern, $Address))
  689. return true;
  690. else
  691. return false;
  692. }
  693. /* function is_email($Address = "")
  694. {
  695. if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $Address))
  696. {
  697. return false;
  698. }
  699. $email_array = explode("@", $Address);
  700. $local_array = explode(".", $email_array[0]);
  701. for ($i = 0; $i < sizeof($local_array); $i++)
  702. {
  703. if(!ereg("^(([A-Za-z0-9!#$%&amp;'*+/=?^_`{|}~-][A-Za-z0-9!#$%&amp;
  704. &#8618;'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$",
  705. $local_array[$i]))
  706. {
  707. return false;
  708. }
  709. }
  710. if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1]))
  711. {
  712. $domain_array = explode(".", $email_array[1]);
  713. if (sizeof($domain_array) < 2)
  714. {
  715. return false; // Not enough parts to domain
  716. }
  717. for ($i = 0; $i < sizeof($domain_array); $i++)
  718. {
  719. if(!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|
  720. &#8618;([A-Za-z0-9]+))$",
  721. $domain_array[$i]))
  722. {
  723. return false;
  724. }
  725. }
  726. }
  727. return true;
  728. /*$pattern = "/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/";
  729. if(preg_match($pattern, $Address))
  730. return true;
  731. else
  732. return false; */
  733. //}
  734. function is_email_old ($Address = "")
  735. {
  736. if($this->CLEAR) { $this->clear_error(); }
  737. if(empty($Address))
  738. {
  739. $this->ERROR = "is_email: No email address submitted";
  740. return false;
  741. }
  742. if(!ereg("@",$Address))
  743. {
  744. $this->ERROR = "is_email: Invalid, no @ symbol in string";
  745. return false;
  746. }
  747. list($User,$Host) = split("@",$Address);
  748. if ( (empty($User)) or (empty($Address)) )
  749. {
  750. $this->ERROR = "is_email: missing data [$User]@[$Host]";
  751. return false;
  752. }
  753. if( ($this->has_space($User)) or ($this->has_space($Host)) )
  754. {
  755. $this->ERROR = "is_email: Whitespace in [$User]@[$Host]";
  756. return false;
  757. }
  758. // Can't look for an MX only record as that precludes
  759. // CNAME only records. Thanks to everyone that slapped
  760. // me upside the head for this glaring oversite. :)
  761. if(!$this->is_host($Host,"ANY")) { return false; }
  762. return true;
  763. }
  764. // ************************************************************
  765. // Valid URL format? true or false
  766. // Checks format of a URL - does NOT handle query strings or
  767. // urlencoded data.
  768. function is_url ($Url = "")
  769. {
  770. if($this->CLEAR) { $this->clear_error(); }
  771. if (empty($Url))
  772. {
  773. $this->ERROR = "is_url: No URL submitted";
  774. return false;
  775. }
  776. if (!eregi("^((http://|https://|file://){0,1}" // type
  777. .'([a-z0-9-]{1,32}[.]){1,10}([a-z0-9]){2,3}' // domain
  778. .'(:[0-9]{1,5}){0,1}' // port
  779. .'([/\]{1,3}[a-z0-9_-~.]{0,64}){0,16}' // directory
  780. .'([?][a-z0-9=%;+]+){0,1}$|$)', // options
  781. trim($Url))) return false;
  782. else return true;
  783. }
  784. /*function is_url ($Url = "")
  785. {
  786. if($this->CLEAR) { $this->clear_error(); }
  787. if (empty($Url))
  788. {
  789. $this->ERROR = "is_url: No URL submitted";
  790. return false;
  791. }
  792. if(ereg("@",$Url))
  793. {
  794. $this->ERROR = "is_url: Invalid, no @ symbol in string";
  795. return false;
  796. }
  797. // Wow, the magic of parse_url!
  798. //echo $Url;
  799. $UrlElements = parse_url($Url);
  800. //echo $Url;
  801. //exit;
  802. if( (empty($UrlElements)) or (!$UrlElements) )
  803. {
  804. $this->ERROR = "is_url: Parse error reading [$Url]";
  805. return false;
  806. }
  807. $scheme = $UrlElements[scheme];
  808. $HostName = $UrlElements[host];
  809. if(empty($scheme))
  810. {
  811. $this->ERROR = "is_url: Missing protocol declaration";
  812. return false;
  813. }
  814. if(empty($HostName))
  815. {
  816. $this->ERROR = "is_url: No hostname in URL";
  817. return false;
  818. }
  819. if (!eregi("^(ht|f)tp",$scheme))
  820. {
  821. $this->ERROR = "is_url: No http:// or ftp://";
  822. return false;
  823. }
  824. if(!$this->is_hostname($HostName)) { return false; }
  825. return true;
  826. }*/
  827. // ************************************************************
  828. // URL responds to requests? true or false
  829. // This will obviously fail if you're not connected to
  830. // the internet, or if there are connection problems. (firewall etc)
  831. function url_responds ($Url = "")
  832. {
  833. global $php_errormsg;
  834. if($this->CLEAR) { $this->clear_error(); }
  835. if(empty($Url))
  836. {
  837. $this->ERROR = "url_responds: No URL submitted";
  838. return false;
  839. }
  840. if(!$this->is_url($Url)) { return false; }
  841. $fd = @fopen($Url,"r");
  842. if(!$fd)
  843. {
  844. $this->ERROR = "url_responds: Failed : $php_errormsg";
  845. return false;
  846. }
  847. else
  848. {
  849. @fclose($fd);
  850. return true;
  851. }
  852. }
  853. // ************************************************************
  854. // Valid phone number? true or false
  855. // Tries to validate a phone number
  856. // Strips (,),-,+ from number prior to checking
  857. // Less than 7 digits = fail
  858. // More than 13 digits = fail
  859. // Anything other than numbers after the stripping = fail
  860. function is_phone ($Phone = "")
  861. {
  862. if($this->CLEAR) { $this->clear_error(); }
  863. if(empty($Phone))
  864. {
  865. $this->ERROR = "is_phone: No Phone number submitted";
  866. return false;
  867. }
  868. $Num = $Phone;
  869. $Num = $this->strip_space($Num);
  870. $Num = eregi_replace("(\(|\)|\-|\+)","",$Num);
  871. /*$length=strlen($Phone);
  872. $length1=strlen(strstr($Phone,'0'));
  873. if($length==$length1)
  874. {
  875. $this->ERROR = "is_phone: All Zero are in Phone.";
  876. }
  877. */
  878. if(!$this->is_allnumbers($Num))
  879. {
  880. $this->ERROR = "is_phone: bad data in phone number";
  881. return false;
  882. }
  883. if ( (strlen($Num)) < 5)
  884. {
  885. $this->ERROR = "is_phone: number is too short [$Num][$Phone]";
  886. return false;
  887. }
  888. // 000 000 000 0000
  889. // CC AC PRE SUFX = max 13 digits
  890. if( (strlen($Num)) > 15)
  891. {
  892. $this->ERROR = "is_phone: number is too long [$Num][$Phone]";
  893. return false;
  894. }
  895. return true;
  896. }
  897. // ************************************************************
  898. // Valid, fully qualified hostname? true or false
  899. // Checks the -syntax- of the hostname, not it's actual
  900. // validity as a reachable internet host
  901. function is_hostname ($hostname = "")
  902. {
  903. if($this->CLEAR) { $this->clear_error(); }
  904. $web = false;
  905. if(empty($hostname))
  906. {
  907. $this->ERROR = "is_hostname: No hostname submitted";
  908. return false;
  909. }
  910. // Only a-z, 0-9, and "-" or "." are permitted in a hostname
  911. // Patch for POSIX regex lib by Sascha Schumann sas@schell.de
  912. $Bad = eregi_replace("[-A-Z 0-9\.]","",$hostname);
  913. if(!empty($Bad))
  914. {
  915. $this->ERROR = "is_hostname: invalid chars [$Bad]";
  916. return false;
  917. }
  918. // See if we're doing www.hostname.tld or hostname.tld
  919. if(eregi("^www\.",$hostname))
  920. {
  921. $web = true;
  922. }
  923. // double "." is a not permitted
  924. if(ereg("\.\.",$hostname))
  925. {
  926. $this->ERROR = "is_hostname: Double dot in [$hostname]";
  927. return false;
  928. }
  929. if(ereg("^\.",$hostname))
  930. {
  931. $this->ERROR = "is_hostname: leading dot in [$hostname]";
  932. return false;
  933. }
  934. $chunks = explode(".",$hostname);
  935. if( (gettype($chunks)) != "array")
  936. {
  937. $this->ERROR = "is_hostname: Invalid hostname, no dot seperator [$hostname]";
  938. return false;
  939. }
  940. $count = ( (count($chunks)) - 1);
  941. if($count < 1)
  942. {
  943. $this->ERROR = "is_hostname: Invalid hostname [$count] [$hostname]\n";
  944. return false;
  945. }
  946. // Bug that can't be killed without doing an is_host,
  947. // something.something will return TRUE, even if it's something
  948. // stupid like NS.SOMETHING (with no tld), because SOMETHING is
  949. // construed to BE the tld. The is_bigfour and is_country
  950. // checks should help eliminate this inconsistancy. To really
  951. // be sure you've got a valid hostname, do an is_host() on it.
  952. if( ($web) and ($count < 2) )
  953. {
  954. $this->ERROR = "is_hostname: Invalid hostname [$count] [$hostname]\n";
  955. return false;
  956. }
  957. $tld = $chunks[$count];
  958. if(empty($tld))
  959. {
  960. $this->ERROR = "is_hostname: No TLD found in [$hostname]";
  961. return false;
  962. }
  963. if(!$this->is_bigfour($tld))
  964. {
  965. if(!$this->is_country($tld))
  966. {
  967. $this->ERROR = "is_hostname: Unrecognized TLD [$tld]";
  968. return false;
  969. }
  970. }
  971. return true;
  972. }
  973. // ************************************************************
  974. function is_bigfour ($tld)
  975. {
  976. if(empty($tld))
  977. {
  978. return false;
  979. }
  980. if(eregi("^\.",$tld))
  981. {
  982. $tld = eregi_replace("^\.","",$tld);
  983. }
  984. $BigFour = array (com=>com,edu=>edu,net=>net,org=>org,aol=>aol);
  985. $tld = strtolower($tld);
  986. if(isset($BigFour[$tld]))
  987. {
  988. return true;
  989. }
  990. return false;
  991. }
  992. // ************************************************************
  993. // Hostname is a reachable internet host? true or false
  994. function is_host ($hostname = "", $type = "ANY")
  995. {
  996. if($this->CLEAR) { $this->clear_error(); }
  997. if(empty($hostname))
  998. {
  999. $this->ERROR = "is_host: No hostname submitted";
  1000. return false;
  1001. }
  1002. if(!$this->is_hostname($hostname)) { return false; }
  1003. /*if(!checkdnsrr($hostname,$type))
  1004. {
  1005. $this->ERROR = "is_host: no DNS records for [$hostname].";
  1006. return false;
  1007. }*/
  1008. return true;
  1009. }
  1010. // ************************************************************
  1011. // Dotted quad IPAddress within valid range? true or false
  1012. // Checks format, leading zeros, and values > 255
  1013. // Does not check for reserved or unroutable IPs.
  1014. function is_ipaddress ($IP = "")
  1015. {
  1016. if($this->CLEAR) { $this->clear_error(); }
  1017. if(empty($IP))
  1018. {
  1019. $this->ERROR = "is_ipaddress: No IP address submitted";
  1020. return false;
  1021. }
  1022. // 123456789012345
  1023. // xxx.xxx.xxx.xxx
  1024. $len = strlen($IP);
  1025. if( $len > 15 )
  1026. {
  1027. $this->ERROR = "is_ipaddress: too long [$IP][$len]";
  1028. return false;
  1029. }
  1030. $Bad = eregi_replace("([0-9\.]+)","",$IP);
  1031. if(!empty($Bad))
  1032. {
  1033. $this->ERROR = "is_ipaddress: Bad data in IP address [$Bad]";
  1034. return false;
  1035. }
  1036. $chunks = explode(".",$IP);
  1037. $count = count($chunks);
  1038. if ($count != 4)
  1039. {
  1040. $this->ERROR = "is_ipaddress: not a dotted quad [$IP]";
  1041. return false;
  1042. }
  1043. while ( list ($key,$val) = each ($chunks) )
  1044. {
  1045. if(ereg("^0",$val))
  1046. {
  1047. $this->ERROR = "is_ipaddress: Invalid IP segment [$val]";
  1048. return false;
  1049. }
  1050. $Num = $val;
  1051. settype($Num,"integer");
  1052. if($Num > 255)
  1053. {
  1054. $this->ERROR = "is_ipaddress: Segment out of range [$Num]";
  1055. return false;
  1056. }
  1057. }
  1058. return true;
  1059. } // end is_ipaddress
  1060. // ************************************************************
  1061. // IP address is valid, and resolves to a hostname? true or false
  1062. function ip_resolves ($IP = "")
  1063. {
  1064. if($this->CLEAR) { $this->clear_error(); }
  1065. if(empty($IP))
  1066. {
  1067. $this->ERROR = "ip_resolves: No IP address submitted";
  1068. return false;
  1069. }
  1070. if(!$this->is_ipaddress($IP))
  1071. {
  1072. return false;
  1073. }
  1074. $Hostname = gethostbyaddr($IP);
  1075. if($Hostname == $IP)
  1076. {
  1077. $this->ERROR = "ip_resolves: IP does not resolve.";
  1078. return false;
  1079. }
  1080. if($Hostname)
  1081. {
  1082. if(!checkdnsrr($Hostname))
  1083. {
  1084. $this->ERROR = "is_ipaddress: no DNS records for resolved hostname [$Hostname]";
  1085. return false;
  1086. }
  1087. if( (gethostbyname($Hostname)) != $IP )
  1088. {
  1089. $this->ERROR = "is_ipaddress: forward:reverse mismatch, possible forgery";
  1090. // Non-fatal, but it should be noted.
  1091. }
  1092. }
  1093. else
  1094. {
  1095. $this->ERROR = "ip_resolves: IP address does not resolve";
  1096. return false;
  1097. }
  1098. return true;
  1099. }
  1100. // ************************************************************
  1101. function browser_gen ()
  1102. {
  1103. if($this->CLEAR) { $this->clear_error(); }
  1104. $generation = "UNKNOWN";
  1105. $client = getenv("HTTP_USER_AGENT");
  1106. if(empty($client))
  1107. {
  1108. $this->ERROR = "browser_gen: No User Agent for Client";
  1109. return $generation;
  1110. }
  1111. $client = $this->strip_metas($client);
  1112. $agents = array(
  1113. 'Anonymizer' => "ANONYMIZER",
  1114. 'Ahoy' => "SPIDER",
  1115. 'Altavista' => "SPIDER",
  1116. 'Anzwers' => "SPIDER",
  1117. 'Arachnoidea' => "SPIDER",
  1118. 'Arachnophilia' => "SPIDER",
  1119. 'ArchitextSpider' => "SPIDER",
  1120. 'Backrub' => "SPIDER",
  1121. 'CherryPicker' => "SPAMMER",
  1122. 'Crescent' => "SPAMMER",
  1123. 'Duppies' => "SPIDER",
  1124. 'EmailCollector' => "SPAMMER",
  1125. 'EmailSiphon' => "SPAMMER",
  1126. 'EmailWolf' => "SPAMMER",
  1127. 'Extractor' => "SPAMMER",
  1128. 'Fido' => "SPIDER",
  1129. 'Fish' => "SPIDER",
  1130. 'GAIS' => "SPIDER",
  1131. 'Googlebot' => "SPIDER",
  1132. 'Gulliver' => "SPIDER",
  1133. 'HipCrime' => "SPAMMER",
  1134. 'Hamahakki' => "SPIDER",
  1135. 'ia_archive' => "SPIDER",
  1136. 'IBrowse' => "THIRD",
  1137. 'Incy' => "SPIDER",
  1138. 'InfoSeek' => "SPIDER",
  1139. 'KIT-Fireball' => "SPIDER",
  1140. 'Konqueror' => "THIRD",
  1141. 'libwww' => "SECOND",
  1142. 'LocalEyes' => "SECOND",
  1143. 'Lycos' => "SPIDER",
  1144. 'Lynx' => "SECOND",
  1145. 'Microsoft.URL' => "SPAMMER",
  1146. 'MOMspider' => "SPIDER",
  1147. 'Mozilla/1' => "FIRST",
  1148. 'Mozilla/2' => "SECOND",
  1149. 'Mozilla/3' => "THIRD",
  1150. 'Mozilla/4' => "FOURTH",
  1151. 'Mozilla/5' => "FIFTH",
  1152. 'Namecrawler' => "SPIDER",
  1153. 'NICErsPRO' => "SPAMMER",
  1154. 'Scooter' => "SPIDER",
  1155. 'sexsearch' => "SPIDER",
  1156. 'Sidewinder' => "SPIDER",
  1157. 'Slurp' => "SPIDER",
  1158. 'SwissSearch' => "SPIDER",
  1159. 'Ultraseek' => "SPIDER",
  1160. 'WebBandit' => "SPAMMER",
  1161. 'WebCrawler' => "SPIDER",
  1162. 'WiseWire' => "SPIDER",
  1163. 'Mozilla/3.0 (compatible; Opera/3' => "THIRD"
  1164. );
  1165. while ( list ($key,$val) = each ($agents) )
  1166. {
  1167. $key = $this->strip_metas($key);
  1168. if(eregi("^$key",$client))
  1169. {
  1170. unset($agents);
  1171. return $val;
  1172. }
  1173. }
  1174. unset($agents);
  1175. return $generation;
  1176. }
  1177. // ************************************************************
  1178. // United States valid state code? true or false
  1179. function is_state ($State = "")
  1180. {
  1181. if($this->CLEAR) { $this->clear_error(); }
  1182. if(empty($State))
  1183. {
  1184. $this->ERROR = "is_state: No state submitted";
  1185. return false;
  1186. }
  1187. if( (strlen($State)) != 2)
  1188. {
  1189. $this->ERROR = "is_state: Too many digits in state code";
  1190. return false;
  1191. }
  1192. $State = strtoupper($State);
  1193. // 50 states, Washington DC, Puerto Rico and the US Virgin Islands
  1194. $SCodes = array (
  1195. "AK" => 1,
  1196. "AL" => 1,
  1197. "AR" => 1,
  1198. "AZ" => 1,
  1199. "CA" => 1,
  1200. "CO" => 1,
  1201. "CT" => 1,
  1202. "DC" => 1,
  1203. "DE" => 1,
  1204. "FL" => 1,
  1205. "GA" => 1,
  1206. "HI" => 1,
  1207. "IA" => 1,
  1208. "ID" => 1,
  1209. "IL" => 1,
  1210. "IN" => 1,
  1211. "KS" => 1,
  1212. "KY" => 1,
  1213. "LA" => 1,
  1214. "MA" => 1,
  1215. "MD" => 1,
  1216. "ME" => 1,
  1217. "MI" => 1,
  1218. "MN" => 1,
  1219. "MO" => 1,
  1220. "MS" => 1,
  1221. "MT" => 1,
  1222. "NC" => 1,
  1223. "ND" => 1,
  1224. "NE" => 1,
  1225. "NH" => 1,
  1226. "NJ" => 1,
  1227. "NM" => 1,
  1228. "NV" => 1,
  1229. "NY" => 1,
  1230. "OH" => 1,
  1231. "OK" => 1,
  1232. "OR" => 1,
  1233. "PA" => 1,
  1234. "PR" => 1,
  1235. "RI" => 1,
  1236. "SC" => 1,
  1237. "SD" => 1,
  1238. "TN" => 1,
  1239. "TX" => 1,
  1240. "UT" => 1,
  1241. "VA" => 1,
  1242. "VI" => 1,
  1243. "VT" => 1,
  1244. "WA" => 1,
  1245. "WI" => 1,
  1246. "WV" => 1,
  1247. "WY" => 1
  1248. );
  1249. if(!isset($SCodes[$State]))
  1250. {
  1251. $this->ERROR = "is_state: Unrecognized state code [$State]";
  1252. return false;
  1253. }
  1254. // Lets not have this big monster camping in memory eh?
  1255. unset($SCodes);
  1256. return true;
  1257. }
  1258. // ************************************************************
  1259. // Valid postal zip code? true or false
  1260. function is_zip ($zipcode = "")
  1261. {
  1262. if($this->CLEAR) { $this->clear_error(); }
  1263. if(empty($zipcode))
  1264. {
  1265. $this->ERROR = "is_zip: No zipcode submitted";
  1266. return false;
  1267. }
  1268. $Bad = eregi_replace("([-0-9]+)","",$zipcode);
  1269. if(!empty($Bad))
  1270. {
  1271. $this->ERROR = "is_zip: Bad data in zipcode [$Bad]";
  1272. return false;
  1273. }
  1274. $Num = eregi_replace("\-","",$zipcode);
  1275. $len = strlen($Num);
  1276. if ( ($len > 10) or ($len < 5) )
  1277. {
  1278. $this->ERROR = "is_zipcode: Invalid length [$len] for zipcode";
  1279. return false;
  1280. }
  1281. return true;
  1282. }
  1283. // ************************************************************
  1284. // Valid postal country code?
  1285. // Returns the name of the country, or null on failure
  1286. // Current array recognizes ~232 country codes.
  1287. // I don't know if all of these are 100% accurate.
  1288. // You don't wanna know how difficult it was just getting
  1289. // this listing in here. :)
  1290. function is_country ($countrycode = "")
  1291. {
  1292. if($this->CLEAR) { $this->clear_error(); }
  1293. $Return = "";
  1294. if(empty($countrycode))
  1295. {
  1296. $this->ERROR = "is_country: No country code submitted";
  1297. return $Return;
  1298. }
  1299. $countrycode = strtolower($countrycode);
  1300. if( (strlen($countrycode)) != 2 )
  1301. {
  1302. $this->ERROR = "is_country: 2 digit codes only [$countrycode]";
  1303. return $Return;
  1304. }
  1305. // Now for a really big array
  1306. // Dominican Republic, cc = "do" because it's a reserved
  1307. // word in PHP. That parse error took 10 minutes of
  1308. // head-scratching to figure out :)
  1309. // A (roughly) 3.1 Kbyte array
  1310. $CCodes = array (
  1311. "do" => "Dominican Republic",
  1312. ad => "Andorra",
  1313. ae => "United Arab Emirates",
  1314. af => "Afghanistan",
  1315. ag => "Antigua and Barbuda",
  1316. ai => "Anguilla",
  1317. al => "Albania",
  1318. am => "Armenia",
  1319. an => "Netherlands Antilles",
  1320. ao => "Angola",
  1321. aq => "Antarctica",
  1322. ar => "Argentina",
  1323. as1 => "American Samoa",
  1324. at => "Austria",
  1325. au => "Australia",
  1326. aw => "Aruba",
  1327. az => "Azerbaijan",
  1328. ba => "Bosnia Hercegovina",
  1329. bb => "Barbados",
  1330. bd => "Bangladesh",
  1331. be => "Belgium",
  1332. bf => "Burkina Faso",
  1333. bg => "Bulgaria",
  1334. bh => "Bahrain",
  1335. bi => "Burundi",
  1336. bj => "Benin",
  1337. bm => "Bermuda",
  1338. bn => "Brunei Darussalam",
  1339. bo => "Bolivia",
  1340. br => "Brazil",
  1341. bs => "Bahamas",
  1342. bt => "Bhutan",
  1343. bv => "Bouvet Island",
  1344. bw => "Botswana",
  1345. by => "Belarus (Byelorussia)",
  1346. bz => "Belize",
  1347. ca => "Canada",
  1348. cc => "Cocos Islands",
  1349. cd => 'Congo, The Democratic Republic of the',
  1350. cf => "Central African Republic",
  1351. cg => "Congo",
  1352. ch => "Switzerland",
  1353. ci => "Ivory Coast",
  1354. ck => "Cook Islands",
  1355. cl => "Chile",
  1356. cm => "Cameroon",
  1357. cn => "China",
  1358. co => "Colombia",
  1359. cr => "Costa Rica",
  1360. cs => "Czechoslovakia",
  1361. cu => "Cuba",
  1362. cv => "Cape Verde",
  1363. cx => "Christmas Island",
  1364. cy => "Cyprus",
  1365. cz => 'Czech Republic',
  1366. de => "Germany",
  1367. dj => "Djibouti",
  1368. dk => 'Denmark',
  1369. dm => "Dominica",
  1370. dz => "Algeria",
  1371. ec => "Ecuador",
  1372. ee => "Estonia",
  1373. eg => "Egypt",
  1374. eh => "Western Sahara",
  1375. er => 'Eritrea',
  1376. es => "Spain",
  1377. et => "Ethiopia",
  1378. fi => "Finland",
  1379. fj => "Fiji",
  1380. fk => "Falkland Islands",
  1381. fm => "Micronesia",
  1382. fo => "Faroe Islands",
  1383. fr => "France",
  1384. fx => 'France, Metropolitan FX',
  1385. ga => "Gabon",
  1386. gb => 'United Kingdom (Great Britain)',
  1387. gd => "Grenada",
  1388. ge => "Georgia",
  1389. gf => "French Guiana",
  1390. gh => "Ghana",
  1391. gi => "Gibraltar",
  1392. gl => "Greenland",
  1393. gm => "Gambia",
  1394. gn => "Guinea",
  1395. gp => "Guadeloupe",
  1396. gq => "Equatorial Guinea",
  1397. gr => "Greece",
  1398. gs => 'South Georgia and the South Sandwich Islands',
  1399. gt => "Guatemala",
  1400. gu => "Guam",
  1401. gw => "Guinea-bissau",
  1402. gy => "Guyana",
  1403. hk => "Hong Kong",
  1404. hm => "Heard and McDonald Islands",
  1405. hn => "Honduras",
  1406. hr => "Croatia",
  1407. ht => "Haiti",
  1408. hu => "Hungary",
  1409. id => "Indonesia",
  1410. ie => "Ireland",
  1411. il => "Israel",
  1412. in => "India",
  1413. io => "British Indian Ocean Territory",
  1414. iq => "Iraq",
  1415. ir => "Iran",
  1416. is => "Iceland",
  1417. it => "Italy",
  1418. jm => "Jamaica",
  1419. jo => "Jordan",
  1420. jp => "Japan",
  1421. ke => "Kenya",
  1422. kg => "Kyrgyzstan",
  1423. kh => "Cambodia",
  1424. ki => "Kiribati",
  1425. km => "Comoros",
  1426. kn => "Saint Kitts and Nevis",
  1427. kp => "North Korea",
  1428. kr => "South Korea",
  1429. kw => "Kuwait",
  1430. ky => "Cayman Islands",
  1431. kz => "Kazakhstan",
  1432. la => "Laos",
  1433. lb => "Lebanon",
  1434. lc => "Saint Lucia",
  1435. li => "Lichtenstein",
  1436. lk => "Sri Lanka",
  1437. lr => "Liberia",
  1438. ls => "Lesotho",
  1439. lt => "Lithuania",
  1440. lu => "Luxembourg",
  1441. lv => "Latvia",
  1442. ly => "Libya",
  1443. m

Large files files are truncated, but you can click here to view the full file