<?php

ini_set("include_path", "/home/userC/c0052000/pear/lib/php:.:/usr/local/lib/php");

// Get http host, i.e. org.tidbokning.se
$http_host = $_SERVER['HTTP_HOST'];

// Get protocol, i.e. http or https
$protocol = ($_SERVER['HTTPS'] != '') ? "https://" : "http://";

error_log("http_host: " . $http_host);

// Extract org id
$str_pos = strpos($http_host, ".");
$org_id = substr($http_host, 0, $str_pos);

error_log("org_id: " . $org_id);

if ($org_id == "www") {
    echo "Error. Url should be http://org.tidbokning.se/wizard/ (ending with slash)";
} 
else {

    // Construct url to 'Booking'
    $new_url = $protocol . "www.tidbokning.se/tidbokning/booking/booking.html?org=$org_id";

    // Redirect to Tomcat and tidbokning servlet
    error_log("Redirecting to " . $new_url);
    header("Location: $new_url");
}

 ?>
