Check which page accessed previously and if positive display something

Asked

Viewed 550 times

0

I need to make a check, that if the source is not coming from facebook with. cannot display a particular code.

Only people who come from facebook with. you may see a certain code, if it comes from another link, you will see a different code.

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

2 answers

1

I’ll put it down here dois links that can help you resolve your question/question.

1st LINK (as I understand your question/doubt, this link is what should give you the most help.)

2nd LINK

I didn’t copy the code of both links because each author deserves the your credits !

  • show, I think the first link resolves, with the $_SERVER['HTTP_REFERER']

  • If you want you can put this answer right, to serve as reference for similar questions.

  • 1

    @thecreator You can put the code here and inform their source. If in the future any of these sites change address or go off the air your answer ends up being useless because it contains only links and no content.

1


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

$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 the 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.

  • but this == won’t return something like http:// and give a false? wouldn’t have to be something like 'contain' facebook

  • @Dorathoto I updated the answer.

Browser other questions tagged

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