Return the previous page after logging into facebook oauth

Asked

Viewed 293 times

1

Use the standard Facebook login system, it asks to enter App ID the App Secret and the URL that will return after requesting the login to the user, my question is, how to return the url where the login was requested. on several pages will be the Login button, so I would like you to return the source page. How do I?

  • It opens a new window to authenticate, does not open?

  • It actually opens in the same window. asks for authentication and login permission and then returns the login page meusite.com.br/login/

1 answer

1

If you are generating the login link via php just change it dynamically.

For example, on the news page:

$helper = new FacebookRedirectLoginHelper('http://seusite/noticia.php');
$loginUrl = $helper->getLoginUrl();
...

and in itself to receive/verify the user back is:

if ( !empty($_GET['code']) ){
...
$helper = new FacebookRedirectLoginHelper('http://seusite/noticia.php');
try {
  $session = $helper->getSessionFromRedirect();
} catch
...

* when facebook returns from login it brings this GET variable

Note: Actually this second piece of code I put should come before the first. If you have $_GET['code'] ( and/or a session variable that you will use to save the login token) log in, if not, it generates the login link (the link you will have on the button)

  • And when the user is in another page like "noticias2.php" and when logging in, he doesn’t want to go back to noticia.php but stay in the news2.php

Browser other questions tagged

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