3

I'm trying to code with the facebook API

here it says : http://developers.facebook.com/docs/authentication/javascript to get the access_token thing, but it's after a # and not a ?

so how can I get it ?

http://www.example.com/callback#access_token=...&expires_in=...

David 天宇 Wong
  • 3,724
  • 4
  • 35
  • 47
  • possible duplicate of [Can PHP read the hash portion of the URL?](http://stackoverflow.com/questions/940905/can-php-read-the-hash-portion-of-the-url) – Andy E Jul 20 '10 at 11:36
  • possible duplicate of [PHP & Hash / Fragment Portion of URL](http://stackoverflow.com/questions/1162008/php-hash-fragment-portion-of-url) – Gordon Jul 20 '10 at 11:37

2 Answers2

4

You won't be able to do it in PHP - you can only access it in javascript - the fragment/hash never reaches the server, it is processed by the browser

in Javascript, you can access the fragment using

window.location.hash
Alex C
  • 1,371
  • 2
  • 13
  • 16
  • still can't understand how to use it – David 天宇 Wong Jul 20 '10 at 11:50
  • try using alert(window.location.hash); - it should show you the hash. You then need to store this in a cookie to be able to access it from PHP (you'll have to reload the page for it to become available in PHP). – Alex C Jul 20 '10 at 12:06
  • rather than storing it in a cookie, why not use Ajax to send it to the server? – TRiG Apr 26 '11 at 10:28
2

The fragment identifier is only used client side. The browser doesn't send it to the server, so you can't access it with PHP.

To quote the page you link to:

Your JavaScript library can read the token from the URL and store it in a cookie for future use.

You have to use JS to read it before it can be sent to the server.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335