• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • Examples
  • File List
  • File Members

docs/examples/example_service_POST.php

Go to the documentation of this file.
00001 <?php
00002 // Example for proxied service with session support
00003 
00004 // Load the settings from the central config file
00005 include_once('config.php');
00006 // Load the CAS lib
00007 include_once($phpcas_path.'/CAS.php');
00008 
00009 // Uncomment to enable debugging
00010 phpCAS::setDebug();
00011 
00012 // Initialize phpCAS
00013 phpCAS::client(CAS_VERSION_2_0, $cas_host, $cas_port, $cas_context);
00014 
00015 // For production use set the CA certificate that is the issuer of the cert 
00016 // on the CAS server and uncomment the line below
00017 // phpCAS::setCasServerCACert($cas_server_ca_cert_path);
00018 
00019 // For quick testing you can disable SSL validation of the CAS server. 
00020 // THIS SETTING IS NOT RECOMMENDED FOR PRODUCTION. 
00021 // VALIDATING THE CAS SERVER IS CRUCIAL TO THE SECURITY OF THE CAS PROTOCOL! 
00022 phpCAS::setNoCasServerValidation();
00023 
00024 // force CAS authentication
00025 phpCAS::forceAuthentication();
00026 
00027 if ($_SERVER['REQUEST_METHOD'] != 'POST') {
00028         header('HTTP/1.1 400 Bad Request');
00029         print "<h1>I only respond to POST requests. This is a ".$_SERVER['REQUEST_METHOD']." request.</h1>";
00030         exit;
00031 }
00032 if (empty($_POST['favorite_color'])) {
00033         header('HTTP/1.1 400 Bad Request');
00034         print '<h1>You must post a <strong>favorite_color</strong>.</h1>';
00035         exit;
00036 }
00037 
00038 print '<h1>I am a service that responds to POST requests.</h1>';
00039 
00040 // at this step, the user has been authenticated by the CAS server
00041 // and the user's login name can be read with phpCAS::getUser().
00042 include 'script_info.php';
00043 
00044 // for this test, simply print that the authentication was successfull
00045 echo '<p>The user\'s login is <b>'.phpCAS::getUser().'</b>.</p>';
00046 
00047 print '<h1>Your favorite color is '.htmlentities($_POST['favorite_color']).'</h1>';
00048 
00049 // increment the number of requests of the session and print it
00050 if (!isset($_SESSION['n']))
00051         $_SESSION['n'] = 0;
00052 echo '<p>request #'.(++$_SESSION['n']).'</p>';
00053 

Generated on Sun Jun 5 2011 19:05:26 for phpCAS by  doxygen 1.7.1