<?php
require 'twitteroauth/autoload.php';
require 'twitter-config.php';

use Abraham\TwitterOAuth\TwitterOAuth;

/**
 * Handles the AJAX POST requests
 */
  if (isset($_POST["action"]) && !empty($_POST["action"]) && isset($_POST["params"]) && !empty($_POST["params"])) {
    $action = $_POST["action"];
    $params = $_POST["params"];

    perform_request($action, $params);
  }


/**
 * Performs a request using the TwitterOAuth library
 * @see https://twitteroauth.com/
 * @param $action - what to retrieve from the Twitter REST API (e.g. trends/place )
 * @param $params - parameters to be passed during the Twitter API request
 */
function perform_request($action, $params){

  $connection = new TwitterOAuth(TwitterConfig::$consumerKey, TwitterConfig::$consumerSecret, TwitterConfig::$accessToken, TwitterConfig::$accessTokenSecret);
  $response = $connection->get($action, $params);

  echo json_encode($response);
}
<?php

/**
* Handles the AJAX POST requests
*/
  if (isset($_POST["action"]) && !empty($_POST["action"]) && isset($_POST["query"]) && !empty($_POST["query"]) && isset($_POST["appID"]) && !empty($_POST["appID"])) {
      $action = $_POST["action"];
      $query = $_POST["query"];
      $appID = $_POST["appID"];
      perform_request($action, $query, $appID);
  }


/**
 * Performs a request using the Yahoo API
 * @param $action - what to retrieve
 * @param $query - passed request query
 * @param $appID - Yahoo App ID
 */
function perform_request($action, $query, $appID){

    $request =  'http://where.yahooapis.com/v1/'.$action.'.q('.$query.')?appid='.$appID.'&format=json';
    $session = curl_init($request);
    curl_setopt($session, CURLOPT_HEADER, false);
    curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($session);
    curl_close($session);

    echo $response;
}