Gijo Varghese
Gijo Varghese

Reputation: 11780

Redirect to a page if shared from Facebook

I don't know whether is this possible. I am creating a site in PHP. Is it possible to detect the previous url is from facebook/twitter, and if yes redirect to an another page?

In detail I have page A and B. There is a share button in page B. On clicking that button it will post title, image, description etc of the page B to facebook. But clicking that in facebook it will redirect to page A.

Can anyone help me?

Upvotes: 1

Views: 220

Answers (1)

Jay Bhatt
Jay Bhatt

Reputation: 5651

If all your pages are on the same domain you can use sessions.

For external pages you can use $_SERVER['HTTP_REFERRER'].

I.e.

if ( $parts = parse_url( $_SERVER['HTTP_REFERRER'] ) ) {
   if($parts['host'] == "www.facebook.com"){
      //do something
    }
}

Upvotes: 1

Related Questions