How to find source URL

Asked

Viewed 2,411 times

3

I need a function that shows me the visitor’s origin url of my page. I have tried $_SERVER['HTTP_REFERER'], but it only seems to work when the source comes from a clicked link.

Currently I work with an affiliate system, which sends customers to my site through links created by the system itself (Before actually being directed to my website, the client goes through the affiliate program server, in order to register this client and who was the affiliate that indicated. Because in the case of a sale made, the affiliate system pays the commissions due).

I’m taking my platform out of this affiliate system, but as there are already many affiliate links posted on the internet, I would like to take advantage of these links to not lose sales.

An example of an affiliate system link is http://edzz.la/LQPZ4?a=656180

As I will no longer use this system, I would like my page to acknowledge that the visitor is from link/url. So that I can know who is the affiliate who is indicating this visitor.

  • 1

    I don’t know if it suits you, but if your intention is just to keep the Authority of your link that already has a good placement by Google for example, you can make a "301 redirect" to the new link. Google Anaytics tb indicates where your traffic is coming from in general. Some tools like Alexa tb record these Backlinks

2 answers

2

Browsers only fill in the information of referrer if the user has clicked on a link.

An HTTP request by itself is an extremely simple message with few details. The only field that could automatically and natively identify an origin is the referrer. In the absence of such information, your partners should use one of the following ways to pass on information:

  • Query String: your partners may include something at the end of the link, such as: http://www.foo.bar/blablabla/?origin=partner

  • Body of the request: if access to your website is via POST (improbable), they may include a field in the body of the request.

If it’s not possible for your partners to pass on that data, then I’m sorry, but there’s nothing you can do.

  • Sorry @Renan, I edited the question to be better understood, I was not clear in the original question. Page visitor coming from another server, is an affiliate system that I don’t have access to.

  • @Brunooliveira edited the answer accordingly.

0

The use of the cookie as a reference page repository is much better in most cases, as cookies will keep the referrer until the browser is closed (and will keep it even if the browser tab is closed), so if the user leaves the page open, say before the weekends, and returned after a few days, your session will probably expire, but cookies will still be there.

Place this code at the beginning of a page (before any html output, as cookies will be set correctly only before any echo / printing):

 if(!isset($_COOKIE['origin_ref']))
 {
  setcookie('origin_ref', $_SERVER['HTTP_REFERER']);
 }  

Then you can access it later:

$var = $_COOKIE['origin_ref'];

And in addition, add an Escaping for $_SERVER['HTTP_REFERER'] to be a common attack vector on the web, when using the cookie, you may also want to use Escaping $_COOKIE['origin_ref'] on each request.

  • O uso do Cookie como um repositório de página de referência é muito melhor... But a lot of people nowadays don’t keep cookies. That’s why many sites nowadays put that little bar at the bottom saying "by browsing here, you agree to enable cookies in your browser..."

  • Hi @Anderson Sorry, I guess I wasn’t clear. The affiliate system is on another server, it’s another service. A service that I will no longer use, but as there are already some affiliate links posted on the Internet, I would like to take advantage of these links to not lose sales. Thank you for the reply.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.