PHP Mobile-Detect检查手机移动设备访问网站

 更新时间:2016年11月25日 15:44  点击:2382
这里给大家介绍一个移动设备检查类了,从google找到的mobile-detect类,这个类可以ct判断android、ios、Tablet平板,浏览器,等比较完美完善的判断ipad,iPhone,win8等

使用方法

 代码如下 复制代码

<?php
    include 'Mobile_Detect.php';
    $detect = new Mobile_Detect();


    if ($detect->isMobile()) {
       // Any mobile device.
    }

    if($detect->isTablet()){
       // Any tablet device.
    }
    Check for a specific platform:

    if($detect->isiOS()){
       // Code to run for the Apple's iOS platform.
    }

    if($detect->isAndroidOS()){
       // Code to run for the Google's Android platform.
    }

官方实例

 代码如下 复制代码

<?php


require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
$deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');
$scriptVersion = $detect->getScriptVersion();

?><!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <title>Mobile Detect Local Demo</title>
    <style type="text/css">
        html { font-size: 100%; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }
        body { margin: 0; padding: 0 1em; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 1em; color: #333333; background-color: #ffffff; max-width:320px; }
        body, td { font-size: 1em; }
        table th { text-align:left; }
        a { color: #0088cc; text-decoration: underline; }
        a:hover { color: #005580; text-decoration: underline; }
        header h1 small { font-size:small; }
        section { margin-bottom:2em; }
        section h1 { font-size:100%; }
        .infoText { font-size:85%; }
        .response { color:red; }
        .computer { background-color:blue; color:white; }
        .tablet { background-color:yellow; color:black; }
        .phone, .true { background-color:green; color:white; }
        .sendDataButton { border-radius: 1em; -moz-border-radius: 1em; -webkit-border-radius: 1em; padding:0.5em 1em; cursor: pointer; }
        .sendDataButton_yes {
                color:white;
                border: 1px solid #56A00E;
                background: #74B042;
                font-weight: bold;
                color: #ffffff;
                text-shadow: 0 1px 0 #335413;
                background-image: -webkit-gradient(linear, left top, left bottom, from( #74B042 ), to( #56A00E )); /* Saf4+, Chrome */
                background-image: -webkit-linear-gradient( #74B042 , #56A00E ); /* Chrome 10+, Saf5.1+ */
                background-image:    -moz-linear-gradient( #74B042 , #56A00E ); /* FF3.6 */
                background-image:     -ms-linear-gradient( #74B042 , #56A00E ); /* IE10 */
                background-image:      -o-linear-gradient( #74B042 , #56A00E ); /* Opera 11.10+ */
                background-image:         linear-gradient( #74B042 , #56A00E );
        }
        .sendDataButton_no {
                color:white;
                border: 1px solid #cd2c24;
                background: red;
                font-weight: bold;
                color: #ffffff;
                text-shadow: 0 1px 0 #444444;
                background-image: -webkit-gradient(linear, left top, left bottom, from( #e13027 ), to( #b82720 )); /* Saf4+, Chrome */
                background-image: -webkit-linear-gradient( #e13027 , #b82720 ); /* Chrome 10+, Saf5.1+ */
                background-image:    -moz-linear-gradient( #e13027 , #b82720 ); /* FF3.6 */
                background-image:     -ms-linear-gradient( #e13027 , #b82720 ); /* IE10 */
                background-image:      -o-linear-gradient( #e13027 , #b82720 ); /* Opera 11.10+ */
                background-image:         linear-gradient( #e13027 , #b82720 );
        }
        #feedbackForm fieldset { border:1px dotted #333; }
        #feedbackForm label { font-weight:bold; font-size:85%; }
        #feedbackForm textarea { width: 260px; }
    </style>
  


</head>
<body>


<section>

    <p>This is a <b><?php echo $deviceType; ?></b>. Your UA is <b class="<?php echo $deviceType; ?>"><?php echo htmlentities($_SERVER['HTTP_USER_AGENT']); ?></b></p>

   


</section>


<!-- copy to GitHub demo.php -->
<section>
    <h1>Supported methods</h1>
    <table cellspacing="0" cellpadding="0">
        <tbody>
        <tr>
            <th colspan="2">Basic detection methods</th>
        </tr>
        <tr>
            <td>isMobile()</td><td <?php $check = $detect->isMobile(); if($check): ?>class="true"<?php endif; ?>><?php var_dump($check); ?></td>
        </tr>
        <tr>
            <td>isTablet()</td><td <?php $check = $detect->isTablet(); if($check): ?>class="true"<?php endif; ?>><?php var_dump($check); ?></td>
        </tr>
        </tbody>
        <tbody>
        <tr>
            <th colspan="2">Custom detection methods</th>
        </tr>
        <?php foreach($detect->getRules() as $name => $regex):
                        $check = $detect->{'is'.$name}();
        ?>
            <tr>
                    <td>is<?php echo $name; ?>()</td>
                    <td <?php if($check): ?>class="true"<?php endif; ?>><?php var_dump($check); ?></td>
            </tr>
        <?php endforeach; ?>
        </tbody>
        <tbody>
            <tr>
                <th colspan="2">Experimental version() method</th>
            </tr>
            <?php
            foreach($detect->getProperties() as $name => $match):
                $check = $detect->version($name);
                if($check!==false):
            ?>
            <tr>
                <td>version(<?php echo $name; ?>)</td>
                <td><?php var_dump($check); ?></td>
            </tr>
            <?php endif; ?>
            <?php endforeach; ?>
        </tbody>
        <tbody>
            <tr>
                <th colspan="2">Other tests</th>
            </tr>
            <tr>
                <td>isiphone()</td>
                <td><?php echo var_dump($detect->isiphone()); ?></td>
            </tr>
            <tr>
                <td>isIphone()</td>
                <td><?php echo var_dump($detect->isIphone()); ?></td>
            </tr>
            <tr>
                <td>istablet()</td>
                <td><?php echo var_dump($detect->istablet()); ?></td>
            </tr>
            <tr>
                <td>isIOS()</td>
                <td><?php echo var_dump($detect->isIOS()); ?></td>
            </tr>
            <tr>
                <td>isWhateverYouWant()</td>
                <td class="randomcrap"><?php echo var_dump($detect->isWhateverYouWant()); ?></td>
            </tr>
        </tbody>
    </table>

</section>

</body>
</html>


php-mobile-detect文件下载地焉: http://file.111cn.net/upload/2013/10/M.rar

ucenter我想有不少朋友会用到了,就是一个会员同步功能了,我们经常会把几个系统或不同论坛整合起来,下面我来给各位同学介绍一下。

UCenter同步流程:

前提是需要在Ucenter上面添加好需要同步登录的应用(至少2个才能看到效果),并且显示:通信成功

假如我添加了A,B两个应用网站

1.首先当A站登录时,登录成功后,处理实质是调用uc_client提供的方法向UCenter获取2个脚本代码(A、B站),这两个脚本代码就是访问A、B两个站的api/uc.php中的登录方法,可以在方法中做登录所需session和cookie操作。

2.当登出时,操作和登录是一样的,都需要向UCenter获取2个脚本代码,目的是用来触发A、B站的api/uc.php中登出方法。

重点:当获取到2个脚本代码后一定需要在输出让浏览器运行,否则将不会实现同步登录登出。

建议:开发调试的时候,借助浏览器监控来查看返回输出值,我当时用的是chrome F12 后 打开Network标签 。

实例详解

所谓单点登录,无非就是几个站点共用一个用户中心,实现同步登陆,同步退出。

服务器端:Loog SSO

客服端: ucenter,说实话dz商业化确实让php发展了不少。

ucenter 基本原理:

其实最终还是 用户去登录 只是采用了ajax 用户不会发现。

我们来看看和ucenter的具体程序:

config.php  [PHP代码]:

 代码如下 复制代码

define(‘UC_CONNECT’, ’mysql’); // 连接 UCenter 的方式: mysql/NULL, 默认为空时为fscoketopen()

//数据库相关 (mysql 连接时, 并且没有设置 UC_DBLINK 时, 需要配置以下变量)
define(‘UC_DBHOST’, ’localhost’); // UCenter 数据库主机
define(‘UC_DBUSER’, ’root’); // UCenter 数据库用户名
define(‘UC_DBPW’, ’123′); // UCenter 数据库密码
define(‘UC_DBNAME’, ’ucenter’); // UCenter 数据库名称
define(‘UC_DBCHARSET’, ’utf8′); // UCenter 数据库字符集
define(‘UC_DBTABLEPRE’, ’ucenter.uc_’); // UCenter 数据库表前缀
define(‘UC_KEY’, ’safefewfef’); // 与 UCenter 的通信密钥, 要与 UCenter 保持一致
define(‘UC_API’, ’http://www.111cn.net/uc’);// UCenter 的 URL 地址, 在调用头像时依赖此常量
define(‘UC_CHARSET’, ’utf-8′); // UCenter 的字符集
define(‘UC_IP’, ’127.0.0.1′); // UCenter 的 IP, 当 UC_CONNECT 为非 mysql 方式时, 并且当前应用服务器解析域名有问题时, 请设置此值
define(‘UC_APPID’, ’3′); // 对应到ucenter当前应用的 ID
define(‘UCDOMAIN’,'http://www.111cn.net/’); // 域名设置

//一些 Cookie 设置
$_UC = array();
$_UC["cookiedomain"] = ”; // cookie 作用域
$_UC["cookiepath"] = ’/'; // cookie 作用路径
$_UC["cookiepre"] = ’uc_’; // cookie 前缀
$_UC["cookietime"] = ’31536000′; //cookie 作用时间

配置文件写好后,到ucenter后台里面添加一个应用记住是自定义的 ‘UC_KEY’必须和config.php里面相同

接下来就是你的主目录下的api/uc.php

例如应用url 填写为 http://www.111cn.net 那么我就有对应的http://www.111cn.net/api/uc.php

如果要自定义的话 请确认你的对应关系。

最重要的就是api/uc.php ,同步登录就是访问各个应用的uc.php 关于这个dz已经给了demo

[PHP代码]:

 代码如下 复制代码
define(‘API_DELETEUSER’,0); //note 用户删除 API 接口开关
define(‘API_RENAMEUSER’, 0); //note 用户改名 API 接口开关
define(‘API_GETTAG’, 0); //note 获取标签 API 接口开关
define(‘API_SYNLOGIN’, 1); //note 同步登录 API 接口开关
define(‘API_SYNLOGOUT’, 1); //note 同步登出 API 接口开关
define(‘API_UPDATEPW’, 0); //note 更改用户密码 开关
define(‘API_UPDATEBADWORDS’, 0); //note 更新关键字列表 开关
define(‘API_UPDATEHOSTS’, 0); //note 更新域名解析缓存 开关
define(‘API_UPDATEAPPS’, 0); //note 更新应用列表 开关
define(‘API_UPDATECLIENT’, 0); //note 更新客户端缓存 开关
define(‘API_UPDATECREDIT’, 0); //note 更新用户积分 开关
define(‘API_GETCREDITSETTINGS’, 0); //note 向 UCenter 提供积分设置 开关
define(‘API_GETCREDIT’,0); //note 获取用户的某项积分 开关
define(‘API_UPDATECREDITSETTINGS’, 0); //note 更新应用积分设置 开关

这些参数都是向别的应用提供的功能开关

最后关于 自己的页面如何同步登录 别的应用

[PHP代码]:

 代码如下 复制代码

include_once ’../config.php’;
include_once ’../uc_client/client.php’;

你的验证登录部分

 代码如下 复制代码
list($uid, $username, $password) = uc_user_login($_POST[username], $_POST[password]);//进入ucenter验证
$ucsynlogin = uc_user_synlogin($uid);//同步登录
echo $ucsynlogin;//因为是ajax 要echo

只用php,康盛的解决方案是比较不错的了,而且利用了p3p头实现了 不同域名 单点登录

缺点就是采用ajax 客服端请求 ,如果有10个以上应用,登录速度就慢下来了,这时候就可以考虑下七夜的Loong SSO

了解了以上的东东 php的CMS和ucenter通信 就不难了。

以前做过一个招聘网站这样我们需要让别有采集不到我们客户的手机号码与邮箱地址了,所以我们会利用php实现从数据库读出来的手机号码与邮箱地址直接生成一张图片了,这样采集过去只能是图片并且无法识别了,下面我来给大家介绍两个实例。


PHP字符串处理-将手机号码生存图片

 

 代码如下 复制代码

   <?php
    ////电话号码转变成图片
    //$str 要显示的字串,$rand是否启用扰码
    function str_to_image($str,$w=130,$h=25,$rand=true)
    {
       //生成11位的数字图片
       Header("Content-type:image/png"); //告诉浏览器,下面的数据是图片,而不要按文字显示
       //定义图片宽高
       $nwidth=$w;
       $nheight=$h;
       //srand((double)microtime()*1000000); //取得目前时间的百万分之一秒值,以执行时的百万分之一秒当乱数种子
       $randval=$str; //11位数
       $im=@imagecreate($nwidth,$nheight) or die("Can't initialize new GD image stream"); //建立图象
       //图片色彩设置
       $background_color=imagecolorallocate($im,255,255,255); //匹配颜色
       $text_color=imagecolorallocate($im,23,14,91);
       //绘制图片边框
       imagefilledrectangle($im,0,0,$nwidth-1,$nheight-1,$background); //矩形区域着色
       imagerectangle($im,0,0,$nwidth-1,$nheight-1,$background_color); //绘制矩形
       imagestring($im,8,10,4,$randval,$text_color); //绘制横式字串
       if($rand){
           //加入干扰因素
           for($i=0;$i<260;$i++)
           {
               $randcolor=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
               imagesetpixel($im,rand()%($nwidth-5),rand()%($nheight+5),$randcolor); //点
           }
       }
       //imagestring($im,3,5,5,"A Simple Text String",$text_color);
       //imageinterlace($im,1);
       imagepng($im); //建立png图型
       imagedestroy($im); //结束图型
    }

    $str =  '13087263453';
    echo str_to_image($str,$w=130,$h=25,$rand=true)

例2

 代码如下 复制代码


<?php //前面不要有空行
$id=$_GET[id];
include("admin/config.php");
$sql="select * from user where id=$id";
$data=mysql_fetch_array(mysql_query($sql));
$p=SBC_DBC($data[Phone],1);
function get_str($str,$strlen=16) {
$str=stripslashes($str);
for($i=0;$i<$strlen;$i++)
if(ord(substr($str,$i,1))>0xa0) $j++;
if($j%2!=0) $strlen++;
$tmp_str=substr($str,0,$strlen);
return $tmp_str;
}
if($p<>''){
//生成5位的数字图片
Header("Content-type:image/png"); //告诉浏览器,下面的数据是图片,而不要按文字显示

//定义图片宽高
$nwidth=120;
$nheight=25;
$im=@imagecreate($nwidth,$nheight) or die("Can't initialize new GD image stream"); //建立图象

//图片色彩设置
$background_color=imagecolorallocate($im,255,255,255); //匹配颜色
$text_color=imagecolorallocate($im,23,14,91);

//绘制图片边框
imagefilledrectangle($im,0,0,$nwidth-1,$nheight-1,$background); //矩形区域着色
imagerectangle($im,0,0,$nwidth-1,$nheight-1,$background_color); //绘制矩形

//srand((double)microtime()*1000000); //取得目前时间的百万分之一秒值,以执行时的百万分之一秒当乱数种子
//$randval=rand();
$randval=$p; //5位数
imagestring($im,8,10,2,$randval,$text_color); //绘制横式字串


//加入干扰因素
//for($i=0;$i<478;$i++)
//{
//$randcolor=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
//imagesetpixel($im,rand()%100,rand()%30,$randcolor); //点
//}
//imagestring($im,3,5,5,"A Simple Text String",$text_color);
//imageinterlace($im,1);
imagepng($im); //建立png图型
imagedestroy($im); //结束图型

}else{
echo "<font size=2>商家未输入电话号码</font>";
}

?>

如果我们是一维数据去重复项就不要说了有直接的函数了,但二维数据php未提供函数了,下面小编来给大家推荐两个不错的二维数组去重复项自定义函数吧。

例1

 代码如下 复制代码


<?php
function unique_array_2d($array2D,$stkeep=false,$ndformat=true)
{
       // 判断是否保留一级数组键 (一级数组键可以为非数字)
       if($stkeep) $stArr = array_keys($array2D);

       // 判断是否保留二级数组键 (所有二级数组键必须相同)
       if($ndformat) $ndArr = array_keys(end($array2D));

       //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
       foreach ($array2D as $v){
               $v = join(",",$v);
               $temp[] = $v;
       }

       //去掉重复的字符串,也就是重复的一维数组
       $temp = array_unique($temp);

       //再将拆开的数组重新组装
       foreach ($temp as $k => $v)
       {
               if($stkeep) $k = $stArr[$k];
               if($ndformat)
               {
                       $tempArr = explode(",",$v);
                       foreach($tempArr as $ndkey => $ndval) $output[$k][$ndArr[$ndkey]] = $ndval;
               }
               else $output[$k] = explode(",",$v);
       }

       return $output;
}

$array2D = array(
       'first'=>array('title'=>'1111','date'=>'2222'),
       'second'=>array('title'=>'1111','date'=>'2222'),
       'third'=>array('title'=>'2222','date'=>'3333')
);

echo "<pre>";
print_r(unique_array_2d($array2D,true));

/**
* 将二维数组通过指定的 key 去重
*
* @param array $arr 要去重的数组
* @param array $by  指定key去重,该参数不指定将返回 array()
* @return array
*/
function array_multunique($arr,$by = array()) {
       $temp = array();
       foreach($arr as $key => $val) {
               foreach($by as $v) {
                       $temp[$key] .= isset($val[$v]) ? $val[$v] : '';
               }
       }
       return array_intersect_key($arr,array_unique($temp));
}
/*$aa = array ( 
   array ('id' => 123, 'name' => '张三' ),  
   array ('id' => 123, 'name' => '李四' ),  
   array ('id' => 124, 'name' => '王五' ),  
   array ('id' => 125, 'name' => '赵六' ),  
   array ('id' => 126, 'name' => '赵六' )  
); 
$key = 'id'; 
array_multunique ($aa, array('id')); */

function array_remove_key($array,$keys){
       if (!is_array($array) || !is_array($keys)){
               return false;
       }
       foreach($array as $t){
               foreach($keys as $k){
                       unset($t[$k]);
               }
               $doc[]=$t;
       }
       return $doc;

}
/*$array = array(
       '0' => array('a' => 'aaaaa', 'b' => 'bbbbb', 'c' => array('d' => 'ddddd', 'e' => 'eeeee')),
       '1' => array('a' => 'aaaaa', 'b' => 'bbbbb', 'c' => array('d' => 'ddddd', 'e' => 'eeeee'))
);
print_r( array_remove_key($array,array('c')));*/

function array_remove_key_val(&$a,$b,$c){
       foreach ($a as $key=>$value){
               if ( isset($value[$b]) && ($value[$b]==$c) ){
                       unset($a[$key]);
               }
       }
}
/*$a=array(
       array('id'=>1,'num'=>10,'type'=>'news'),
       array('id'=>2,'num'=>100,'type'=>'pic')
);
print_r( array_remove_key_val($a,"id","1") );*/


例2

 

 代码如下 复制代码

/二维数组去掉重复值
function array_unique_fb($array2D){
     foreach ($array2D as $v){
         $v = join(",",$v);  //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
         $temp[] = $v;
     }
     $temp = array_unique($temp);    //去掉重复的字符串,也就是重复的一维数组
    foreach ($temp as $k => $v){
        $temp[$k] = explode(",",$v);   //再将拆开的数组重新组装
    }
    return $temp;
}


//二维数组去掉重复值  并保留键值
function array_unique_fb($array2D){
    foreach ($array2D as $k=>$v){
        $v = join(",",$v);  //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
  $temp[$k] = $v;
    }
 $temp = array_unique($temp);    //去掉重复的字符串,也就是重复的一维数组
    foreach ($temp as $k => $v){
        $array=explode(",",$v);  //再将拆开的数组重新组装
  $temp2[$k]["id"] =$array[0];  
  $temp2[$k]["litpic"] =$array[1];
  $temp2[$k]["title"] =$array[2];
  $temp2[$k]["address"] =$array[3];
  $temp2[$k]["starttime"] =$array[4];
  $temp2[$k]["endtime"] =$array[5];
  $temp2[$k]["classid"] =$array[6];
  $temp2[$k]["ename"] =$array[7];
 }
    return $temp2;
}

利用php调用discuz登录框方法有很多种,最常用的就是直接使用iframe方式调用了,还有就是直接在php页面中调用了,下面小编来给大家总结一些常用的方法。

方法一,直接使用iframe调用一个加了discuz登录功能的页面

 代码如下 复制代码

 <iframe src="/login.html" style="width:100%; height:32px" scrolling="no" frameborder="0" ></iframe>


login.html代码

 代码如下 复制代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title> c-gd.com-登录</title>
<style type="text/css">
<!--
* {
 margin:0;
 padding:0;
}
body {
 font: normal 12px Arial, Helvetica, Sans-Serif, "宋体";
 line-height: 160%;
 text-align:left;
 color: #3a3a3a;
 margin:0;
 padding:0;
}
img {
 border:0;
}
ul, li {
 padding:0;
 margin:0;
 list-style:none;
}
a {
 text-decoration: none;
 color:#3a3a3a;
}
a:hover {
 color: #C00;
}
.banner {
 margin-bottom:1px;
 height:59px;
}
.denglu {
 height:31px;
 border-bottom:1px solid #FFF;
 background:#e7e3e4;
 color:#7b797a;
}
.denglu a {
 color:#7b797a;
 text-decoration:none;
}
.denglu a:hover {
 color:#C00;
 text-decoration:underline;
}
.denglu .box01 {
 margin-left:30px;
 float:left;
 width:224px;
 line-height:30px;
 height:31px;
}
.denglu .box02 {
 width:433px;
 float:left;
 color:#000;
 text-align:right;
}
.denglu .box02 input {
 border:1px #c5c3c3 solid;
 height:20px;
 width:88px;
 background:#FFF;
 line-height:20px;
 margin-top:5px;
}
.denglu .box02 .button {
 background:url(/static/image/common/img01.gif) no-repeat;
 width:50px;
 height:21px;
 border:0;
 color:#4b4b4b;
 margin:0 5px;
 font-size:12px;
 line-height:20px;
}
.denglu .box03 {
 float:right;
 line-height:30px;
 height:31px;
 margin-right:15px;
}
.denglu .box03 .font1 {
 margin-left:20px;
}
.denglu .box03 .font2 {
 margin-left:10px;
 background:url(/static/image/common/icon03.jpg) left center no-repeat;
 padding-left:8px;
 margin-left:40px;
}
-->
</style>
<script type="text/javascript">
function checkform(){
 if(document.getElementById('username').value==''){
  alert('请输入用户名');
  return false;
 }
 if(document.getElementById('password').value==''){
  alert('请输入密码');
  return false;
 } 
 return true;
}
 
function showDate()
{
var d = new Date(); 
document.write("<div class='date_div'>"+d.getYear()+"年"+(d.getMonth()+1)+"月"+d.getDate()+"日");
switch(d.getDay())
{
 case 0:
  document.write("  星期日");
  break;
 case 1:
  document.write("  星期一");
  break;
 case 2:
  document.write("  星期二");
  break;
 case 3:
  document.write("  星期三");
  break;
 case 4:
  document.write("  星期四");
  break;
 case 5:
  document.write("  星期五");
  break;
 case 6:
  document.write("  星期六");
  break;
}
 document.write("</div>");
}
</script>

</head>
<body>
<div id="header">
  <!--登录-->
  <div class="denglu">
    <div class="box01">
 <script language="JavaScript" type="text/JavaScript">
showDate();
</script>    </div>
         <form method="post" action="/bbs/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes" onsubmit="return checkform();">
     <div class="box02">
     用户名:<input type="text" name="username" id="username" />
         密码:<input type="password" name="password" id="password"  />
             <input type="hidden" name="quickforward" value="yes" />
               <input type="hidden" name="handlekey" value="ls" />
               <input type="hidden" name="iflogin" value="plus.php?mod=iframelogin" />
      <span>
      <input name="input" type="submit"  class="button" value="登录" style="cursor:pointer" />
      </span>
      <span>
      <input name="input" type="button"  class="button" value="注册" style="cursor:pointer" onclick="window.open('/bbs/member.php?mod=register')"/>
      </span>
      </div>
      </form>
   
    <div class="box03">
    <span class="font2"><a onclick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.111cn.net');" href="javascript:;">设为首页</a></span>
    <span class="font1"><a href="/" target="_parent">中文</a> | <a href="#"  target="_parent">English</a></span>
   
    </div>
 
   
  </div>
</div>
</body>
</html>

方法二,利用php方式调用了

在自定义的PHP页面里加入discuz登陆框。PHP如何调用discuz登陆框。

 代码如下 复制代码
<?php
 error_reporting(0);
 require 'source/class/class_core.php';
 $discuz = & discuz_core::instance();
 $discuz->init();
if (empty($_G['uid'])) {
?>
 
<form target="_blank" action="member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes" method="post" name="form2" onSubmit="return check()">
 <span>用户名:<input name="username" type="text" id="textfield2" size="13" tabindex="1" value="请输入用户名" onFocus="this.value='';" onBlur="if(this.value==''){this.value='请输入用户名';}">
 密码:<input name="password" type="password" id="password" size="12">
 <input type="submit" name="button2" id="button2" value="登录" onClick="setTimeout('window.location.reload()', 2000)">
 <a href="member.php?mod=register" target="_blank">注册</a>
 <a href="member.php?mod=logging&action=login&viewlostpw" target="_blank">找回密码</a>
 <input type="hidden" name="referer" value="/" /></span>
</form>
 
<?php } else { ?>
 
<div>
尊敬的<a href="home.php?mod=space&uid=<?php echo $_G['uid']; ?>&do=profile" target="_blank"><? echo $_G['username']; ?></a>,欢迎您光临!&nbsp&nbsp|&nbsp<a href="home.php?mod=space&do=thread&view=me" target="_blank">我的帖子</a>&nbsp|&nbsp <a href="home.php" target="_blank">个人中心</a>&nbsp|&nbsp <a href="member.php?mod=logging&action=logout&formhash=<? echo FORMHASH;?>" target="_blank" onClick="setTimeout('window.location.reload()', 2000)">退出登陆</a>
</div>
 
<?php }?>


方法三:discuz登陆框是ajax调用的,一开始在firebug下看到了调用了接口:

 代码如下 复制代码
/member.php  ?mod=logging&action=login&infloat=yes&handlekey=login&inajax=1&ajaxtarget=fwin_content_login

 
这返回的是一个xml的内容,其中就一个结点root,里面会根据本地的cookies判断是否登录了论坛,如果没有登陆

里面的内容就是一段form登陆表单。如果登陆了里面就是一段登陆后的信息。然后将ajax请求中的css保存到本

地。能够实现登陆框调用。登陆框中有一个hidden的input name=‘reffer’ 这里面的value值是来路链接.不过要是

论坛程序里的。比如将这个连接换成h/home.php?mod=spacecp&ac=blog这样登陆完后会

自动跳转到发博客的页面。可以实现一键发帖功能。

代码如下:

 代码如下 复制代码

<?php 
$login = file_get_contents("/member.php? 
mod=logging&action=login&infloat=yes&handlekey=login&inajax=1&ajaxtarget=fwin_content_login"); 
require_once('SofeeXmlParser.php');//xml解析类 博客里搜索xml有相关介绍 
$xml = new SofeeXmlParser(); 
$xml->parseString($login); 
$tree = $xml->getTree(); 
$login = str_replace("member.php","h/member.php",$tree["root"]["value"]); 
$login = str_replace("h/./","h/home.php? 
mod=spacecp&ac=blog",$login);//跳转到发帖页面 
$login = preg_replace('/<h3 class="flb">(.*)</h3>/i','',$login); 
var_dump($login); 
exit(); 
$login = iconv('utf-8','gbk',$login); 
   
echo $login; 
?>

[!--infotagslink--]

相关文章

  • 安卓手机app添加支付宝支付开发教程

    支付宝支付在国内算是大家了,我们到处都可以使用支付宝了,下文整理介绍的是在安卓app应用中使用支付宝进行支付的开发例子。 之前讲了一篇博客关与支付宝集成获取...2016-09-20
  • PHP+Ajax手机发红包的程序例子

    PHP+Ajax有许多的功能都会用到它小编今天就有使用PHP+Ajax实现的一个微信登录功能了,下面我们来看一个PHP+Ajax手机发红包的程序例子,具体如下所示。 PHP发红包基本...2016-11-25
  • 破解安卓手机上的九宫格锁方法步骤

    很多用安卓智能手机的朋友是用九宫格锁屏,网上也有暴力删除手机图形锁的方法,不过我们可以用程序来破解。本文只提供技术学习,不能干坏事 安卓手机的图形锁(九宫格)...2016-09-20
  • 华为手机怎么恢复已卸载的应用?华为手机恢复应用教程

    华为手机怎么恢复已卸载的应用?有时候我们在使用华为手机的时候,想知道卸载的应用怎么恢复,这篇文章主要介绍了华为手机恢复应用教程,需要的朋友可以参考下...2020-06-29
  • 如何获取网站icon有哪些可行的方法

    获取网站icon,常用最简单的方法就是通过website/favicon.ico来获取,不过由于很多网站都是在页面里面设置favicon,所以此方法很多情况都不可用。 更好的办法是通过google提供的服务来实现:http://www.google.com/s2/favi...2014-06-07
  • 华为手机怎么开启双时钟? 华为添加双时钟的技巧

    华为手机怎么开启双时钟?华为手机是可以设置双时钟的,如果来回在两个有时差的地方工作,是可以设置双时钟显示,下面我们就来看看华为添加双时钟的技巧,需要的朋友可以参考下...2020-12-08
  • 安卓手机wifi打不开修复教程,安卓手机wifi打不开解决方法

    手机wifi打不开?让小编来告诉你如何解决。还不知道的朋友快来看看。 手机wifi是现在生活中最常用的手机功能,但是遇到手机wifi打不开的情况该怎么办呢?如果手机wifi...2016-12-21
  • jQuery Mobile开发中日期插件Mobiscroll使用说明

    这篇文章主要介绍了jQuery Mobile开发中日期插件Mobiscroll使用说明,需要的朋友可以参考下...2016-03-03
  • mac下Apache + MySql + PHP搭建网站开发环境

    首先为什不自己分别搭建Apache,PHP和MySql的环境呢?这样自己可以了解更多知识,说起来也更酷。可也许因为我懒吧,我是那种“既然有现成的,用就是了”的人。君子生非异也,善假于物也。两千年前的荀子就教导我们,要善于利用工具...2014-06-07
  • React引入antd-mobile+postcss搭建移动端

    本文给大家分享React引入antd-mobile+postcss搭建移动端的详细流程,文末给大家分享我的一些经验记录使用antd-mobile时发现我之前配置的postcss失效了,防止大家踩坑,特此把解决方案分享到脚本之家平台,需要的朋友参考下吧...2021-06-21
  • php实现网站留言板功能

    我要实现的就是下图的这种样式,可参考下面这两个网站的留言板,他们的实现原理都是一样的畅言留言板样式:网易跟帖样式:原理 需要在评论表添加两个主要字段 id 和 pid ,其他字段随意添加,比如文章id、回复时间、回复内容、...2015-11-08
  • jQuery mobile 移动web(6)

    这篇文章主要介绍了jQuery mobile 移动web(6)的相关资料,需要的朋友可以参考下...2015-12-21
  • jQuery Mobile 触摸事件实例

    这篇文章主要演示了5个jQuery Mobile 触摸事件实例,需要的朋友可以参考下。...2016-06-12
  • 网站广告怎么投放最好?首屏广告投放类型优化和广告位布局优化的案例

    网站广告怎么投放最好?一个网站中广告位置最好的是哪几个地方呢,许多的朋友都不知道如何让自己的网站广告收效最好了,今天我们就一起来看看吧。 在说到联盟优化前,...2016-10-10
  • 小米手机负一屏该怎么设置? 如何使用小米手机负一屏

    小米手机负一屏该怎么设置?小米手机最近推出了负一屏的功能,集成了很多信息,可以放一些需要知道的信息,下面我们就来看看详细的教程,需要的朋友可以参考下。 最新的开...2016-12-15
  • oppo手机怎么设置充电提示音 oppo手机充电提示音设置方法

    oppo手机充电提示音怎么关闭?用户要学会充电提示音的设置方法,这样才能熟练的操作更换提示音或者是关掉提示音,关于OPPO手机充电提示音的设置下面会有具体的介绍,各位用户一起来看看详细的操作方法吧...2020-12-08
  • 保千里打令VR手机怎么样?什么时候发布?

    保千里打令VR手机怎么样?什么时候发布?全球首款VR手机保千里打令VR手机将于10月24日在深圳大梅沙国际水上运动中心隆重发布,对保千里打令VR手机不太了解朋友可以看看...2016-11-01
  • 手机配置那么高为什么玩王者荣耀还会卡?

    明明我的手机配置那么高(都八核了)为什么玩游戏还会卡?对安卓手机来说玩游戏卡顿的原因一般有两种;性能不足导致的卡顿以及CPU发热降频导致的卡顿,详情我们来看看吧...2017-07-06
  • 钉钉怎么双开登录两个账号? 小米手机双开钉钉的技巧

    钉钉怎么双开登录两个账号?钉钉中想要双开登录两个账号,该怎么登录呢?下面我们就来看看小米手机双开钉钉的技巧,需要的朋友可以参考下...2020-06-29
  • 华为手机蓝牙可以连接几个设备?华为设置蓝牙音频连接个数的技巧

    华为手机蓝牙可以连接几个设备? 华为手机使用蓝牙的时候,想要知道能连接几个设备,这都是可以设置呢?下面我们就来看看华为设置蓝牙音频连接个数的技巧,需要的朋友可以参考下...2020-12-08