1

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?

Gijo Varghese
  • 11,264
  • 22
  • 73
  • 122

1 Answers1

1

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
    }
}
Jay Bhatt
  • 5,601
  • 5
  • 40
  • 62
  • Thanks. One doubt. When share page B, its title, description, image etc will be fetched by facebook. If i use the above code, will facebook shows title of page A or page B??? – Gijo Varghese Apr 14 '14 at 16:50
  • @user3392772 This variable will only return the URL of the last page. If you have passed title as a variable in URL you will be able to access it. Otherwise not. – Jay Bhatt Apr 14 '14 at 17:24
  • How to pass title as variable in url? Sorry I didn't get what you mean. – Gijo Varghese Apr 14 '14 at 23:38
  • @user3392772 I.e. xxx.com?title=abc If you have title variable like in this example you can then get it using the prase_url() method. – Jay Bhatt Apr 15 '14 at 04:39