简体   繁体   中英

How to get parameter from the url?

I have to get value of access_token from a URL, like:

localhost/facebook/#access_token=xyz

$_GET['access_token'] doesn't work. How can I get the value of access_token ?

Use getAccessToken

$facebook->getAccessToken();

https://developers.facebook.com/docs/reference/php/facebook-getAccessToken/

$user = $facebook->getUser();
echo $facebook->getAccessToken();
if(!$user){
    $loginUrl = $facebook->getLoginUrl();
    echo '<a href="$loginUrl">Login with Facebook</a>';
}

Clicking login with take you to fb, you login/accept whatever, then it redirects you back to your page and you get your access token.

I believe the hash part of the URL isn't sent to PHP, so can't be accessed via PHP. Javascript can access it, and can then pass it onto PHP.

There is a guide here showing how.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM