Skip to content
RandomFox logo

How to use the RandomFox API in PHP

Random pictures of foxes. A free animals API by randomfox.ca. This guide calls it from PHP with code we've run against the live endpoint.

Online · 1546 msEndpoint tested Oct 24, 2026

1. What you need

PHP 7.4+ with the cURL extension (enabled by default on most hosts).

No API key or sign-up. Endpoint: https://randomfox.ca/floof/

2. Make the request

PHP
<?php
$ch = curl_init("https://randomfox.ca/floof/");
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);
print_r($data);

3. The response

Trimmed from the live response on Oct 24, 2026.

JSON
{
  "image": "https://randomfox.ca/images/77.jpg",
  "link": "https://randomfox.ca/?i=77"
}

4. Before you ship

  • Set a timeout and handle non-200 responses: free APIs can rate-limit or go down.
  • Cache responses where you can, instead of calling the API on every page view.
  • Read the official documentation ↗ for rate limits and terms of use.

FAQ

Does the RandomFox API need an API key in PHP?

No. The RandomFox API works without an API key, so the PHP example runs as-is.

Can I call the RandomFox API from the browser?

Yes. It sends CORS headers, so front-end JavaScript can call it directly.

What does the RandomFox API return?

JSON. The example response on this page is trimmed from a real response our health check received on Oct 24, 2026.

Same API in: Python · JavaScript · Node.js · Java · Go · Ruby · C#
RandomFox API: ratings & reviews · RandomFox API alternatives · more free APIs for PHP