1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
| function checkVAT($iso_country_code,$vatcode) {
$vat_onlydigits = substr($vatcode, 2);
$str_vars = "Lang=EN&MS=$iso_country_code&VAT=$vat_onlydigits";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_TIMEOUT, 3);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $str_vars);
curl_setopt ($ch, CURLOPT_URL,"http://europa.eu.int/comm/taxation_customs/vies/cgi-bin/viesquer");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
if($response = curl_exec($ch))
{
$search_for_true = "Yes, valid VAT number";
$search_for_false = "No, invalid VAT number";
if(strstr($response,$search_for_true))
{
$return = "TRUE";
}
elseif(strstr($response,$search_for_false))
{
$return = "FALSE";
}
else
{
$return = "ERROR";
}
}
else
{
$return = "ERROR";
}
curl_close ($ch);
return $return;
} |