---
title: "BIN Lookup API PHP Guide"
description: "Call the BIN Lookup API from PHP with cURL. Handle current error codes and send a batch lookup."
section: "Guides"
url: "https://binlookupapi.com/docs/guides/php/"
markdown_url: "https://binlookupapi.com/docs/guides/php.md"
---
# BIN lookup with PHP

This page uses PHP with the curl extension. Create an API key in the [quickstart](/docs/quickstart/). Put the key in the environment variable `BINLOOKUP_API_KEY`.

## Look up one BIN

```php
<?php
$apiKey = getenv("BINLOOKUP_API_KEY");
$ch = curl_init("https://api.binlookupapi.com/v1/bin");
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HEADER => true,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer " . $apiKey,
        "Content-Type: application/json",
    ],
    CURLOPT_POSTFIELDS => json_encode(["number" => 42467101]),
]);

$raw = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
curl_close($ch);

$headers = substr($raw, 0, $headerSize);
$body = json_decode(substr($raw, $headerSize), true);

if ($status === 200) {
    echo $body["data"]["scheme"], "\n";
} elseif ($status === 401) {
    fwrite(STDERR, "The API key is missing or not valid.\n");
} elseif ($status === 403) {
    fwrite(STDERR, $body["error"] . ": " . $body["message"] . "\n");
} elseif ($status === 404) {
    fwrite(STDERR, "The BIN is not in the data.\n");
} elseif ($status === 429) {
    fwrite(STDERR, "The daily quota is used.\n");
} elseif ($status === 400) {
    fwrite(STDERR, $body["message"] . "\n");
} else {
    fwrite(STDERR, "The API returned HTTP {$status}.\n");
}
```

`data` contains the fields in the [API reference](/docs/api-reference/#response-fields). On BLAPI-150KPM and above, read `$body["meta"]["longer_bin_available"]`.

The quota headers are in `$headers`. There is no limit on requests per second.

## Look up many BINs

`POST /v1/bins` accepts 1 to 2,000 values. It requires BLAPI-500KPM, or a test-mode organisation.

```php
<?php
$ch = curl_init("https://api.binlookupapi.com/v1/bins");
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 60,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer " . getenv("BINLOOKUP_API_KEY"),
        "Content-Type: application/json",
    ],
    CURLOPT_POSTFIELDS => json_encode([
        "numbers" => [400062, "400597", 99999999],
    ]),
]);

$body = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($status === 403 && ($body["error"] ?? "") === "FEATURE_NOT_AVAILABLE") {
    fwrite(STDERR, "Batch lookup needs the BLAPI-500KPM plan.\n");
    exit(1);
}

foreach ($body["results"] as $item) {
    if (isset($item["data"])) {
        echo $item["number"], " ", $item["data"]["scheme"], "\n";
    } else {
        echo $item["number"], " ", $item["error"], "\n";
    }
}
```

See [Batch lookups](/docs/batch-lookups/). One item error does not stop the other items.

## Related pages

- [Python guide](/docs/guides/python/)
- [Java guide](/docs/guides/java/)
- [API reference](/docs/api-reference/)
- [API keys](/docs/api-keys/)
- [Billing](/docs/subscriptions/)
