I have a try catch setup so that if the variables fail from the client or are not included they are populated to a default.

The request comes in like;

mysite.com/getroute.php?lat=123&lng=123&pref1=abc

I want to get the variables and put them into the variables at the top of my code below, but like i say there needs to be the default backup.

Here is my code;

//HTTP Request Variables
$URL_LATITUDE = null;
$URL_LONGITUDE = null;
$URL_PREFERENCE_1 = null;
$URL_PREFERENCE_2 = null;
$URL_PREFERENCE_3 = null;
$URL_USER_TIME = null;


try{
    parseHTTPRequest($URL_LATITUDE,$URL_LONGITUDE,$URL_PREFERENCE_1,$URL_PREFERENCE_2,$URL_PREFERENCE_3,$URL_USER_TIME);
} catch (Exception $ex) {
    automateHTTPRequest($URL_LATITUDE,$URL_LONGITUDE,$URL_PREFERENCE_1,$URL_PREFERENCE_2,$URL_PREFERENCE_3,$URL_USER_TIME);
}


function parseHTTPRequest(&$latitude, &$longitude, &$preference1, &$preference2, &$preference3, &$userTime) {
line20    $latitude =  htmlspecialchars($_GET["lat"]);
          $longitude =  htmlspecialchars($_GET["lng"]);
          $preference1 =  htmlspecialchars($_GET["pref1"]);
          $preference2 =  htmlspecialchars($_GET["pref2"]);
          $preference3 =  htmlspecialchars($_GET["pref3"]);
          $userTime =  htmlspecialchars($_GET["time"]); 
}


function automateHTTPRequest(&$latitude, &$longitude, &$preference1, &$preference2, &$preference3, &$userTime){
    $latitude =  "53.997945";
    $longitude =  "-6.4059567";
    $preference1 =  "Food";
    $preference2 =  "History";
    $preference3 = "Entertainment";
    $userTime =  240;
}

My errors;

Post image

Thanks



Source link

Write A Comment