function redirectHandler()
{
    $hostedPageId = $_GET['id'];
    /* Requesting ChargeBee server about the Hosted page state and 
     * getting the details of the created subscription.
     */
    $result = ChargeBee_HostedPage::retrieve($hostedPageId);
    $hostedPage = $result->hostedPage();
    /*
     * Checking the state of the hosted page. If the state is not "succeeded",
     * then cusotmer checkout is considered as failed.
     */
    if ($hostedPage->state != "succeeded") {
        header("HTTP/1.0 400 Error");
        include $_SERVER["DOCUMENT_ROOT"] . "/error_pages/400.html";
        return;
    }
    $subscriptionId = $hostedPage->content()->subscription()->id;
    addShippingAddress($subscriptionId, $result);
    header("Location: thankyou?subscription_id=" . URLencode($subscriptionId));
}
<?php

/*
 * Adding ChargeBee php librariesand configuration files.
 */
require_once dirname(__FILE__) . "/Config.php";
require_once dirname(__FILE__) . "/ErrorHandler.php";
require_once dirname(__FILE__) . "/Util.php";
if ($_POST) {
    validateParameters($_POST);
    try {
        $result = createSubscription();
        addShippingAddress($result->subscription(), $result->customer());
        $jsonResp = array();
        /*
         * Forwarding to success page after successful create subscription in ChargeBee.
         */
        $queryParameters = "name=" . urlencode($result->customer()->firstName) . "&planId=" . urlencode($result->subscription()->planId);
        $jsonResp["forward"] = "thankyou.html";
        echo json_encode($jsonResp, true);
    } catch (ChargeBee_PaymentException $e) {
        handleTempTokenErrors($e);
    } catch (ChargeBee_InvalidRequestException $e) {
        handleInvalidRequestErrors($e, "plan_id");
    } catch (Exception $e) {
        handleGeneralErrors($e);
    }
}
/* Creates the subscription in ChargeBee using the checkout details and 
 * stripe temporary token provided by stripe.
 */