cas java php单点登录_php 单点登录CAS客户端使用方法

登陆页去掉用户名 密码输入框,直接用一个连接或者按钮如下

cas.php代码如下:

session_start();header("Content-Type:text/html;charset=utf-8");

include_once("inc/init.php");

include_once("inc/class/common/common_config.php");

include_once("inc/class/common/common_db.php");

include_once("inc/class/table/table_admin.php");

// Load the settings from the central config file

//require_once 'config.php';

// Load the CAS lib

$cas_host="passport.******.edu.cn";

$cas_port=443;

$cas_context="";

require_once 'inc/CAS-1.3.0/CAS.php';

// Uncomment to enable debugging

phpCAS::setDebug();

// Initialize phpCAS

phpCAS::client(CAS_VERSION_2_0, $cas_host, $cas_port,

$cas_context);

// For production use set the CA certificate that is the issuer

of the cert

// on the CAS server and uncomment the line below

// phpCAS::setCasServerCACert($cas_server_ca_cert_path);

// For quick testing you can disable SSL validation of the CAS

server.

// THIS SETTING IS NOT RECOMMENDED FOR PRODUCTION.

// VALIDATING THE CAS SERVER IS CRUCIAL TO THE SECURITY OF THE CAS

PROTOCOL!

phpCAS::setNoCasServerValidation();

// force CAS authentication

phpCAS::forceAuthentication();

// at this step, the user has been authenticated by the CAS

server

// and the user's login name can be read with

phpCAS::getUser().

// logout if desired

if (isset($_REQUEST['logout'])) {

phpCAS::logout();

unset($_SESSION['usertype']);unset($_SESSION['adminchecked']);

}

$login_name = phpCAS::getUser();

$sql = "select id,login_name from

".common_config::TABLE_PREFIX."admin where

login_name='".$login_name."' limit 1";

$rs = cls::getDB()->getRowsNew($sql);$num = count($rs);

if($num==0){

die("请在管理员后台设置用户名为:".$login_name."的管理员账户");

}

$userid =

cls::getTable('admin')->checkLogin($login_name,'',1);

cls::closeDB();

if($userid == 0){

echo "

//common_func::sendMsg("帐户或密码输入有误",1,"./","返回重新登录");

}else{

echo "

}

主要方法就是拿doc/examples/examp_simple.php修改即可。

要先下载cas客户端文件,使用的是cas1.3.0在网盘里有

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值