---
title: "Context Types"
manual: "Multi-channel Contexts"
version: "main"
source: "ContextTypes/Index.rst"
rendered: "2026-10-07T11:40:39+00:00"
---

# Context Types {#context-types}

The extension provides several built-in context types. Each type evaluates
different conditions to determine if a context is active.

**On this page**

-   [IP Address Context](#ip-address-context)
-   [Domain Context](#domain-context)
-   [Query Parameter Context](#query-parameter-context)
-   [HTTP Header Context](#http-header-context)
-   [Session Context](#session-context)
-   [Combination Context](#combination-context)
-   [Related Extensions](#related-extensions)

## IP Address Context {#context-type-ip}

Match visitors by their IP address or IP range. Supports both IPv4 and IPv6.

### Configuration {#configuration}

-   **IP/Range**

    -   *type:* string
    -   *required:* true

    Single IP address, CIDR notation, range, or comma-separated list.

Examples:

-   Single IP: `192.168.1.100`
-   CIDR notation: `10.0.0.0/8`, `FE80::/16`
-   Range: `192.168.1.1-192.168.1.255`
-   Wildcards: `80.76.201.*`, `80.76.*.37`
-   Multiple: `192.168.1.0/24,10.0.0.0/8`

### Use Cases {#use-cases}

-   Internal network detection (show admin tools for office IPs)
-   Geographic content (by IP geolocation with `contexts_geolocation`)
-   Office vs. external visitor differentiation
-   Development/staging environment detection

## Domain Context {#context-type-domain}

Match based on the accessed domain name (HTTP_HOST).

### Configuration {#configuration-1}

-   **Domain**

    -   *type:* string
    -   *required:* true

    Domain name(s) to match. One domain per line.

**Matching Rules:**

-   Without leading dot: Exact match only

    -   `www.example.org` will **not** match `example.org`
-   With leading dot: Matches all subdomains

    -   `.example.org` matches `www.example.org`, `shop.example.org`, etc.

Examples:

-   Single: `www.example.com`
-   Multiple (one per line):

    ```
    example.com
    www.example.com
    ```
-   Subdomain wildcard: `.example.com`

### Use Cases {#use-cases-1}

-   Multi-domain setups (different content per domain)
-   Staging vs. production detection
-   Brand-specific content on shared installations
-   Language-specific domains

## Query Parameter Context {#context-type-getparam}

Match based on URL query parameters (GET parameters).

### Configuration {#configuration-2}

-   **Parameter Name**

    -   *type:* string
    -   *required:* true

    The GET parameter name to check.

-   **Expected Value**

    -   *type:* string
    -   *required:* false

    Value to match. Supports regular expressions. If empty, any non-empty
    value activates the context.

-   **Store in Session**

    -   *type:* boolean
    -   *default:* true

    When enabled, the context state is stored in the user session, persisting
    across page navigations even after the parameter is removed from the URL.

Examples:

-   `?debug=1` with parameter `debug` and value `1`
-   `?variant=a` for A/B testing
-   `?affID=partner` for affiliate tracking

### Use Cases {#use-cases-2}

-   A/B testing variants
-   Debug mode activation
-   Campaign and affiliate tracking
-   Feature flags via URL

## HTTP Header Context {#context-type-httpheader}

<!-- TODO: no Markdown rendering for "versionadded" -->

HTTP Header context for matching request headers.

Match based on HTTP request headers sent by the browser or proxy.

### Configuration {#configuration-3}

-   **Header Name**

    -   *type:* string
    -   *required:* true

    The HTTP header name to check (case-insensitive).

-   **Expected Value**

    -   *type:* string
    -   *required:* false

    Value(s) to match against the header. One value per line.
    Matching uses **case-insensitive substring** comparison: if any
    configured value appears anywhere in the actual header value,
    the context matches. If empty, any non-empty header value
    activates the context.

-   **Store in Session**

    -   *type:* boolean
    -   *default:* true

    Has no effect for this context type. The header is evaluated on every
    request, so the context is active only on requests that carry a matching
    header.

<!-- TODO: no Markdown rendering for "versionadded" -->

PSR-7 header support and case-insensitive substring matching.

#### Header Name Resolution {#header-name-resolution}

The extension supports both standard HTTP header names and
`$_SERVER` parameter keys:

-   **PSR-7 header names** (recommended): `User-Agent`,
    `Accept-Language`, `X-Forwarded-For`
-   **$\_SERVER keys** (legacy): `HTTP_USER_AGENT`,
    `HTTP_ACCEPT_LANGUAGE`

The lookup order is:

1.  PSR-7 `$request->getHeaderLine()` (standard header name)
1.  `$request->getServerParams()` (`$_SERVER` key format)

#### Value Matching {#value-matching}

Values are matched using **case-insensitive substring** comparison.
For example, with header `User-Agent` and configured values:

```
Mobile
Android
iPhone

```

A User-Agent string like `Mozilla/5.0 (iPhone; CPU iPhone OS)`
matches because it contains `iPhone` (case-insensitive).

Examples:

-   `X-Forwarded-For` for proxy detection
-   `Accept-Language` for language preferences
-   `User-Agent` for browser/device detection
-   Custom headers from CDN or load balancer

### Use Cases {#use-cases-3}

-   CDN or proxy detection (`X-Forwarded-For`, `CF-Connecting-IP`)
-   Mobile device detection via `User-Agent`
-   Accept-Language based content
-   Custom application headers
-   Bot detection

## Session Context {#context-type-session}

Match based on frontend user session data.

### Configuration {#configuration-4}

-   **Session Key**

    -   *type:* string
    -   *required:* true

    Key in the session data to check.

-   **Expected Value**

    -   *type:* string
    -   *required:* false

    Value to match. If empty, checks if the key exists and is not NULL.

### Use Cases {#use-cases-4}

-   User state tracking
-   Shopping cart state (cart has items)
-   Login/authentication state
-   Multi-step form progress
-   User preference flags

## Combination Context {#context-type-combination}

Combine multiple contexts with logical operators for complex rules.

### Configuration {#configuration-5}

-   **Expression**

    -   *type:* string
    -   *required:* true

    Logical expression combining context aliases.

**Operators:**

-   `&&` \- logical AND (all must match)
-   `||` \- logical OR (any must match)
-   `!` \- negation (must NOT match)
-   `(...)` \- parentheses for grouping

Examples:

-   `mobile && !tablet` \- Mobile but not tablet
-   `internal || admin` \- Internal network or admin user
-   `(german || austrian) && !guest` \- German-speaking non-guest
-   `campaign_a && !already_converted` \- Campaign A visitors who haven't converted

### Use Cases {#use-cases-5}

-   Complex multi-condition business rules
-   Nested context hierarchies
-   Exclusion rules (show to A but not if B)
-   Compound targeting (A AND B OR C)

> [!TIP]
> Use descriptive context aliases to make combination expressions readable.
> For example: `premium_user && active_campaign && !opted_out`

## Related Extensions {#related-extensions}

Additional context types are available through companion extensions:

-   **contexts_geolocation**

    Location-based contexts using IP geolocation:

    -   Continent detection
    -   Country detection
    -   Area/region detection

-   **contexts_wurfl**

    Device-based contexts using WURFL database:

    -   Device type (phone, tablet, TV, desktop)
    -   Screen size detection
    -   Browser capabilities
