Introduction and pre-requisites

 

 
phpCAS is the Official PHP CAS library of JA-SIG, the people behind CAS. It is a full featured CAS library. 
 
 
You will need CURL with SSL support for phpCAS to work.If you are using Zend Server (on Red Hat), these are the steps:
# yum install libidn libidn-devel curl curl-devel 
# cd /usr/local/zend/share/php-source/ext/curl 
# /usr/local/zend/bin/phpize 
# ./configure --with-ssl 
# make 
# make install
 
Download the phpCAS library from: http://www.ja-sig.org/downloads/cas-clients/php/current/and unzip the library somewhere in your PHP include path. 
 

Sample PHP script using phpCAS to authenticate against GTLogin

This script will force a user to authenticate against GTLogin and then print out their GT Account. 
 
//include the phpCAS library 
include_once("CAS.php"); 
//initialize phpCAS (CAS Version, CAS Server, Port, Base URI, Should phpCAS start a PHP Session?)
phpCAS::client(CAS_VERSION_2_0,'login.gatech.edu',443,'/cas', TRUE); 
 
//For development. Prints out additional warnings. 
phpCAS::setDebug(); 
 
//no SSL validation for the CAS server 
phpCAS::setNoCasServerValidation(); 
 
//force CAS authentication. 
phpCAS::forceAuthentication(); 
 
//Assign the GTAccount returned by GTLogin to a variable. 
$gtAccount = phpCAS::getUser(); 
 
 echo "Welcome $gtAccount!";
 
 
 
To initiatie a logout from GTLogin, call phpCAS:logout(). This will destroy the session cookie if phpCAS is in charge of it and then send the user to the GTLogin logout page. 
 
 

Tricks, Gotchas, and Things to Know

 
- If you set up your CAS client to control session cookies it will throw a warning if your session is already started.