Reputation: 3741
I would like to track the link that a user followed to reach my website just like google analytic does?
Upvotes: 1
Views: 241
Reputation: 26081
if (isset($_SERVER['HTTP_REFERER'])) {
if (preg_match('/^https?\:\/\/(www\.)?\mywebsite\.(com|org|net)$/im', $_SERVER['HTTP_REFERER'])) {
// from your website //
} else {
// from other website //
}
} else {
// direct typing in browser //
}
Above regular expression match only
http://website.com
https://website.com
https://www.website.com
http://www.website.com
Write your own Regex. Hope this helps you. Thank you.
Upvotes: 5
Reputation: 9448
You can check the $_SERVER['HTTP_REFERER'] value, it will contain the URL the user clicked in order to reach your page.
Upvotes: 2
Reputation: 1219
You could use the 'HTTP_REFERER' attribute of the $_SERVER array but they're not 100% reliable
as John Conde said
Upvotes: 0
Reputation: 219814
Unless you have a relationship with the other website and they allow you to add tracking detail to the link, you cannot reliably get this information. You can get referrer information from the HTTP request headers but they are not completely reliable.
Upvotes: 5