How can I know which website the member has visited previously? - php

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).

Related

Link Referer Origin in PHP

I am trying the following. I have a facebook ad that has redirect link. This link leads to lets say xyz.com. I have have access to xyz.com.
I like to find out from where the user came from to xyz.com.
Basically, I am trying to avoid to let people copy the link from the facebook ad and put on their personal sites. Is that even possible to detect whether through Javascript or PHP if possible.
In PHP, there is the global variable $_SERVER['HTTP_REFERER'] available, but it contains a value provided by the client (the browser when interacting with humans) and cannot be relied on to be consistently set. If there is a redirect in between, possibly you see only the server where the redirect is coming from. JavaScript has the history object, but does not allow you to see its contents for privacy reasons.
If you do not need 100% reliability, I would propose to log the data in $_SERVER['HTTP_REFERER'] for a few days and then have an eye on the records, thus allowing you to spot how the traffic origin is distributed.
Depending on your server's settings, the referer may also be contained in the access log. For Apache, see the documentation here.

HTTP_REFERER blank, need alternative

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.

PHP or Javascript to read clickbank hoplink cookie?

I need to write a PHP or javascript that can read the clickbank cookie that's set when a user has clicked on one of my affiliate's hoplinks prior to reaching any of my sales pages.
How can one do this?
Here's my example:
I have a main salespage that I direct my referred users to (users who already know me and were not referred by an affiliate). It does not use ClickBank as a payment gateway.
I also have a salespage specifically for clickbank referrals. It uses ClickBank to clear transactions.
I would like to add script to MY salespage that will check to see if the user has an active cookie that denotes they've been referred to my product page by a hoplink. If so, I want to redirect them to the clickbank sales page for my product.
Any help much appreciated.
I know how the clickbank works and he tried to explain something different.
When affiliates sending visitors to his sale page, it adds the affiliate id at the end (fx mysite.com/?id=nick)
People can also come to his sale page directly(like mysite.com) simply typing his url. So he wants to check if the visitor come directly or with an affilate link.
So you have to answer first :
-Are you saving cookies at visitor browser(if not, you don't have to worry about your problem)?
-If not, then #Robert answer is going to help you...
You can't read cookies for a domain that isn't yours. So if ClickBank sets cookies for clickbank.com then you can't access them from yourdomain.com.
If you share part of a domain then you can. Eg. clickbank.example.com and yoursite.example.com the cookies could be set to example.com and be read by both. However clickbank would have to make this change so I think you're probably out of luck.
#Balir McMillan summed it up pretty well, cookies are locked to the domain that set it, that includes sub domains etc.
I am not fully shore how ClickBank works but it seems to me that you want to check to make sure that the referral was from a clickbank hop.
What you can do in PHP is check the $_SERVER['HTTP_REFERER'] to check the referrer, but I will tell you this can be faked and should be used with caution
Or you could get the hop variable directly from the URL and redirect to your affiliate sales page.
<?php
if(isset($_GET['hop'])) {
$cbid = htmlentities($_GET['hop']);
header('location: affiliatesalespage.php?a='.$cbid);
}
?>

how to track from where visitor come to my site php

I want to track the site URL from where user reached my site.
From where he came i.el, Google, GMail, Facebook, etc.
I tried $_SERVER['HTTP_REFERER'] but it does not contain anything when user click on my site link from any external site but resides the value when I visit among my site pages and this is also not trusted.
So, What I can do from here?
Is there any other way to track the external URL through PHP?
Any idea?
EDIT: Now HTTP_REFERER is able to get the url from most of sites but not able to get the url if user came through Gmail and AOL. What could be the causes?
HTTP_REFERER is the only way to get any information about previous site.
And that is also up to the broser if it supplies that information, most do as default.
Its a header that is set by the browser in the request to your server, if it is not present, then you will never know where the user came from.
If the browser is sending and you still to not get anything on the server check if you have any code that interferes with the $_SERVER variable.
Try this URL, its a google search result that goes to a page that just dumps the HTTP_REFERER.
As the pages indicates, if the box lists (none), then your browser is not sending HTTP_REFERER but if you get a result then the problem is in sour server.
http://www.google.com/url?sa=t&source=web&cd=1&sqi=2&ved=0CBIQFjAA&url=http%3A%2F%2Fkarmak.org%2F2004%2Freftest%2Ftest&rct=j&q=http_referer%20test&ei=cNQ2TdGYGsmUOp_ExPoD&usg=AFQjCNFVSmYmQBUcL2l3_ZpmZzVWZztjWg&cad=rja
You can compare it to when you load the page withour google to redirect you:
http://karmak.org/2004/reftest/test
Here is their own start page with link:
http://karmak.org/2004/reftest/
Have you tried it in a variety of browsers? It's down to the browser (As far as I'm aware) to set HTTP_REFERER and sometimes privacy settings can prevent this.
Visitors coming from google can be tracked using google analytics, it gives you the search query terms used before.
This solution also track a lot of other things from your visitors. I undertand it's not PHP based, but it's the only other kind of solution I know if HTTP_REFERRER is not enough to you, and as you quoted google...

php how to know that a click came from google

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

Categories