Is there a way that I can determine if someone has clicked the link in a email vs if they typed the url in their web browser rather than clicking the link?
When I look at the weblogs I want to determine how the page was accessed, would this be a case of a unique url in the email?
Unique links would be one option. Depending on your needs, a simple querystring such as ?source=email could suffice. Of course, if somebody were to type this into the address bar, then it looks as if it were accessed from the email.
$_SERVER['HTTP_REFERER'] If the user is coming via e-mail, you can detect it with referrer. If the user is coming from the browser (unless manipulated) the referer will be empty. http_referer
Related
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.
I want to determine the website from which the request to the particular website has been called. For Example..I have a website www.ex.com. Now this website link has been there on three websites www.a.com, www.b.com, and www.c.com. Suppose one user has clicked the link from www.a.com to go to www.ex.com. Now I want to determine that the request has come from the www.a.com and then the page in www.ex.com will be displayed accordingly. Similarly if the user has clicked the www.ex.com link from www.b.com then the page will be displayed accordingly.
So how can I determine this request source, means from which website www.ex.com has been called? It is good if you will explain this using code in PHP.
Thanks
Look here for HTTP_HOST and HTTP_REFERER.
Since both global variables are populated from HTTP headers, look also here for Host and Referer.
That's how you use them:
$host = $_SERVER['HTTP_HOST'];
$referer = $_SERVER['HTTP_REFERER'];
The 1st is the original host name (like 'www.a.com') referring to your page. The 2nd is the full URL (like https://www.a.com/some/path/to/some.html).
Then, based on some conditional logic, you may return to your users appropriate HTML.
There are two different websites.
Say from a.com, you click on ex.com
So, for the link in a.com, add some parameter:
Click Here
Now, your from parameter will be
1) a.com
2) b.com
3) c.com
If none of the above, then its clicked from ex.com itself.
You can also add some encryption for this link to add security.
You can use this
$_SERVER['HTTP_REFERER']
for referral url
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.
Lets say I have a URL, www.mysite.com/go that I want to redirect to www.anothersite.com/site.php?id=999
The trick is, I do not want anothersite.com to be able to see that the request came from mysite.com. It should look like the address www.anothersite.com/site.php?id=999 was typed into the addressbar manually by the user.
It is important to note, that this has nothing to do with Google Analytics, and there will never exist an anchor link to www.mysite.com/go anywhere. Instead, the user will manually input www.mysite.com/go in the address bar (which is easier to remembar than the long URL).
How is this achieved? The technology in question is PHP. I imagine that it can be achieved with the header() function, but google searches reveal that this only works with https, not http. Can I via PHP control what the client provides of referrel information when the redirect is performed? I guess that if I want it to look like the address was typed into the address bar, I would have to blank out the referrer information. Is it possible?
It's not possible by means of a HTTP Redirect. You don't have any control over the outgoing referrer header as the browser handles it entirely client-side.
Your only real option that you can directly control is to use HTTPS. Referrers with a value of a HTTPS page are not carried forward by browsers.
Example flow:
http://www.mysite.com/go (so any existing links don't have to change)
https://www.mysite.com/go
http://www.anothersite.com/site.php?id=999
is there a way for php to tell if an address is directly typed by user or coming from a click or any other method that in the end will result a php-generated page?
this question is purely out of curiosity so the urgency is very, very low. but thank you if you want to spare sometime to answer. :D
You could use $_SERVER['HTTP_REFERER']. It should be set to the page that referred the user to your page. If the user typed the address in, it will be empty.
However, beware, it is not reliable, and can be easily modified by the user. As the PHP doc says, you can't really trust it.
In general, you can't.
0) typed (or copy-pasted!) links - REFERER will be empty
1) links clicked on a webpage - REFERER will be set
2) links clicked in an email client (not web based like gmail) - REFERER will be empty
3) links loaded as a home page - REFERER will be empty
4) links loaded from bookmarks - REFERER will be empty
So using PHP $_SERVER['HTTP_REFERER'] variable you can only distinguish case 1 from all the other cases...
You can look at the http_referrer, for a webpage loaded by directly typing in address bar it should not have any referrer but the page that was loaded by some click will have a referrer.
Using http_referrer for this purpose is very unreliable. HTTP_REFERRER is empty when the user types the URL in some browsers. It is NULL in Chrome 19, it is NOT NULL in IE8.
$direct = (bool)$_SERVER['HTTP_REFERER'];