Go to the documentation of this file.00001 <?php
00002
00003
00004
00005 include_once('config.php');
00006
00007 include_once($phpcas_path.'/CAS.php');
00008
00009
00010 phpCAS::setDebug();
00011
00012
00013 phpCAS::proxy(CAS_VERSION_2_0, $cas_host, $cas_port, $cas_context);
00014
00015
00016
00017
00018
00019
00020
00021
00022 phpCAS::setNoCasServerValidation();
00023
00024
00025 phpCAS::forceAuthentication();
00026
00027
00028
00029
00030
00031
00032
00033 $serviceUrl = $curbase.$curdir.'example_service_POST.php';
00034
00035 ?>
00036 <html>
00037 <head>
00038 <title>phpCAS proxy POST example</title>
00039 <link rel="stylesheet" type='text/css' href='example.css'/>
00040 </head>
00041 <body>
00042 <h1>phpCAS proxy POST example</h1>
00043 <?php include 'script_info.php' ?>
00044 <p>the user's login is <b><?php echo phpCAS::getUser(); ?></b>.</p>
00045 <h2>Response from service <?php echo $serviceUrl; ?></h2>
00046 <?php
00047 flush();
00048
00049 // call a service and change the color depending on the result
00050 try {
00051 $service = phpCAS::getProxiedService(PHPCAS_PROXIED_SERVICE_HTTP_POST);
00052 $service->setUrl($serviceUrl);
00053 $service->setContentType('application/x-www-form-urlencoded');
00054 $service->setBody('favorite_color=blue');
00055 $service->send();
00056 if ($service->getResponseStatusCode() == 200) {
00057 echo '<div class="success">';
00058 echo $service->getResponseBody();
00059 echo '</div>';
00060 } else {
00061 // The service responded with an error code 404, 500, etc.
00062 echo '<div class="error">';
00063 echo 'The service responded with a '.$service->getResponseStatusCode().' error.';
00064 echo $service->getResponseBody();
00065 echo '</div>';
00066 }
00067 } catch (CAS_ProxyTicketException $e) {
00068 if ($e->getCode() == PHPCAS_SERVICE_PT_FAILURE) {
00069 echo '<div class="error">';
00070 echo "Your login has timed out. You need to log in again.";
00071 echo '</div>';
00072 } else
00073 // Other proxy ticket errors are from bad request format (shouldn't happen)
00074
00075 throw $e;
00076 } catch (CAS_ProxiedService_Exception $e) {
00077
00078
00079
00080
00081 throw $e;
00082 }
00083
00084
00085 ?>
00086 </body>
00087 </html>
00088