I’ve written some simple code in PHP which save slug from my 301 redirect URL so I know how many visitors come from that advertisement. However, it’s not working when user comes from 301/307.
Example: if user comes from 301 redirect url example.com/example
to redirect url to example.com/example1
now in example1 page not showing referral from this link example.com/example
:
$url = example.com/example; $data = "$url"; $j=0; foreach (count_chars($data, 1) as $i => $val) { $j=$j+$val; } $result = substr(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '',$j); echo $result;
Hope this makes sense.
Dont rely on $_SERVER[‘HTTP_REFERER’] it is purely optional for a browser to send it, and some security software blocks it in requests. Read more here
Thats a normal problem of Referer Tracking. You should use other methodes to track ads.
The most used option are Get Parameters (offer.php?ref=sitexy)