How to Get a Domain's Age in PHP

November 04, 2026
How to Get a Domain's Age in PHP

You need to decide whether to trust or flag a newly submitted domain in your app. By the end of this guide, you’ll fetch a domain’s age and expiration details via the Klazify API, wire it into your pipeline (including a PHP example), and use those fields to score signups, gate risky traffic, and enrich records in your CRM.

Why Klazify is the right API for domain age, trust, and classification

When you’re evaluating signups, partners, or ad inventory, domain registration signals are a fast way to spot risk. A domain registered last week behaves differently than one that’s decades old. Klazify pairs accurate domain age and expiration data with full website classification, so you can combine lifecycle signals with content context in one call stack.

Illustration: How to Get a Domain's Age in PHP
  • Accurate website categorization using AI: In addition to domain age, Klazify analyzes on-page content (not just whois metadata) to assign precise IAB-mapped categories. That lets you factor both how old a domain is and what it actually publishes.
  • Global coverage: Age and expiration checks, plus classification, work for domains across regions and languages—useful when your user base or ad supply is international.
  • Real-time analysis: Freshly registered domains often change quickly. Klazify focuses on up-to-date results instead of static lists.
  • Industry-level categories: With IAB taxonomy available from the same API surface, you can apply your brand-safety or content policies alongside age thresholds.
  • Simple API integration: Straightforward REST endpoints with bearer auth, returning JSON that plugs directly into your enrichment or risk scoring jobs.
  • Compliance and filtering: Combine domain_age_days_ago with content categories to block newly minted domains in sensitive categories or to quarantine signups for review.

Get started any time with a 7-day trial on the Starter plan ($39.99/mo), and note that failed or unreachable calls are not billed. Create your free account here: Register. You can also explore the product at klazify.com.

What you’ll build: a domain age check for signups and traffic

The goal is to programmatically retrieve:

  • domain_age_date: when the domain was first registered
  • domain_age_days_ago: how many days ago it was registered
  • domain_expiration_date: the current expiration date
  • domain_expiration_days_left: the number of days until expiration

Then you’ll enforce policies such as:

  • Block or review signups with domain_age_days_ago below your threshold.
  • Mark leads that have domain_expiration_days_left below a cutoff for re-verification.
  • Cache and reuse results per domain to minimize latency and cost.

Endpoint and parameters

Use the dedicated domain expiration endpoint. Send a POST request with bearer authentication and a JSON body containing the URL you wish to analyze:

  • Endpoint: https://www.klazify.com/api/domain_expiration
  • Method: POST
  • Headers: Authorization: Bearer YOUR_API_KEY, Content-Type: application/json
  • Body: {"url": "https://example.com"}

Consult the Documentation for additional integration details. For account management, see the MCP.

Quick start: curl request you can paste

This request demonstrates the required headers and body shape. Replace YOUR_API_KEY with your actual token.

curl -X POST "https://www.klazify.com/api/domain_expiration" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://cbsnews.com"}'

Official sample response and how to use it

The response below shows where to find the domain registration fields you’ll consume. Keep in mind that the same overall JSON format may include classification and company information when you use the main categorization endpoint.


{
    "domain": {
        "categories": [
            {
                "confidence": 0.92,
                "name": "/Computers & Electronics/Consumer Electronics",
                "IAB-632-596": "Consumer Electronics/Technology & Computing/Consumer Electronics"
            },
            {
                "confidence": 0.89,
                "name": "/Internet & Telecom/Mobile & Wireless/Mobile Phones"
            }
        ],
        "social_media": null,
        "logo_url": "https://klazify.s3.amazonaws.com/2110787991611585019600ed5fb1d1300.04730104.png"
    },
    "success": true,
    "objects": {
        "company": {
            "url": "https://www.apple.com/",
            "name": "Apple",
            "city": "Cupertino",
            "stateCode": "CA",
            "countryCode": "US",
            "employeesRange": "100K+",
            "revenue": 274515000000,
            "raised": null,
            "tags": [
                "E-commerce",
                "Consumer Electronics",
                "Mobile",
                "B2C"
            ],
            "tech": [
                "omniture_adobe_analytics",
                "atlassian_confluence",
                "successfactors",
                "apache_apex",
                "talend",
                "oracle_peoplesoft",
                "salesforce",
                "stripe",
                "dell_boomi_atomsphere",
                "gigya",
                "sage_50cloud",
                "quickbooks",
                "webmethods",
                "apache_tomcat",
                "alteryx",
                "tibco_rendezvous",
                "atlassian_jira",
                "..."
            ]
        }
    },
    "domain_registration_data": {
        "domain_age_date": "1987-02-19",
        "domain_age_days_ago": "13026",
        "domain_expiration_date": "2030-02-20",
        "domain_expiration_days_left": "123"
    },
    "similar_domains": [
        "bestbuy.com",
        "icloud.com",
        "microsoft.com",
        "macrumors.com",
        "google.com",
        "samsung.com",
        "twitter.com",
        "hp.com",
        "bhphotovideo.com",
        "dell.com"
    ]
}

Use these fields under domain_registration_data:

  • domain_age_date: First registration date (YYYY-MM-DD).
  • domain_age_days_ago: Days since registration (string-encoded integer).
  • domain_expiration_date: Current expiration date (YYYY-MM-DD).
  • domain_expiration_days_left: Days until expiration (string-encoded integer).

Operational tips:

  • Dates are provided as date-only strings. If you need timezone-aware logic, treat them as UTC dates at 00:00:00.
  • domain_age_days_ago and domain_expiration_days_left are strings you should parse into integers before comparing with thresholds.
  • When a domain is new or the registrar data is limited, some fields may be missing or empty. Always implement null checks.

PHP example: enrich a signup with domain age

The snippet below posts a URL to the domain expiration endpoint, decodes the JSON, and applies a basic age-based rule. You can adapt it to your signup form handler or scheduled enrichment job.

<?php
$apiKey = 'YOUR_API_KEY';
$endpoint = 'https://www.klazify.com/api/domain_expiration';

$payload = json_encode([
  'url' => 'https://example.com'
]);

$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
  'Authorization: Bearer ' . $apiKey,
  'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$err = curl_error($ch);
curl_close($ch);

if ($err || $httpCode < 200 || $httpCode >= 300) {
  // Failed or unreachable calls are not billed.
  // Decide whether to retry, queue, or degrade gracefully.
  error_log('Klazify error: ' . ($err ?: 'HTTP ' . $httpCode));
  exit;
}

$data = json_decode($response, true);

// Always check keys exist
$reg = $data['domain_registration_data'] ?? null;
if (!$reg) {
  // Fallback if registration data is unavailable
  // e.g., mark as needs_review
  exit;
}

$ageDays = isset($reg['domain_age_days_ago']) ? (int)$reg['domain_age_days_ago'] : null;
$daysLeft = isset($reg['domain_expiration_days_left']) ? (int)$reg['domain_expiration_days_left'] : null;

// Example policy
$tooNew = $ageDays !== null && $ageDays < 14;
$expiringSoon = $daysLeft !== null && $daysLeft < 30;

// Persist enriched signals to your user or lead record
// e.g., save $reg['domain_age_date'], $ageDays, $reg['domain_expiration_date'], $daysLeft

if ($tooNew) {
  // Flag signup for manual review
}

if ($expiringSoon) {
  // Schedule re-verification reminder
}
?>

For production, add retries with backoff, instrument timeouts, and cache by domain (see the caching section below).

JavaScript example: evaluate a domain on the edge

If you run enrichment in Node.js or at the edge (serverless), you can call the same endpoint and act on age thresholds inline.

import fetch from 'node-fetch';

const API_KEY = 'YOUR_API_KEY';
const ENDPOINT = 'https://www.klazify.com/api/domain_expiration';

async function getDomainAge(url) {
  const res = await fetch(ENDPOINT, {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${API_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ url })
  });

  if (!res.ok) {
    // Failed or unreachable calls are not billed.
    throw new Error(`Klazify HTTP ${res.status}`);
  }

  const json = await res.json();
  const reg = json.domain_registration_data || {};

  const ageDate = reg.domain_age_date || null;
  const ageDays = reg.domain_age_days_ago ? parseInt(reg.domain_age_days_ago, 10) : null;
  const expDate = reg.domain_expiration_date || null;
  const expDays = reg.domain_expiration_days_left ? parseInt(reg.domain_expiration_days_left, 10) : null;

  return { ageDate, ageDays, expDate, expDays };
}

(async () => {
  const { ageDate, ageDays, expDate, expDays } = await getDomainAge('https://example.com');

  // Policy examples
  const isTooNew = ageDays !== null && ageDays < 7;
  const isExpiringSoon = expDays !== null && expDays < 14;

  console.log({ ageDate, ageDays, expDate, expDays, isTooNew, isExpiringSoon });
})();

How the fields translate into decisions

Field What it tells you Typical actions Edge cases
domain_age_date First registration date (YYYY-MM-DD) Store as canonical registration timestamp Missing for some TLDs or new domains
domain_age_days_ago Days since registration (string-encoded) Compare to your risk threshold (e.g., 7–30 days) Parse to integer; handle null or non-numeric
domain_expiration_date Expiration date (YYYY-MM-DD) Plan re-verification or renewal reminders Some registrars mask data; verify downstream
domain_expiration_days_left Days until expiration (string-encoded) Flag expiring soon for additional checks Parse to integer; can be null for some records

Combining age with classification for stronger policies

If your workflow also needs content context or brand-safety signals, you can call the main categorization endpoint to retrieve IAB-mapped categories and related company data. The official example above shows categories under domain.categories. Using both:

  • Block brand-sensitive categories when the domain is too new.
  • Allowlist long-lived domains in low-risk categories to reduce friction.
  • Route mixed signals to manual review (e.g., new domain but neutral category).

Explore all available fields and endpoints in the Documentation.

Batching, rate control, and resilience

  • Batching: If you need to score many domains, queue them and send requests concurrently up to a safe concurrency that meets your latency goals. Persist results per domain to avoid duplicate calls.
  • Caching: Cache domain age and expiration data keyed by the registrable domain. Choose a TTL that fits your SLA; domains don’t change age quickly, but expiration can approach over time. Re-check before critical events (e.g., provisioning or ad flight starts).
  • Retries: Implement bounded retries with jitter for transient network errors. Since failed or unreachable calls are not billed, it’s safe to retry within reason.
  • Backoff: When you detect sustained failures, back off to protect your queue and respect service health.

Handling unknown or newly registered domains

Occasionally, a response may have partial or missing registration fields. For example, domain_age_days_ago can be null for some brand-new or masked registrations. Plan for:

  • Graceful degradation: Default to “needs_review” when critical fields are missing.
  • Deferred checks: Queue a recheck after several hours or on the next login.
  • User prompts: Ask for an alternate domain or proof if high risk and you can’t verify age.

Mapping to your own taxonomy and data model

If you maintain your own domain trust tiers, map Klazify fields into stable columns for analysis and alerts:

  • trust_age_bucket: derive from domain_age_days_ago (e.g., 0–6, 7–29, 30+).
  • exp_risk_bucket: derive from domain_expiration_days_left.
  • content_class: optional, from domain.categories[ ].name (IAB-aligned).

Because Klazify supports IAB taxonomy mapping, it’s straightforward to align content signals with your ad tech or brand safety policies while keeping age-based trust signals in the same dataset.

Data hygiene, storage, and audits

  • Normalization: Store dates as ISO 8601 (YYYY-MM-DD) and parse numeric fields from strings.
  • Idempotency: Key by the eTLD+1 (registrable domain) to avoid duplicates across www and subdomains.
  • Auditability: Log request/response IDs and the exact fields you used for decisions to help with approvals or customer support later.
  • Latency: Cache hits should serve immediately; misses can run through your async job and update records once ready.

Cost and signup notes

Starter is $39.99/mo with a 7-day trial, and failed or unreachable calls are not billed. You can register and start testing the API in minutes: Register. Visit the homepage for an overview: klazify.com.

FAQ

What happens if the API can’t retrieve registration data for a domain?
Some fields can be missing for very new or masked registrations. Implement null checks and fallback policies (e.g., flag for review and retry later). Failed or unreachable calls are not billed.

How often should I refresh domain age and expiration?
Age changes predictably, while expiration becomes relevant as it approaches. Cache results and recheck near critical operations or when expiration_days_left falls below your threshold.

Can I combine domain age with content categories for brand safety?
Yes. Use the categorization response’s IAB-mapped categories together with domain_age_days_ago to enforce stricter rules for new domains in sensitive categories.

Do I need to pass a domain or a full URL?
Send the URL in the JSON body as {"url":"https://example.com"}. The service will normalize as needed.

How do I handle throughput at scale?
Queue domains, run controlled concurrency with retries and backoff, and cache per registrable domain to minimize duplicate lookups. Consult the Documentation for integration patterns.

Ready to use Klazify?

Start classifying websites, enriching company data, and exploring web intelligence.

Get Started Free