Repository navigation
Visitor and request context
The released facade exposes two reads. Both use the active request and return immutable snapshots without making network requests.
use Moztopia\Cloudflare\Facades\Cloudflare;
$visitor = Cloudflare::visitor();
$context = Cloudflare::requestContext();All properties below are nullable strings:
-
countryCode: a country code validated against the Symfony country-code dataset, fromCF-IPCountry. -
continentCode: one of AF, AN, AS, EU, NA, OC or SA fromCF-IPContinent. -
region: estimated region/state name fromCF-Region. -
regionCode: region code fromCF-Region-Code. -
city: estimated city fromCF-IPCity. -
timezone: a validated PHP timezone identifier fromCF-Timezone. -
countryMarker: Cloudflare'sXXunknown marker orT1Tor marker.
When a country marker is present, countryCode remains null. A marker is not an ordinary country.
Location describes Cloudflare's estimate for the visitor IP. It is not precise physical location, verified residence, language preference, delivery eligibility or authorization.
Source b52f0eeb485f67119f209094ce546096427358bf implements these additions toward 0.10.0 Cirrus; they are absent from tagged 0.9.1:
-
latitude: nullable float parsed fromCF-IPLatitude, bounded from −90 through 90 inclusive. -
longitude: nullable float parsed fromCF-IPLongitude, bounded from −180 through 180 inclusive. -
metroCode: nullable numeric identifier string fromCF-Metro-Code, accepting 1–16 ASCII digits and preserving leading zeroes. The length bound is package validation, not a claimed Cloudflare wire limit.
Coordinates accept bounded signed decimal strings and return finite floats. Exponent notation, non-finite values, duplicate headers, invalid UTF-8/control characters and values outside the coordinate bounds are rejected. Each field is independent: an invalid latitude does not discard a valid longitude. Existing constructor arguments retain their positions; the three nullable properties are appended. Manually constructed snapshots remain application-supplied data.
Zero is valid. Avoid a truthiness check in Blade:
@if ($visitor->latitude !== null && $visitor->longitude !== null)
<p>Estimated coordinates: {{ $visitor->latitude }}, {{ $visitor->longitude }}</p>
@else
<p>Location coordinates unavailable</p>
@endifRich metadata depends on the zone’s enabled Add visitor location headers Managed Transform and a verified trusted ingress. Country availability alone does not prove the richer fields are supplied. Cloudflare describes latitude, longitude and metro wire fields as strings; the coordinate float results are a deliberate SDK contract. These remain approximate IP-derived metadata, with no reverse geocoding, account secret, locale change or hidden network call.
Postal-code support is excluded from the initial 1.x requirements and has no promised release target. Missing geographic values remain unknown without a GeoLookup dependency.
-
trusted: a boolean indicating whether the configured immediate peer was accepted; false by default. -
clientIp: a nullable valid IPv4/IPv6 string fromCF-Connecting-IP. -
rayId: a nullable Ray identifier fromCF-Ray: 16–32 hexadecimal characters followed by a hyphen and a three-letter data-centre suffix. -
scheme: nullablehttporhttpsfromCF-VisitorJSON.
The Ray suffix identifies Cloudflare infrastructure involved in the request; it is not the visitor's region. Worker subrequests and Pseudo IPv4 can affect client-IP semantics, so consult Cloudflare's documentation for your deployment.
Absent, untrusted or malformed values return null. Parsing rejects multiple values where one is expected, invalid UTF-8, control characters and malformed structured fields. Location header values are limited to 256 bytes and must still be escaped when rendered.
An accepted peer may supply only some fields. Always check the particular field needed by the application instead of treating trusted as a complete-data flag.
The service resolves the current request on every call. A previously returned object remains a snapshot of the request that produced it; it is not updated in place. Resolving the service in a warmed worker does not intentionally retain a previous visitor.
Use the returned snapshot within the current application operation. Do not store a visitor snapshot in a global singleton for reuse across visitors.
Maintained by-dolly.
Released API reference: 0.9.0 — Cirrus. Future capabilities are marked on the Roadmap.
Repository · Project website · Apache-2.0
Maintained by-dolly.

Moztopia Cloudflare
- Home
- Getting started
- Trusted ingress
- Visitor and request context
- Diagnostics and doctor
- Blade and testing
- Example website
- Development and verification
- Branding
- SDK contract
- Roadmap
- Unreleased core work
- Release gates
- Optional credential-free additions
- V2 discovery
- Planning decisions
- Ecosystem review
- Ecosystem inventory
Maintained by-dolly.