Is it possible (and if yes, how) to get a referer, when a user clicks on a link in an e-mail? I can't use <form> tags in my e-mail, only pure links.
I want to display a special message, if a user visits my site when coming from my newsletter. I noticed however, that no referer ist provided when clicking on a link in (lets say outlook).
echo "Refererer " . ($_SERVER["HTTP_REFERER"] ? $_SERVER["HTTP_REFERER"] : "Not provided");
When coming from another site, the referer works. I assume that there is no referer then? Is there a way to tell "yes, this user comes from the newsletter-link"?
One workaround I was thinking about is using get-params.
Visit now
Without testing it, it should work, when I explicitly look for that get-param. This however is a way I don't want to go, since I'd like to have a clean url
mysite.com/
Any other ideas? Is it even doable with other approaches?
The easiest way to achieve this is to use a custom referrer parameter, since many email clients (gmail being one) explicitly removes any referer information to prevent sites from tracking that you clicked the link from an email.
If you look at any newsletter you've received via email, you will see that this is the way it is usually done.
What you could do (if you haven't already done so) is to extract the functionality to get the "referer" into a common method that you can call, which will search through any available referrer information and pick the correct one.
Related
I am kind of new to PHP and I am just wondering if there is a way to REDIRECT a URL based on the type of client that the call has come from? Like if a user is clicking a link in a email client as opposed to a HTTP request.
Is there a difference? Can it be done?
So for example:
IF "http://somesite.com/somesubpage.php"
do THIS
ELSE if "EMAIL CLIENT"
do SOMETHING ELSE
Hope someone can answer this. It could be in PHP or in htaccess.
If a user clicks on a link in an e-mail, and the link opens in a web browser, this is still considered an HTTP request.
If you want to track clicks on links within an e-mail, one common solution is to add a query string to the link. For example, your homepage might be:
http://www.example.com/index.php
But from your e-mail, you can link to:
http://www.example.com/index.php?source=email
and then track the source variable from within the index.php script.
Is there a way in which I can detect the URL that is calling in my php page, similar to say a GET or POST but would like to get the URL as I would like to restrict the page accessing it to a certain URL as this file is being called from another server.
Basically: www.MYURL.com calls the php file from say www.PHPURL.com if the URL is NOT www.MYURL.com then bounce them out etc.
Many Thanks
In response to the answers below I used the as mentioend and here is what I did:
$URL_REF = parse_url($_SERVER['HTTP_REFERER']);
$URL_REF_HOST = $URL_REF['host'];
Thanks #Philip Bevan,#Itai Sagi and #EvilP
well, you could use $_SERVER['HTTP_REFERER'] - but it can be cloaked/removed.
EDIT: as someone asked, the HTTP_REFERER is a header which is sent by the client, most browsers default behavior is to send it, but if you'd like, you can disable it or even send a different referer header so people will think you come from some place else.
the bottom line: if it isn't THAT critical for you, you can use it, but don't EVER, EVER give people extra privileges based on their referer alone.
$_SERVER["HTTP_REFERER"]
is what you are looking for.
I have a simple signup form that needs to track number of hits from one specific external referer. This is a simple task with PHP's:
$_SERVER['HTTP_REFERER']
however, it is blank. After doing some research i tried to use some javascript:
document.referrer
Still blank. :(
I really dont need anything elaborate, but am trying to NOT use awstats.
Is there any other way to get the referer (hacks accepted)?? Or am I stuck with the stats???
-thanks
In short: If the user don't want it, you will never know, where he comes from. However, a more "reliable" solution may be to add the referrer to the link from the origin site to yours. Something like
Visit example.com
This requires, that external sites cannot just link to your site, but always needs to add their personal id. If this is not possible there is not much you can do.
At all its possible, that someone may change this id too.
The referer is possibly sent in the HTTP request's header.
It is possible that the browser will not even send it, or some kind of proxy, firewall or security suite strips it out or even changes it. You cannot rely on it.
There is only one thing you can do: if it is empty, consider that you don't know the referer.
My adsense ad have a dedicated land page.
I want to show the content only to those who came through that ad.
The page is coded with PHP so I'm using $_SERVER['HTTP_REFERER'].
Two questions here:
Is there a better alternative to $_SERVER['HTTP_REFERER'] ?
To what strings/domains should I compare the referrer's domain (I'll handle extracting it)? I mean, I'm guessing that google has more than one domain they're using for the ads, or not? There's doubleclick.com.... any other domain? How can I check it, besides try/fail?
$_SERVER['HTTP_REFERER'] is the canonical way to determine where a click came from generally. There are more reliable (and complicated) methods for clicks within a site you fully control, but that's not much help for clicks from Google. Yes, it can be spoofed, and yes, it can be null, but as long as you're not targeting nuclear weapons based on that data, and you can handle null values gracefully, it should be good enough.
As for domains, you have to consider the international google domains, as well as all the google*.com domains.
I suggest adding a parameter on the link you give to Google. i.e. instead of yoursite.com/landing, do yoursite.com/landing?campaign=12.
If you are concerned that curious users will play with this parameter, the fix is simple-- redirect via a server 301 redirect when they hit that URL.
That is, if I request yoursite.com/landing?campaign=12, your server--before serving a page-- should log my visit to campaign 12 and redirect me to the plain url yoursite.com/landing. This has the added advantage that reloads won't increment your campaign hit count.
Yes, users could still mess with the original link if they are clever or curious enough to look at it before they click on it, but I think this is going to be far more effective than sniffing the referer.
Rather than trying to work out on your own how to measure your page views, you can consider using an existing system for that, like Google Analytics
So, I can use getenv('HTTP_REFERER') to get an URL which the member has visited previously, but it works only if it's the same website. I want this:
for example. the member firstly visits google.com then goes to my website. I want to show him, that previously he visited a google.com website. How can I do it if it's possible?
$_SERVER['HTTP_REFERER'] works fine for either case, as long as they followed a link from google.com to get to your site. Example: http://mrozekma.com/referer.php
You can only use the HTTP_REFERER header, and capture it the moment the visitor comes to your site. It might not be set, it might be false. There is no other way (and rightly so, I value my privacy). If you need to 'remember' the data store it in a session.
The simple answer is this is not possible. You can get the direct referrer if you're lucky, but nothing else (i.e. not the referrer of the referrer for example). Being able to retrieve the full history of a browser tab via JavaScript or post-back would be a major security issue.
Grabbing a browser's history is considered a breach of privacy, so any method that might exist to grab it would be considered a security bug in the browser.
Note that even the HTTP_REFERER header is considered to be a privacy issue by many people, so it's either disabled or filtered quite often (http://en.wikipedia.org/wiki/HTTP_referrer#Referrer_hiding).