demo (#22) - Example  http://wrs.postlbs.org/lab/wrs_tools_box_demo/ (#119) - Message List

Hello, I can´t view the file proxy.php. How can I get it? Sombody has it? Thanks

  • Message #439

    To make a cross-domain AJAX request we need that "proxy.php" file. Otherwise it is not necessary. I customized a simple example, which I found in internet (as far as I remember it was an example made by Yahoo, Author: Jason Levitt). That's how it looks like:

    <?php
    // PHP Proxy example for Yahoo! Web services.
    // Responds to both HTTP GET and POST requests
    //
    // Author: Jason Levitt
    // December 7th, 2005
    //
    // Allowed hostname (api.local and api.travel are also possible here)
    define ('HOSTNAME', 'http://host.name.domain/');
    $url = HOSTNAME.$_POST['path'];
    // Open the Curl session
    $session = curl_init($url);
    if (isset($_POST))
    {
            $postvars = '';
            foreach ($_POST as $key=>$value)
            {
                    $postvars .= $key.'='.stripslashes($value).'&';
            }
    }
    curl_setopt ($session, CURLOPT_POST, true);
    curl_setopt ($session, CURLOPT_POSTFIELDS, $postvars);
    // Don't return HTTP headers. Do return the contents of the call
    curl_setopt($session, CURLOPT_HEADER, false);
    curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
    // Make the call
    $response = curl_exec($session);
    $format = explode('.',$_POST['path']);
    // The web service returns XML. Set the Content-Type appropriately
    //error_log($format[1]);
    switch($format[1]){
            case "kml":
                    header('Content-type: application/vnd.google-earth.kml+xml');
                    break;
            case "gml":
                    header("Content-Type: text/xml");
                    break;
            case "xml":
                    header("Content-Type: text/xml");
                    break;
            case "json":
                    header("Content-Type: application/jsonrequest");
                    break;
            case "geojson":
                    header("Content-Type: application/jsonrequest");
                    break;
            case "wkt":
                    header("Content-Type: text/plain");
                    break;
            case "html":
                    header("Content-Type: text/html");
                    break;
            default:
                    header("Content-Type: text/plain");
                    break;
    }
    //header("Content-Type: text/xml");
    echo $response;
    curl_close($session);
    ?>