Oauth not working for the first authorization


@abraham I’m using your PHP API for Oauth connection. Everything works fine except that I have to authorize app twice to get into the home page of the site.
The authorization is not working for the first sign in. It redirects to my index page where I have to sign in. After that, It sends to the home page and works perfectly.I don’t know why I’m not getting authorized every first time I sign in. Can you please help me out where I went wrong.
Note: I am using Authorize URL. I have set the callback URL to callback.php. The problem is in Localhost.