Search code examples
phpfacebookfacebook-php-sdk

Facebook 'redirect_uri' param for php sdk not redirecting to passed uri (redirects only return to homepage)


I'm having issues redirecting to a page on my site after login via facebook. I'm using the php graph sdk (version 3.1) and the redirect_uri is set in facebook's getLoginUrl method. For example, when an action on my site requires user authentication, I would like a user to authenticate with facebook and then be forwarded to the page they were trying to access. I can do this easily with a standard login page. After user authentication with facebook,the passed in redirect_uri value is ignored and I'm redirected to the homepage of my site with #= appended to the url. The redirect_uri values passed are under the same domain as my website url on my app's setting.


Solution

  • Figured it all out. The redirect_url is left blank and facebook returns to the action that called it. In this action I check to see if the session returned by facebook->getUser() (user is logged into facebook) is valid and then I forward the user to the page that required authentication--just like a regular login page.