很多站长朋友们都不太清楚php会员登录,今天小编就来给大家整理php会员登录,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 php会员登陆验证怎么写啊? 2、 php会员登录获取最后一次登录时间?? 3、 php thinkphp3.2怎么做会员登录 4、 php 不同用户登录 5、 php会员最后登录时间问题 6、 PHP做的会员登陆系统,第一次输入好用户名与密码按登陆没反应,要再次输入再按登陆才登陆成功。 php会员登陆验证怎么写啊?这是我写,你可以参考下``
<?
session_start();
//获取到用户的密码和用户名
$username=$_POST['loginname'];
$userpass=$_POST['loginpass'];
//调用数据库执行类
include_once "Connect.class.php";
$link=new Connect();
//查询是否有与之配对的信息,有返回1,没有返回0
$strsql="select * from user where username='$username' and userpass='$userpass'";
//echo $strsql;
$row = $link->execute($strsql);
//记录用户的名字,在后面的网页中保存
$_SESSION['sname']=$username;
//echo $_SESSION['sname'];
if($link->getnum($row)==1){
echo "<script>alert('登陆成功');location.href='usercenter.php';</script>";
}else{
echo "<script>alert('登陆失败');location.href='index.php';</script>";
}
?>
/*----------------------------*/
connnect.class.php
<?
/**
* 数据库的连接与各项基本操作
*
* 实现数据库 连接,并提供insert,update,delete等基本的数据库查询语句执行方法,
* 返回查询结果集或函数执行结果。
*
* @version V1.0,2005-07-26
*/
class Connect
{
/**
* @var Object $conn 数据库连接字
* @Access private
*/
var $conn;
var $result;
var $num; //查询所得记录数
var $error; //错误信息
var $row; //一条记录
var $insert_id; //自动增量值
/**
* 构造方法,根据给定的主机名,用户名,密码,数据库名建立与数据库的连接,
* 如果连接失败则抛出错误。
*
* @param String $host 数据库所在主机名或地址
* @param String $user 数据库上的一个用户名
* @param String $pwd 用户名对应的密码
* @param String $db 需要连接的库名
*
* @access public
*/
function Connect($host="localhost",$user="root",$pwd="",$db="shenglan") {
$this->conn = $this->mysql_db_connect($host,$user,$pwd,$db);
}
/**
* 执行一条sql语句,如果是查询语句,则返回一个以字段名为下标的二维数组;
* 如果是一条执行语句,则返回执行结果,执行成功返回true,失败返回false。示例如下:
* @param String $sql 需要执行的查询语句
* @return array 以字段名为下标的数组集合或者Boolean值
* @access public
*/
function execute($sql) {
if(strtolower(substr($sql,0,6))=="select")
{
//echo $sql;
return $this->Query($sql);
} else {
if($this->result = mysql_query($sql,$this->conn))
return true;
else
return false;
}
}
/**
* 取得上次查询所得数据的记录数
* @return int 查询所得记录数
* @access public
*/
function getNum() {
return $this->num;
}
/**
* 向指定的数据表中插入一条记录
* @param String $table 插入数据的数据表名
* @param Array $array 以字段名为下标的数组,如:<code>
*
* @return Boolean 插入成功返回true,失败返回false
*/
function insertSql($table,$array) {
$t1 = array();
$t2 = array();
foreach($array as $key=>$value) {
$t1[] = $key;
$t2[] = "'".$value."'";
}
$sql = "insert into ".$table." (".implode(",",$t1).") values (".implode(",",$t2).")";
//echo $sql;
if($this->execute($sql)) {
$this->insert_id = mysql_insert_id();
return true;
} else
throw new Exception("错误的SQL语句:".$sql);
}
/**
* 取得最用一个插入有自动增量字段的自动增量值
* @return int 最后一个自动增量值
* @access public
*/
function getInsertID() {
return $this->insert_id;
}
/**
* 删除给定表中的数据
* @param String $table 表名
* @param Array $array 删除条件,用法同function insertSql($table,$array) 中的参数$array
* @return Boolean
* @access public
*/
function delSql($table,$array) {
$t1 = array();
foreach($array as $key=>$value) {
$t1[] = $key."='".$value."'";
}
$sql = "delete from ".$table." where ".implode(" and ",$t1);
if($this->execute($sql))
return true;
else
throw new Exception("错误的SQL语句:".$sql);
}
/**
* 修改给定表中的数据
* @param String $table 表名
* @param Array $array 修改的字段名和值,用法同function insertSql($table,$array) 中的参数$array
* @return Boolean 修改成功返回true,失败返回false
* @access public
*/
function updateSql($table,$array,$where=0) {
$t1 = array();
foreach($array as $key=>$value) {
$t1[] = $key."='".$value."'";
}
$sql = "update ".$table." set ".implode(", ",$t1)." where ".$where;
if($this->execute($sql))
return true;
else
throw new Exception("错误的SQL语句:".$sql);
}
/**
* 返回最后一次Insert或Update操作受影响的数据行数
* @return int 行数
* @access public
*/
function getAffectedRows() {
return mysql_affected_rows();
}
/*************** private fucntions ********************/
/**
*连接数据库
*@access private
*/
function mysql_db_connect($host,$user,$pwd,$db) {
$conn = mysql_connect($host,$user,$pwd) or die(mysql_error());
mysql_select_db($db,$conn) or die(mysql_error());
return $conn;
}
/**
* 执行一句查询语句,返回一个以字段名为下标的数组集合
*
* @param String $sql 需要执行的查询语句
* @return Array 以字段名为下标的数组集合
* @access private
*/
function Query($sql) {
$array = array();
if(!$this->result = mysql_query($sql,$this->conn)) {
$this->num = 0;
return $array;
}
$this->num = mysql_num_rows($this->result);
for($i=0;$i < mysql_num_fields($this->result);$i++) {
$field[$i] = mysql_field_name($this->result,$i);
}
for($i=0;$i<$this->num;$i++) {
$parray = $this->getRow();
$array[$i] = $parray;
}
return $array;
}
/**
* 取得查询所得数据集中一条数据
* @return Array
* @access private
*/
function getRow() {
$array = array();
if($this->num==0)
return $array;
$fields = mysql_num_fields($this->result);
$this->row = mysql_fetch_array($this->result);// or die(mysql_error());
for($i=0;$i<$fields;$i++) {
$array[mysql_field_name($this->result,$i)] = $this->row[$i];
}
return $array;
}
}
?>
php会员登录获取最后一次登录时间??你好,首先你的用户数据表要有相应的字段,然后才能记录时间。具体如下,验证用户登录之后,用update语句更新用户登录时间的字段,然后再显示登录成功。希望你的问题能解决,望采纳
php thinkphp3.2怎么做会员登录现在很多网站都有 QQ互联 和新浪微博 一键登录功能,国内很多php开源项目的代码都是使用thinkphp框架编写的,但是thinkphp框架如何添加QQ互联 和新浪微博 一键登录功能呢?
工具/原料
Thinkphp3.2版本源码
QQ互联 和新浪微博 申请到的 APPID和APPKEY。
方法/步骤
一:到腾讯QQ互联上申请APPID和APPKEY。申请地址: 如同,这里我们可以获取到需要跳转到的APPID和APPKEY。新浪微博的申请同理
二:在Thinkphp官网下载 Thinkphp3.2版本的框架源码
本地安装好Thinkphp后,找到应用下的,Common/conf/config.php文件里加上。QQ互联对应的APPID和APPKEY等QQ_AUTH配置信息:
'QQ_AUTH' => array(
'APP_ID' => '1XDXXXXX', //你的QQ互联APPID
'APP_KEY' => '2XXXXXXXXXXXXXXXXXXXXX',
'SCOPE' => 'get_user_info,get_repost_list,add_idol,add_t,del_t,add_pic_t,del_idol',
'CALLBACK' => '',
),
//新浪微博的配置同理一样。
在Common目录下建立一个文件夹api。创建文件QQConnect.class.php ,添加如下代码,这里是 我们写好的一个类:
<?php
namespace Common\Api;
class QQConnect{
/**
* 获取QQconnect Login 跳转到的地址值
* @return array 返回包含code state
*
**/
public function login($app_id, $callback, $scope){
$_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection
$login_url = ";client_id="
.$app_id. "redirect_uri=" . urlencode($callback)
. "state=" . $_SESSION['state']
. "scope=".urlencode($scope);
//显示出登录地址
header('Location:'.$login_url);
}
/**
* 获取access_token值
* @return array 返回包含access_token,过期时间的数组
* */
private function get_token($app_id,$app_key,$code,$callback,$state){
if($state !== $_SESSION['state']){
return false;
exit();
}
$url = "";
$param = array(
"grant_type" => "authorization_code",
"client_id" => $app_id,
"client_secret" => $app_key,
"code" => $code,
"state" => $state,
"redirect_uri" => $callback
);
$response = $this->get_url($url, $param);
if($response == false) {
return false;
}
$params = array();
parse_str($response, $params);
return $params["access_token"];
}
/**
* 获取client_id 和 openid
* @param $access_token access_token验证码
* @return array 返回包含 openid的数组
* */
private function get_openid($access_token) {
$url = "";
$param = array(
"access_token" => $access_token
);
$response = $this->get_url($url, $param);
if($response == false) {
return false;
}
if (strpos($response, "callback") !== false) {
$lpos = strpos($response, "(");
$rpos = strrpos($response, ")");
$response = substr($response, $lpos + 1, $rpos - $lpos -1);
}
$user = json_decode($response);
if (isset($user->error) || $user->openid == "") {
return false;
}
return $user->openid;
}
/**
* 获取用户信息
* @param $client_id
* @param $access_token
* @param $openid
* @return array 用户的信息数组
* */
public function get_user_info($app_id,$token,$openid){
$url = ''.$app_id.'access_token='.$token.'openid='.$openid.'format=json';
$str = $this->get_url($url);
if($str == false) {
return false;
}
$arr = json_decode($str,true);
return $arr;
}
/**
* 请求URL地址,返回callback得到返回字符串
* @param $url qq提供的api接口地址
* */
public function callback($app_id, $app_key, $callback) {
$code = $_GET['code'];
$state = $_GET['state'];
$token = $this->get_token($app_id,$app_key,$code,$callback,$state);
$openid = $this->get_openid($token);
if(!$token || !$openid) {
return false;
exit();
}
return array('openid' => $openid, 'token' => $token);
}
/*
* HTTP GET Request
*/
private function get_url($url, $param = null) {
if($param != null) {
$query = http_build_query($param);
$url = $url . '?' . $query;
}
$ch = curl_init();
if(stripos($url, "https://") !== false){
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
$content = curl_exec($ch);
$status = curl_getinfo($ch);
curl_close($ch);
if(intval($status["http_code"]) == 200) {
return $content;
}else{
echo $status["http_code"];
return false;
}
}
/*
* HTTP POST Request
*/
private function post_url($url, $params) {
$ch = curl_init();
if(stripos($url, "https://") !== false) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$content = curl_exec($ch);
$status = curl_getinfo($ch);
curl_close($ch);
if(intval($status["http_code"]) == 200) {
return $content;
} else {
return false;
}
}
}
在项目下创建一个User模板,然后再创建一个OauthConnect.class.php文件,用户调用 QQConnect.class.php。
OauthConnect.class.php里面加入如下,
<?php
namespace User\Controller;
use Think\Controller;
class OauthController extends Controller {
/*
* Type类型,初始化
* QQConnet WeiboConnect
*/
public function index(){
switch ($_GET['type']) {
/* QQ互联登录 */
case qq:
$app_id = C('QQ_AUTH.APP_ID');
$scope = C('QQ_AUTH.SCOPE');
$callback = C('QQ_AUTH.CALLBACK');
$sns = new \Common\Api\QQConnect;
php 不同用户登录首先,你得把自己要做系统的权限设计好,比如系统管理员是否可以登录会员页面(系统管理员有最高权限,那么登录会员和普通用户页面也应该可以),会员是否能登录普通用户页面(一般来说会员是可以登录普通页面的),好了,接下来就是你的问题了:假设管理员可以登录余下两个页面,会员既能登录会员页面也能登录普通页面
第一个问题,选择abc之后提交,获取相应选择的选项:比如是普通会员,但是登录用户是管理员权限,那么你只要在根据选择的权限和用户权限判断是否有权限登录该页面,判断成功后跳转到相应页面
大致代码么,我简单写下:
$a = $_POST[登录选项];
$b = 用户权限(f_limi)用sql根据post过来的账号密码获取
if($a==0($b==0||$b==1||$b==2)){
跳转到普通用户页面(我记得php里location能实现)
}elseif($a==1($b==1||$b==2){
跳转到会员页面
}elseif($a==2$b==2){
跳转到管理员页面
}else{
echo“权限不足无法访问”;
}
第二个问题上面也解决了,不用另外给权限,判断的时候加个或就行了,规则自己建立好就行了
php会员最后登录时间问题你写个logout方法在用户退出的时候就调用这方法,在logout方法里用mktime();生成当时时间,再在logout方法里把这时间保存到数据库里就行啦。。
当然,要简单当然是记住用户登录时的时间而不是退出的时时间。这样就更简单啦。当用户登录成功的时候直接用mktime();生成时间保存到数据库。这样更简单 唉,帮你改一下吧。。
<?php
include("config.php");
if($_POST[submit]){
$username= str_replace(" ","",$_POST[username]);
$sql="select * from user_list where `username` = '$username'";
$query=mysql_query($sql);
$us=is_array($row=mysql_fetch_array($query));
$ps= $us ? md5($_POST[password].ALL_PS)== $row[password] : FALSE;
if($ps){
$_SESSION[uid]=$row[uid];
$_SESSION[user_shell]=md5($row[username].$row[password].ALL_PS);
echo "登陆成功";
$time=mktime();//注意这生成的时候栅,所以是一段你看不太明的数字,当你要调用出回来的时候要帮它格式化,Date("这里写你想显示的格式",$time)
$sql="update `你的表名` set `你表储存时间的字段名`='$time()'";
mysql_query($sql);
header("Location:user_sys.php");
}else{
echo "密码或者用户名错误";
session_destroy();
}
}
?>
PHP做的会员登陆系统,第一次输入好用户名与密码按登陆没反应,要再次输入再按登陆才登陆成功。你确认第一次按下了登陆按键之后 执行了一下代码?
else { // 登录成功
$_SESSION['Passed'] = True;
$_SESSION['U_Usermane'] = $U_Usermane;
}
如果不是的话 要注意检查你提交表单的页面
关于php会员登录的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于php会员登录 php 用户登录的详细内容...