How to find source Url

3

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

Currently working with an affiliate system, which sends clients to my site through links created by the system itself (Before actually being directed to my site, the customer goes through the affiliate program server, in order to register that customer and 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 since you already have many affiliate links posted on the internet, I'd like to take advantage of those links so you do not lose sales.

An example of an affiliate link is link

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

    
asked by anonymous 04.01.2018 / 16:14

2 answers

2

Browsers only populate referrer information 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 a source is referrer . In the absence of this information, your partners should use one of the following ways to pass information:

  • Query String: Your partners can include something at the end of the link, such as: >
  • Request body: If access to your site is via POST (think improbable), they can include a field in the request body. p>

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

    
04.01.2018 / 16:51
0

Using Cookie as a reference page repository is much better in most cases as cookies will hold the referrer until the browser is closed (and will keep it even if the browser tab is closed) if the user leaves the page open, say before the weekends, and returns after a few days, your session will probably be expired, but cookies will still be there.

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

 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 escaping by $ _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.

    
04.01.2018 / 16:40