php - Losing session after a redirect to another domain then back -



php - Losing session after a redirect to another domain then back -

i creating login scheme utilize persons email address unique identifier in db. people can login using openid provider such google ect (also facebook), take email , store unique identifier in users table in sql db. (means dont have worry email verification, passwords ect , users dont have register).

this works, opening new window using link/javascript, php script directed google or whoever provider is. come in there details, google/ect automaticly redirect window login script along (if worked) user details (most importantly email).

now on response @ email, if in database, if not add together it, if so, using $_session, log user site.

i have working using openid mechanism (google, yahoo, ect). trying working facebook , having great difficulty. able log user fb, grab users email ect. seek log user site, not work. reason has seperate session(inc seperate sessionid) new window have opened (and script + redirection runs in), rest of site?

just wondering if has thought why happening.

this login script looks (thats runs in new window):

<?php $app_id = "your_app_id"; $app_secret = "your_app_secret"; $my_url = "your_url"; session_start(); $code = $_request["code"]; if(empty($code)) { $_session['state'] = md5(uniqid(rand(), true)); //csrf protection $dialog_url = "https://www.facebook.com/dialog/oauth?client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url) . "&scope=email&state=" . $_session['state']; echo("<script> top.location.href='" . $dialog_url . "'</script>"); } if($_request['state'] == $_session['state']) { $token_url = "https://graph.facebook.com/oauth/access_token?" . "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url) . "&client_secret=" . $app_secret . "&code=" . $code; $response = file_get_contents($token_url); $params = null; parse_str($response, $params); $graph_url = "https://graph.facebook.com/me?access_token=" . $params['access_token']; $user = json_decode(file_get_contents($graph_url)); echo("hello " . $user->name); // try_register_or_login($user->email); } else { echo("the state not match. may victim of csrf."); } ?>

source: https://developers.facebook.com/docs/authentication/

i have spent far many hours trying work out myself. help much appreciated.

i believe issue may have crossing domains or potentially how cookie set.

for crossing domains, take @ cross domain cookies

another possibility flags set cookie. had exact issue when set secure flag on cookie , tried access via non secure (http) page. also, if httponly flag set, cause problems javascript. can read both flags @ http://www.php.net/manual/en/function.setcookie.php

php facebook session login session-variables

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -