example_db.php

00001 <?php
00002 
00003 //
00004 // phpCAS proxy client with PGT storage to database
00005 //
00006 
00007 // import phpCAS lib
00008 include_once('CAS/CAS.php');
00009 
00010 // set debug mode
00011 phpCAS::setDebug();
00012 
00013 // initialize phpCAS
00014 phpCAS::proxy(CAS_VERSION_2_0,'sso-cas.univ-rennes1.fr',443,'');
00015 
00016 // set PGT storage to file in XML format in the same directory as session files
00017 phpCAS::setPGTStorageDB('user',
00018                         'password',
00019                         '',// database_type defaults to `mysql'
00020                         '',// hostname defaults to `localhost'
00021                         0,// use default port
00022                         '',// database defaults to phpCAS
00023                         '' // table defaults to `pgt'
00024                         );
00025 
00026 // force CAS authentication
00027 phpCAS::forceAuthentication();
00028 
00029 // at this step, the user has been authenticated by the CAS server
00030 // and the user's login name can be read with phpCAS::getUser().
00031 
00032 // moreover, a PGT was retrieved from the CAS server that will
00033 // permit to gain accesses to new services.
00034 
00035 $service = 'http://phpcas-test.univ-rennes1.fr/examples/example_service.php';
00036 
00037 ?>
00038 <html>
00039   <head>
00040     <title>phpCAS proxy example with PGT storage to database</title>
00041   </head>
00042   <body>
00043     <h1>phpCAS proxy example with PGT storage to database</h1>
00044     <p>the user's login is <b><?php echo phpCAS::getUser(); ?></b>.</p>
00045     <h2>Response from service <?php echo $service; ?></h2><ul><hr>
00046 <?php
00047   flush();
00048   // call a service and change the color depending on the result
00049   if ( phpCAS::serviceWeb($service,$err_code,$output) ) {
00050     echo '<font color="#00FF00">';
00051   } else {
00052     echo '<font color="#FF0000">';
00053   }
00054   echo $output;
00055   echo '</font><hr></ul>';
00056 ?>
00057   </body>
00058 </html>

Generated on Wed Mar 14 14:55:56 2007 for phpCAS by  doxygen 1.5.0