2

I have a php file that takes JSON data coming from a url. I want some keys and values to be included in my local database and remaining keys and values to be uploaded in the database of OpenStreetMap (OSM).

I want to call the respective php file with the GET parameters from the main php file.

My script looks like this:

<?php

$url = "something";

$parts = file_get_contents($url);

$json = json_decode($parts);

//echo(sizeof($json));  

$private = array("people_count");

$to_osm = array("Rent","drinking_water","Shop","communication","Energy_source","waste_management","Internet_access","emigrants","number_storey","adboard");

foreach ($json as $object) {

    $get_url = "?id=";

    foreach ($object as $key => $value) {

        if ($key == "osmid") {
            $id = $value;
            $geom = "Polygon";
            $get_url.=$id."&geom=".$geom;
            //print_r($get_url);
        }

        elseif (in_array($key, $to_osm)) {
            $get_url.="&".$key."=".$value;
        }






    }
    print_r("updateOSM.php".$get_url);





}



?>

I tried include but that didn't worked. I cannot redirect my page as I am running loop.

Any help would be appreciated.

2
  • header('Location: updteOSM.php'.$get_url); Commented Nov 9, 2014 at 9:24
  • Remember that tags in OSM are always lower case, except for names in values. Commented Nov 9, 2014 at 11:11

3 Answers 3

1

try this

header('Location: updateOSM.php'.$get_url);
exit();
Sign up to request clarification or add additional context in comments.

7 Comments

Dont forget exit(); after header(); function.
@trzyeM- , Hi , After you hit this statement , You will goto another page immediately braking next execution ,So you dont need exit() Or die()
@jQueryAngryBird as you said it is not necessary to put exit() or die() but in some sort of conditions they are required. so it is good to keep them.
@user3510665 in some sort of conditions they are required ? Can you please give at least 1 example of it ? See After header() NO statement will get executed.So it will be Extra line of code which will NEVER execute.
@jQueryAngryBird Check live http headers for firefox.
|
0

Anyway

header('Location: updateOSM.php'.$get_url);

Is proper solution , because After you hit this statement , You will goto another page immediately braking next execution ,So you dont need exit() Or die()

Comments

0

I tried this:

<?php

$url = "something";

$parts = file_get_contents($url);

$json = json_decode($parts);

$private = array("people_count");

$to_osm = array("Rent","drinking_water","Shop","communication","Energy_source","waste_management","Internet_access","emigrants","number_storey","adboard");

foreach ($json as $object) {

    $get_url = "?id=";

    foreach ($object as $key => $value) {

        if ($key == "osmid") {
            $id = $value;
            $geom = "Polygon";
            $get_url.=$id."&geom=".$geom;
            //print_r($get_url);
        }

        elseif (in_array($key, $to_osm)) {
            $get_url.="&".$key."=".$value;
        }           

    }

    header('Location: updateOSM.php'.$get_url);

}

exit();
?>

The redirected url looks like this:

updateOSM.php?id=*******&geom=Polygon&Rent=no&drinking_water=public_supply&Shop=no&communication=yes&Energy_source=solar&waste_management=septic_tank&Internet_access=yes&emigrants=no&number_storey=7&adboard=yes

The id it shows is the last index of my array $json. And when I checked the changes on the feature in osm.org itself, I see only the last feature being modified and not others.

What I want is updateOSM to take every array element not just the last one to make changes.

1 Comment

Whether or not I keep exit() only the last index of the array is being modified and not all of them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.