<?php
require_once 'config.php';
?>
<html>
<head>
<title>
phpCAS proxy example #2</title>
<link rel="stylesheet" type='text/css' href='example.css'/>
</head>
<body>
<h1>
phpCAS proxied proxy example</h1>
<?php require 'script_info.php' ?>
<p>the user's login is <b><?php echo phpCAS::getUser(); ?></b>.</p>
<h2>Response from service <?php echo $serviceUrl; ?></h2>
<?php
flush();
// call a service and change the color depending on the result
try {
$service = phpCAS::getProxiedService(PHPCAS_PROXIED_SERVICE_HTTP_GET);
$service->setUrl($serviceUrl);
$service->send();
if ($service->getResponseStatusCode() == 200) {
echo '<div class="success">';
echo $service->getResponseBody();
echo '</div>';
} else {
// The service responded with an error code 404, 500, etc.
echo '<div class="error">';
echo 'The service responded with a '
. $service->getResponseStatusCode() . ' error.';
echo '</div>';
}
} catch (CAS_ProxyTicketException $e) {
if ($e->getCode() == PHPCAS_SERVICE_PT_FAILURE) {
echo '<div class="error">';
echo "Your login has timed out. You need to log in again.";
echo '</div>';
} else {
// Other proxy ticket errors are from bad request format (shouldn't happen)
throw $e;
}
throw $e;
}
?>
</body>
</html>