PHP – Webmaster’s choice

VinLINK service is used in a lot of PHP based websites. Below we demonstrate how to build a simple php vin decoder.

This is a sample code that decodes basic YMM information from any VIN number.
To begin, we access VinLINK service using digest authentication then, we fetch a report of type BASIC_LIGHT based on the $vin variable.

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_USERPWD, get_option('vd_user') . ":" . get_option('vd_password'));
curl_setopt($ch, CURLOPT_URL, "https://service.vinlink.com/report?type=BASIC_LIGHT&vin=" . $vin);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$report = curl_exec($ch);
curl_close($ch);

Afterwards the report is stored in $report variable, after which we convert the report to XML form, and use xpath selector to locate the portion of the report containing our data.

For the next process, we use the Model_Year, Make and Model attributes.

$xml = simplexml_load_string($report);
$decoded = $xml->xpath("REPORT/VINPOWER/VIN/DECODED");
$year = (string)$decoded[0]['Model_Year'];
$make = (string)$decoded[0]['Make'];
$model = (string)$decoded[0]['Model'];

Then we can display the variables. Voila, VIN Decoded!

Questions about php vin decoder implementation? Please, contact us.