篮球外围下注_篮球投注导航_[所有网址]

篮球外围下注_篮球投注导航_[所有网址]是该公司为打造信誉第一,2014最新体验金,篮球外围下注_篮球投注导航_[所有网址]这里的所有老虎机游戏及真人百家乐游戏都具有欧洲风格,致力成为最具传播力和互动性的娱乐城网站。

美洲杯竞猜网址php实现的SSO单点登录系统接入功

2019-07-31 19:49 来源:未知

正文实例陈述了PHP完毕的注册,登入及查询用户资料成效API接口。共享给我们供大家参谋,具体如下:

本文实例陈诉了php完结的SSO单点登入系统连接效能。分享给大家供大家参照他事他说加以考察,具体如下:

正文实例陈说了PHP轻便实现单点登入功效。分享给大家供大家参谋,具体如下:

服务端

SSO斯拉维尼亚语全称Single Sign On,单点登入。SSO是在多个利用种类中,用户只要求报到三遍就能够访谈具备互相信任的施用体系。它归纳能够将这一次器重的登入映射到其它使用中用于同三个用户的报到的机制。它是方今可比流行的厂商职业整合的解决方案之一,上面大家来探问啊。

1.筹算四个设想域名

<?php
require 'conn.php';
header('Content-Type:text/html;charset=utf-8');
$action = $_GET['action'];
switch ($action) {
  //注册会员
  case"adduserinfo";
    $username = lib_replace_end_tag(trim($_GET['username']));
    $password2 = lib_replace_end_tag(trim($_GET['userpassword']));
    $password = md5("$password2" . ALL_PS);
    $email = lib_replace_end_tag(trim($_GET['email']));
    if ($username == '' || $password2 == '' || $password == '') {
      $res = urlencode("参数有误");
      exit(json_encode($res)); //有空信息
    }
    $sql = "select username from `member` where username='$username'";
    $query = mysql_query($sql, $conn);
    $count = mysql_num_rows($query);
    if ($count > 0) {
      exit(json_encode(1)); //返回1表示注册失败
    } else {
      $addsql = "insert into `member` (username,password,email) values ('$username','$password','$email')";
      mysql_query($addsql);
      exit(json_encode(0)); //返回0表示注册成功
    }
    break;
  //查询用户信息
  case"selectuserinfo";
    $username = lib_replace_end_tag($_GET['username']);
    $sql = "select id,username,nickname,mobile from `member` where username='$username'";
    $query = mysql_query($sql, $conn);
    $row = mysql_fetch_array($query);
    foreach ($row as $key => $v) {
      $res[$key] = urlencode($v);
    }
    exit(json_encode($res));
    break;
  //会员登录
  case"userlogin";
    $username = lib_replace_end_tag($_GET['username']);
    $password2 = lib_replace_end_tag(trim($_GET['userpassword']));
    $password = md5("$password2" . ALL_PS);
    $sqluser = "select id,username,password from `member` where username='" . $username . "' and password='" . $password . "'";
    $queryuser = mysql_query($sqluser);
    $rowuser = mysql_fetch_array($queryuser);
    if ($rowuser && is_array($rowuser) && !empty($rowuser)) {
      if ($rowuser['username'] == $username && $rowuser['password'] == $password) {
        if ($rowuser['password'] == $password) {
          $res = urlencode("登录成功");
          exit(json_encode($res));
        } else {
          $res = urlencode("密码错误");
          exit(json_encode($res));
        }
      } else {
        $res = urlencode("用户名不存在");
        exit(json_encode($res));
      }
    } else {
      $res = urlencode("用户名密码错误");
      exit(json_encode($res));
    }
    /*
     * 0:表示登录成功,1:表示密码错误,2:用户名不存在,3:用户名密码错误
     */
    break;
  default:
    exit(json_encode(error));
}
?>

轻便讲一下 SSO 单点登入连串的交接的法规,前提是系统本身有完美的用户认证功效,即着力的用户登入功用,那做起来就很实惠了。

127.0.0.1  www.openpoor.com
127.0.0.1  www.myspace.com

客户端例子:

SSO 登陆诉求接口往往是接口加上一个回调地址,访谈这几个地点会跳转到回调地址并带上四个ticket 参数,拿着那些 ticket 参数再诉求接口能够获取到用户新闻,要是存在用户则自动登入,不设有就新添用户并报到。

2.在openpoor的根目录下创办以下文件

<?php
header('Content-Type:text/html;charset=utf-8'); //避免输出乱码
function httpPost($url, $parms) {
  $url = $url . $parms;
  if (($ch = curl_init($url)) == false) {
    throw new Exception(sprintf("curl_init error for url %s.", $url));
  }
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 600);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  if (is_array($parms)) {
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data;'));
  }
  $postResult = @curl_exec($ch);
  $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  if ($postResult === false || $http_code != 200 || curl_errno($ch)) {
    $error = curl_error($ch);
    curl_close($ch);
    throw new Exception("HTTP POST FAILED:$error");
  } else {
    // $postResult=str_replace("xEFxBBxBF", '', $postResult);
    switch (curl_getinfo($ch, CURLINFO_CONTENT_TYPE)) {
      case 'application/json':
        $postResult = json_decode($postResult);
        break;
    }
    curl_close($ch);
    return $postResult;
  }
}
$postUrl = "http://pujia.test.com/api/server.php";
$p=$_GET['p'];
if ($p =="selectuserinfo") {
  $username = $_GET['username'];
  $parms = "?action=selectuserinfo&username=" . $username . "";
} elseif ($p =="adduserinfo") {
  $username = $_GET['username'];
  $userpassword = $_GET['userpassword'];
  $parms = "?action=adduserinfo&username=" . $username . "&userpassword=" . $userpassword . "";
} elseif ($p =="userlogin") {
  $username = $_GET['username'];
  $userpassword = $_GET['userpassword'];
  $parms = "?action=userlogin&username=" . $username . "&userpassword=" . $userpassword . "";
}
$res = httpPost($postUrl, $parms); //$parms
$res = json_decode($res);
print_r(urldecode(json_encode($res)));
?>

比方说这几个 SSO 模型实现了八个办法,三个是收获接口 url,三个是凭 ticket 获取用户音讯:

index.PHP

美洲杯竞猜网址,注:代码中的lib_replace_end_tag函数为自定义字符串过滤函数,具体可参照:浅析php过滤html字符串,制止SQL注入的章程

interface SSOLogin
{
  /**
   * 获取登录用户信息
   * @param $ticket
   * @return mixed
   */
  public function getInfoFromTicket($ticket);
  /**
   * 单点登录授权地址
   * @return mixed
   */
  public function getAuthUrl();
}
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>sync login</title>
</head>
<body>
<?php if(empty($_SESSION['username'])):?>
hello,游客;请先<a href="login.php" rel="external nofollow" >登录</a><a href="http://www.myspace.com/index.php" rel="external nofollow" rel="external nofollow" >进入空间</a>
<?php else: ?>
hello,<?php echo $_SESSION['username']; ?>;<a href="http://www.myspace.com/index.php" rel="external nofollow" rel="external nofollow" >进入空间</a>
<?php endif; ?>
 <a href="http://www.openpoor.com/index.php" rel="external nofollow" >home</a>
</body>
</html>

越多关于PHP相关内容感兴趣的读者可查阅本站专项论题:《PHP MySQL会员系统开采专项论题》、《php mysql数据库操作入门教程》、《php mysqli数据库程序设计本领总计》、《php面向对象程序设计入门教程》、《PHP网络编制程序能力计算》及《php常见数据库操作本领汇总》

再来看看调节器的主要性措施,比如回调地址是跳转到调控器

login.php

瞩望本文所述对我们PHP程序设计有着协理。

/**
 * 检测是否单点登录
 * @return bool|string
 */
public function actionCheck()
{
  $ticket = Yii::$app->getRequest()->get('ticket');
  if (!$ticket) {
    return $this->renderAuthError('请先授权', sprintf('<a href="%s">点击登录单点登录系统</a>', SSOlogin::getInstance()->getAuthUrl()));
  }
  $userInfo = SSOlogin::getInstance()->getInfoFromTicket($ticket);
  if (empty($userInfo['username'])) {
    return $this->renderAuthError('请先授权', sprintf('<a href="%s">点击登录单点登录系统</a>', SSOlogin::getInstance()->getAuthUrl()));
  }
  $username = $this->getUserName($userInfo['username']);
  $user = User::find()->canLogin()->username($username)->one();
  if (!$user) {
    $newUser = [];
    $newUser['username'] = $userInfo['username'];
    $newUser['email'] = $this->getUserName($userInfo['username']);
    $newUser['role'] = User::ROLE_DEV;
    $newUser['is_email_verified'] = 1;
    $newUser['realname'] = $userInfo['truename'];
    $user = $this->addUser($newUser);
  }
  $isLogin = Yii::$app->user->login($user, 3600 * 24 * 30);
  if ($isLogin) {
    $this->redirect('/task/index');
  }
  return true;
}
<?php
session_start();
if(!empty($_POST['username'])){
 require '../Des.php';
 $_SESSION['username'] = $_POST['username'];
 $redirect = 'http://www.openpoor.com/index.php';
 header('Location:http://www.openpoor.com/sync.php?redirect='.urlencode($redirect).'&code='.Des::encrypt($_POST['username'],'openpoor'));exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>sync login</title>
</head>
<body>
<form action="" method="post">
 <input type="text" name="username" placeholder="用户名"/>
 <input type="text" name="password" placeholder="密码"/>
 <input type="submit" value="登录"/>
</form>
</body>
</html>

您恐怕感兴趣的稿子:

  • php达成的SSO单点登入系统联网功效示例深入分析
  • SSO单点登入的PHP达成格局(Laravel框架)
  • php的sso单点登入完毕情势
  • PHP版单点登录实现方案的实例
  • PHP达成用户异地登陆提醒功效的方法【基于thinkPHP框架】
  • thinkPHP5项目中完结QQ第三方登入作用
  • PHP在同一域名下五个分裂的体系做单独登入机制详解
  • ThinkPHP完结登入退出职能
  • php面向对象的用户登入身份验证
  • PHP第三方登陆—QQ登入达成方式
  • PHP轻易完成单点登陆功效示例

大要看看这几个调整器逻辑就驾驭了。SSO 接口起到的成效正是获得用户音讯,拿这么些用户消息跟系统用户表相比,存在用户则张开登陆,子虚乌有成立用户并登入。

sync.php

那是贰在那之中间的单点系统,集成到后台,恐怕别的的 SSO 跟这不太雷同,但基本原理进程大概。

<?php
$redirect = empty($_GET['redirect']) ? 'www.openpoor.com' : $_GET['redirect'];
if(empty($_GET['code'])){
 header('Loaction:http://'.urldecode($redirect));
 exit;
}
$apps = array(
 'www.myspace.com/slogin.php'
);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<?php foreach($apps as $v): ?>
<script type="text/javascript" src="http://<?php echo $v.'?code='.$_GET['code'] ?>"></script>
<?php endforeach; ?>
<title>passport</title>
</head>
<body>
<script type="text/javascript">
window.onload=function(){
 location.replace('<?php echo $redirect; ?>');
}
</script>
</body>
</html>
TAG标签: 篮球外围下注
版权声明:本文由篮球外围下注发布于系统,转载请注明出处:美洲杯竞猜网址php实现的SSO单点登录系统接入功