# click — repo context

> Curated overview for code_search. Source: `bitbucket_server:AD/click` (Bitbucket, project AD). Legacy flat PHP (no framework). Default branch `master`.

## Purpose
The **AdMedia click-tracking / redirect server** — the endpoint that ad clicks hit. It receives an inbound click, records tracking / stats, runs fraud & bot checks, resolves the destination (offer / deeplink), and redirects the user to the advertiser landing page. This is the legacy, high-traffic "click hop" service, written as a large collection of small procedural PHP scripts served directly off the web root (each `*.php` is its own endpoint — there is no router/framework).

## Structure
- **Flat web root** — ~150 `*.php` scripts at the top level, each a callable endpoint. Naming is terse and versioned (`r.php` / `r1.php` / `r2.php`, `rdr.php` / `rdr2.php` / `rdr3.php` / `rdr4.php`, `cad.php` / `cad2.php` / `cad10.php` / `cad20.php`) — the numbered variants are historical revisions kept live.
- **Subdirs:** `includes/` (shared PHP helpers), `cl/`, `cpa/`, `edm/`, `list/`, `p/`, `pix/`, `wise/`, `d/`, `thanks/` (endpoint groupings); `js/`, `images/`, `font/`, `video/`, `Campaigns_Images/` (static assets — non-code, not useful to search).

## Key scripts (by area)
- **Click entry & redirect** — `c.php`, `c1.php`, `c2.php`, `dclick.php`, `r.php`/`r1.php`/`r2.php`, `rdr.php`/`rdr2.php`/`rdr3.php`/`rdr4.php`, `redirect.php`/`redirect1.php`/`redirect2.php`, `credirect.php`, `internal_redirect.php`, `direct_link.php`, `jump.php`, `hp_rdr.php`, `new_rdr.php`.
- **CAD (click-and-deeplink) resolution** — `cad.php` + variants (`cad2`, `cad10`, `cad20`, `native_cad`, `rtb_cad`, `sl_cad`, `deeplink_cad`), `deeplink.php`, `offer.php`, `offers.php`.
- **Tracking & stats** — `t.php`, `ctrack.php`, `adtrack.php`/`adtrack_1.php`, `ajtrack.php`, `clicktrack1.php`/`clicktrack2.php`, `impression.php`, and the `*_stats` / `*stats` family (`stats.php`, `cstats.php`, `dstats.php`, `ostats.php`, `lpc_stats.php`, `cap_stats.php`, `ref_stats.php`, `arb_stats.php`/`arb_stats2.php`, `yb_stats.php`, `r2_stats.php`, `lpstats.php`).
- **Fraud / bot / validation** — `fraud.php`, `bot_check.php`, `check.php`, `chk.php`, `chk_hash.php`/`chk_hash2.php`, `validate.php`, `validateUrl.php`, `testingIps.php`, `edmunds_blacklist_Ips.php`, `validclick-monitor-matcher.php`.
- **Helpers / infra** — `helper_functions.php`, `encrypt_helper.php`, `ipinteger.php`/`ipx.php`, `config.php`/`config_new.php`, `db.php`, `cache.php`/`cacheredirect.php`, `class.GACollectRequester.php` (Google Analytics Measurement Protocol), `Base2n.php` (base-N encoding), `platform.php`, `log.php`.
- **Health / monitoring** — `health_check_click.php`, `os_health.php`, `click-monitor.php`, `cad_monitor.php`, `click-read-write-test.php`.
- **Data feeds** — `datafeed.php`, `admedia_feed.php`, `drops.php`, `edrop.php`.

## Search notes
- Each endpoint is a standalone script; behaviour usually lives in one `*.php` file plus shared code under `includes/` and the `helper_functions.php` / `*_helper.php` files. When tracing "how a click flows", start at the entry scripts (`c.php`, `rdr*.php`, `cad*.php`) and follow into helpers + `db.php`.
- Many near-duplicate numbered variants exist — prefer the highest-numbered / non-`_backup` / non-`test` file as the current one; `*_backup.php`, `test*.php`, `*_test.php` and `rtest.php` are scratch/legacy.
- Static asset dirs (`images/`, `font/`, `video/`, `Campaigns_Images/`, `js/`) are not code — ignore for logic questions.

## Tech
Legacy procedural **PHP** (no framework), served per-file off the web root · **MySQL** (`db.php`) · caching (`cache.php`) · Google Analytics Measurement Protocol (`class.GACollectRequester.php`) · IP/encryption helpers. The AdMedia click/redirect hop feeding advertiser landing pages.
