anitg 0 Newbie Poster

I am trying to get access toke from FB through Developer App. But I am not able to json_decode the call back response.

If I use the token_url call from browser, it returns the access token. But from within the script it does work.

I searched online and foun that it could be that the Json encoded response must be containg some UTF -8 BOM. So I tried some functions that would strip the response from that. However, I still am not able to get that elusive access token as a variable by json decoding and getting an array.

My code

function remove_utf8_bom($data)
    $bom = pack('H*','EFBBBF');
    $data = preg_replace("/^$bom/", '', $data);
    return $data;
                    $token_url = ""
                        . "client_id=".$config['appId']."&redirect_uri=" . urlencode($config['callback_url'])
                        . "&client_secret=".$config['secret']."&code=" . $_GET['code'];
                    echo $token_url."<br>";                 
                    $ch = curl_init();
                    curl_setopt($ch, CURLOPT_URL, $token_url);
                    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
        //          curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
                    $data = curl_exec ($ch);
                    if(curl_exec($ch) === false) {
                        echo 'Curl error: ' . curl_error($ch);
                    } else 
                        echo 'Operation completed without any errors<br>';

//                  $data=file_get_contents($token_url);                    
    //              echo $data."<br>";
                    $data = remove_utf8_bom($data);
//                  echo "<br> DATA : <br>";
    //              var_dump($data);
                    $params = null;
                    print_r ($params)."<br>";
                    $_SESSION['token'] = $params['access_token'];

                    echo "SESSION TOKEN : ".$_SESSION['token']."<br>";

But still it returns NULL

I have been breaking my head and browsing all kinds of forums but could not get any solution.

Thanks in advance if you can put me out of my misery