Hi there Weedpacket,
The error is because it's trusting that the data was validated properly in the if/else section posted and it's not a valid array, since it never should have gotten that far. If you enter U15HLEA2601 into the text box, the error will go away because that input is a proper input(all letters and numbers and under 17 chars.
I'm completely flummoxed. I've stripped parts out to see if there was a conflict and I've echoed and print_r'ed everything I can think of. It's working with the information I've inputted it's just not handling it the way I intended.
Here's the entire code I'm working with(I'll strip the unnecessary HTML:
<?php
function random_pic($dir = './images/bg')
{
$files = glob($dir . '/*.*');
$file = array_rand($files);
//$files[$file] = ltrim($files[$file], '.');
//echo $files[$file];
return $files[$file];
}
// test VIN: U15HLEA2601
$match1 = array(
/* Group 1: Vehicle type */
array("group" => "1", "strpos" => "0, 3", "code" => "F10", "desc" => "F100 2 Wheel Drive"),
array("group" => "1", "strpos" => "0, 3", "code" => "X10", "desc" => "F100 2 Wheel Drive Super Cab"),
array("group" => "1", "strpos" => "0, 3", "code" => "F11", "desc" => "F100 4 Wheel Drive"),
array("group" => "1", "strpos" => "0, 3", "code" => "F14", "desc" => "F150 4 Wheel Drive"),
array("group" => "1", "strpos" => "0, 3", "code" => "X14", "desc" => "F150 4 Wheel Drive Super Cab"),
array("group" => "1", "strpos" => "0, 3", "code" => "F15", "desc" => "F150 2 Wheel Drive"),
array("group" => "1", "strpos" => "0, 3", "code" => "X15", "desc" => "F150 2 Wheel Drive Super Cab"),
array("group" => "1", "strpos" => "0, 3", "code" => "F25", "desc" => "F250 2 Wheel Drive"),
array("group" => "1", "strpos" => "0, 3", "code" => "X25", "desc" => "F250 2 Wheel Drive Super Cab"),
array("group" => "1", "strpos" => "0, 3", "code" => "F26", "desc" => "F250 4 Wheel Drive"),
array("group" => "1", "strpos" => "0, 3", "code" => "X26", "desc" => "F250 4 Wheel Drive Super Cab"),
array("group" => "1", "strpos" => "0, 3", "code" => "U15", "desc" => "4 Wheel Drive Bronco Wagon"),
/* Group 2: Engine */
array("group" => "2", "strpos" => "3, 1", "code" => "A", "desc" => "6Cyl 240 CID 4.0L 1BBL Carburetor 1973-1974"),
array("group" => "2", "strpos" => "3, 1", "code" => "B", "desc" => "6Cyl 300 CID 4.9L 1BBL Carburetor 1973-1979"),
array("group" => "2", "strpos" => "3, 1", "code" => "G", "desc" => "V8 302 CID 5.0L 2BBL Carburetor 1973-1979"),
array("group" => "2", "strpos" => "3, 1", "code" => "H", "desc" => "V8 351M CID 5.8L 2BBL Carburetor 1977-1979"),
array("group" => "2", "strpos" => "3, 1", "code" => "Y", "desc" => "V8 360 CID 5.9L 2BBL Carburetor 1973-1976"),
//array("group" => "2", "strpos" => "3, 1", "code" => "H", "desc" => "V8 390 CID 6.4L 2BBL Carburetor 1973-1976"),
array("group" => "2", "strpos" => "3, 1", "code" => "M", "desc" => "V8 390 CID 6.4L 4BBL Carburetor 1974-1976"),
array("group" => "2", "strpos" => "3, 1", "code" => "S", "desc" => "V8 400 CID 6.6L 2BBL Carburetor 1977-1979"),
array("group" => "2", "strpos" => "3, 1", "code" => "J", "desc" => "V8 460 CID 7.5L 4BBL Carburetor 1973-1979"),
/* Group 3: Assembly Plant */
array("group" => "3", "strpos" => "4, 1", "code" => "B", "desc" => "Oakville, Ontario, Canada"),
array("group" => "3", "strpos" => "4, 1", "code" => "C", "desc" => "Ontario, Canada"),
array("group" => "3", "strpos" => "4, 1", "code" => "E", "desc" => "Mahwah, NJ, USA"),
array("group" => "3", "strpos" => "4, 1", "code" => "H", "desc" => "Lorain, OH, USA"),
array("group" => "3", "strpos" => "4, 1", "code" => "I", "desc" => "Highland Park, MI, USA"),
array("group" => "3", "strpos" => "4, 1", "code" => "K", "desc" => "Kansas City, MO, USA"),
array("group" => "3", "strpos" => "4, 1", "code" => "L", "desc" => "Michigan Truck Plant, Wayne, MI, USA"),
array("group" => "3", "strpos" => "4, 1", "code" => "N", "desc" => "Norfolk, VA, USA"),
array("group" => "3", "strpos" => "4, 1", "code" => "P", "desc" => "Twin Cities, MN, USA"),
array("group" => "3", "strpos" => "4, 1", "code" => "R", "desc" => "San Jose, CA, USA"),
array("group" => "3", "strpos" => "4, 1", "code" => "S", "desc" => "Allen Park, MI, USA"),
array("group" => "3", "strpos" => "4, 1", "code" => "U", "desc" => "Louisville, KY, USA"),
array("group" => "3", "strpos" => "4, 1", "code" => "V", "desc" => "Kentucky Truck Plant, Louisville, KY, USA")
);
//$_GET['vin'] = "U15HLEA2601";
//print_r($_GET);
if(ISSET($_GET['vin'])){
echo 'GET data: '.$_GET['vin'];
$vin = strtoupper($_GET['vin']);
/* Letters and numbers only */
if(!ctype_alnum($vin)) {
$blurb = "Hey, buddy! your VIN will only have letters and numbers! Try it again.";
}elseif(strlen($vin) > 17){
$blurb = "My, what a big VIN you have... In fact, it's too big. Someone's compensating.";
}else{
/* Basic checks have passed. Let's see if we can decode it. */
$mc = 1;
/* This will loop through all VIN arrays until we either run out or a match is found */
while (ISSET(${'match'.$mc}) AND !ISSET($matchfound)){ // This loops through each VIN format array and will stop if we define $matchfound in the previous array.
/* Define it right away, then take that **** away if we find a discrepency */
$matchfound = 'hellsyeah';
/* Get a fresh start */
UNSET($result);
foreach(${'match'.$mc} AS $match){
/* We are now inside a VIN format array. Loop through array, making sure to check for previous group match */
$group = $match['group'];
$strpos = $match['strpos'];
$code = $match['code'];
$desc = $match['desc'];
/* Before continuing, check for previous group's match */
if($group > 1 AND !ISSET($result[$group-1])){
UNSET($matchfound);
break;
}
$strpos = explode(", ", $strpos);
$pos = $strpos[0];
$len = $strpos[1];
$vinchunk = substr($vin, $pos, $len);
if($vinchunk == $code){
$result[$group]['code'] = $code;
$result[$group]['desc'] = $desc;
}
}
/* Need to check final result, since there's no subsequent loop to do it */
if(!ISSET($result[$group])){
UNSET($matchfound);
}
$mc = ++$mc;
}
}
$vindate = substr($vin, 5, 6);
$vdchar = str_split($vindate);
$alpha = 0;
foreach($vdchar AS $vd){
if(ctype_alpha($vd)){
$alpha = ++$alpha;
}
}
if($alpha == 2){
/* Vindate contains two alpha chars */
if(strcmp($vindate, "AE0001") >= 0 AND strcmp($vindate, "CK9999") <= 0){
$year = '1978';
}elseif(strcmp($vindate, "DC0001") >= 0 AND strcmp($vindate, "FK9000") <= 0){
$year = '1979';
};
}elseif($alpha == 1){
/* Vindate contains one alpha chars */
if(strcmp($vindate, "Q00001") >= 0 AND strcmp($vindate, "S60000") <= 0){
$year = '1973';
}elseif(strcmp($vindate, "S60001") >= 0 AND strcmp($vindate, "V20000") <= 0){
$year = '1974';
}elseif(strcmp($vindate, "V20001") >= 0 AND strcmp($vindate, "X40000") <= 0){
$year = '1975';
}elseif(strcmp($vindate, "A00001") >= 0 AND strcmp($vindate, "D25000") <= 0){
$year = '1976';
}elseif(strcmp($vindate, "X80001") >= 0 AND strcmp($vindate, "Z25000") <= 0){
$year = '1977';
};
}else{
/* Vindate contains no alpha chars because we checked at the beginning of the process to make sure all is alphanumeric. */
if(strcmp($vindate, "000001") >= 0 AND strcmp($vindate, "099999") <= 0){
$year = '1977';
};
}
if(!ISSET($year)){
UNSET($matchfound);
}else{
$group = ++$group;
$result[$group]['code'] = $vindate;
$result[$group]['desc'] = 'Manufactured in '.$year;
}
$blurb = '<h2>We know a little sumfin sumfin about that VIN:</h2><br>
<table>';
foreach($result AS $res){
$blurb .= '
<tr>
<td><b>'.$res['code'].':</b> </td>
<td>'.$res['desc'].'</td>
</tr>';
}
$blurb .='
</table>';
}
//print_r($result);
echo '
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<div id="content">
<div align="center">
<h1>Schwim's VIN Debofuscat-O-Matic 2000</h1>
<p>
Currently, we are testing 73-79 Ford VINs only. Once we are sure we have that sorted, we can spread out the love to other ranges.
</p>
<form method="GET" name="vintricks" id="vintricks" action="/vintricks">
<table>
<tr>
<td>
<input type="text" name="vin" value="'.$vin.'" placeholder="VIN goes here!">
</td>
</tr>
</table>
</form>
<br><br>
'.$blurb.'<br>
<br>
</div>
</div>
</body>
</html>
';
?>