Check which page was previously accessed and if it shows something

0

I need to make a verification that if the source is not coming from facebook.com you will not be able to show a certain code.

Only people coming from facebook.com will be able to see the particular code, if it comes from another link, you'll see another code.

  

I do not have PHP knowledge, only in C #, but I can understand it well   the structure ... (are similar)

    
asked by anonymous 06.02.2015 / 19:48

2 answers

1

You can check whether the referrer host is facebook.com. The parse_url function returns an array containing URL information. The host index of the array that is returned by the function will contain only the address host and nothing else.

$info = parse_url($_SERVER["HTTP_REFERER"]);

if(strpos($info['host'], 'facebook.com') !== false) {
    // veio do facebook!
} else {
    // não veio do facebook
}

The problem is that facebook uses HTTPS and the browser will send referrer only if your link is also HTTPS.

If your site does not have SSL certificate, another alternative is to use some parameter in the URL to identify the source of the access.

    
06.02.2015 / 20:06
1

I'm going to put down dois links down here that can help you solve your question / question.

1st LINK

2nd LINK

  

I did not copy the code from both links because each author deserves the   your credits!

    
06.02.2015 / 20:01