-1

I am trying to grab #access_token from a URL, it doesn't print anything

My url is like the following test.php#access_token=2f6b037435a6fc614ff5cab8a188dc70c4953f78%27

My PHP code:

echo $_GET['#access_token']

I tried the following as well

$url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$url=parse_url($url);
echo $url["fragment"]; //This variable contains the fragment
user580950
  • 3,558
  • 12
  • 49
  • 94
  • That's not what get parameters looks like... They'd be more like `test.php?access_token=2f6b037435a6fc614ff5cab8a188dc70c4953f78%27`. Notice the `?` instead of `#` – JustCarty Apr 30 '18 at 14:44
  • It needs to be a question mark not a `#` -- IE `test.php?access_token=2f6b037435a6fc614ff5cab8a188dc70c4953f78%27` --- Next, remove the `#` from the `_GET` -- IE `$_GET['access_token']` – Zak Apr 30 '18 at 14:44
  • there is no question mark after.php its #, its a webservice that returns that url – user580950 Apr 30 '18 at 14:45
  • 1
    Possible duplicate: https://stackoverflow.com/q/2317508/3578036 – JustCarty Apr 30 '18 at 14:46
  • 2
    Possible duplicate of [Get fragment (value after hash '#') from a URL in php](https://stackoverflow.com/questions/2317508/get-fragment-value-after-hash-from-a-url-in-php) – JustCarty Apr 30 '18 at 14:48
  • ^ a.k.a it can't be done - the URL fragment is never sent to the server – CD001 Apr 30 '18 at 14:50
  • *"its a webservice that returns that url"* ... if you're connecting to a web service, then that URL isn't a header response surely? – CD001 Apr 30 '18 at 14:54
  • What exactly was wrong with your `parse_url()` attempt? If you actually are getting (somehow) a URL that contains a hash-delimited fragment, then using `parse_url()` should be able to grab that fragment just fine. – Patrick Q Apr 30 '18 at 14:55

1 Answers1

0

I fixed the issue using Javascript, so grab the # from the URL, append that to the PHP page, redirect

   <script language="javascript">

    var strURL=(window.location.hash.substr(1));
     window.location.href = 'test-new.php?access_token ='
                           + strURL;
    </script>
user580950
  • 3,558
  • 12
  • 49
  • 94