<?php

function cardinfo($card){
    $ctx = stream_context_create(array('http'=>
        array(
            'timeout' => 2,  //1200 Seconds is 20 Minutes
        )
    ));
    $card = str_replace(" ", "", $card);
    $bin = substr($card,0,6);
    try {
        $ret = file_get_contents("https://lookup.binlist.net/$bin", false, $ctx);
        if ($ret != false){
            $data = json_decode($ret,true);
            if($data['scheme']) {
                return array(
                    'bank' => $data['bank']['name'],
                    'country_name' => $data['country']['name'],
                    'country' => $data['country']['alpha2'],
                    'currency' => $data['country']['currency'],
                    'emoji' => $data['country']['emoji'],
                    'scheme' => $data['scheme'],
                    'brand' => $data['brand'],
                    'type' => $data['type'],
                    'bin' => $bin
                );
            }
            else {
                return false;
            }
        } else {
            return false;
        }
    } catch(Exception $e) {
        return false;
    }
}

?>