微信扫码网站自动登录的实现方法
magento 微信扫码网站自动登录
案例仿照了微信联合登陆的做法,微信联合登陆介绍:
https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&lang=zh_CN
查看授权后接口调用(UnionID),不难发现填写回调地址,用户确认登陆pc端即可跳转
获取UnionID方法
public function wcallbackAction(){
$code = $_GET['code'];
$state = $_GET['state'];
$setting = include CONFIG_PATH . 'setting.php';
$appid=$setting['weixin']['appid'];
$appsecret=$setting['weixin']['appsecret'];
if (empty($code)) $this->showMessage('授权失败');
try{
$token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$appsecret.'&code='.$code.'&grant_type=authorization_code';
$token = json_decode($this->https_request($token_url));
}catch(Exception $e)
{
print_r($e);
}
if (isset($token->errcode)) {
echo '<h1>错误:</h1>'.$token->errcode;
echo '<br/><h2>错误信息:</h2>'.$token->errmsg;
exit;
}
$access_token_url = 'https://api.weixin.qq.com/sns/oauth2/refresh_token?appid='.$appid.'&grant_type=refresh_token&refresh_token='.$token->refresh_token;
//转成对象
$access_token = json_decode($this->https_request($access_token_url));
if (isset($access_token->errcode)) {
echo '<h1>错误:</h1>'.$access_token->errcode;
echo '<br/><h2>错误信息:</h2>'.$access_token->errmsg;
exit;
}
$user_info_url = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$access_token->access_token.'&openid='.$access_token->openid.'&lang=zh_CN';
//转成对象
$user_info = json_decode($this->https_request($user_info_url));
if (isset($user_info->errcode)) {
echo '<h1>错误:</h1>'.$user_info->errcode;
echo '<br/><h2>错误信息:</h2>'.$user_info->errmsg;
exit;
}
//打印用户信息
// echo '<pre>';
// print_r($user_info);
// echo '</pre>';
//获取unionid
$uid=$user_info->unionid;
}
//用户操作处理 分为再次登录和第一次登陆
$sql="select h_user_id from dtb_user_binded as t1 left join dtb_user_weixin as t2 on t1.u_id=t2.id where t1.u_type='".
User::$arrUtype['weixin_num_t']."' and t2.openid='$user_info->unionid'";
$h_user_id = Core_Db::getOne($sql);
if(!empty($h_user_id)){//该weixin号再次登录
}{//该weixin号第一次登录
}
php 微信扫码 pc端自动登陆注册
用的接口scope 是snsapi_userinfo,微信登陆一个是网页授权登陆,另一个是微信联合登陆
网页授权登陆:http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html
微信联合登陆:https://open.weixin.qq.com/cgi-bin/frame?t=home/web_tmpl&lang=zh_CN
一:首先把微信链接带个标识生成二维码
比如链接为 https://open.weixin.qq.com/connect/oauth2/authorize?appid=’.$appid.’&redirect_uri=’.$url.’&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect’ 我们可以在state上做文章,因为state你传入什么微信那边返回什么
可以作为服务器与微信段的一个标识
public function creatqrAction(){
if($_GET['app']){
$wtoken=$_COOKIE['wtoken'];
$postdata=$_SESSION['w_state'];
if($wtoken){
$postdata=$wtoken;
}
<span style="color: #3366ff;">include CONFIG_PATH . 'phpqrcode/'.'phpqrcode.php';</span>
$sh=$this->shar1();
$value="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx138697ef383a9167&redirect_uri=http://www.xxx.net/login/wcallback&response_type=code&scope=snsapi_userinfo&state=".$postdata."&connect_redirect=1#wechat_redirect";
$errorCorrectionLevel = "L";
$matrixPointSize = "5";
QRcode::png($value, false, $errorCorrectionLevel, $matrixPointSize);
}
}
此时生成了二维码 state是标识,phpqrcode可以在文章末尾下载,这样我们设置了回调地址http://www.xxx.net/login/wcallback
就可以在wcallback方法里面处理数据 插入用户 生成session,跳转登陆,pc端可以设置几秒钟ajax请求服务器,一旦获取到了
state,即实现调整,微信浏览器里处理完后可以关闭窗口,微信js可实现
document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
WeixinJSBridge.call('closeWindow');
}, false);
也可以授权登陆成功后跳转到微信服务号关注页面
header("Location: weixin://profile/gh_a5e1959f9a4e");
wcallback方法做处理登陆
$code = $_GET['code'];
$state = $_GET['state'];
$setting = include CONFIG_PATH . 'setting.php';
$appid=$setting['weixin']['appid'];
$appsecret=$setting['weixin']['appsecret'];
if (empty($code)) $this->showMessage('授权失败');
try{
$token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$appsecret.'&code='.$code.'&grant_type=authorization_code';
$token = json_decode($this->https_request($token_url));
}catch(Exception $e)
{
print_r($e);
}
if (isset($token->errcode)) {
echo '<h1>错误:</h1>'.$token->errcode;
echo '<br/><h2>错误信息:</h2>'.$token->errmsg;
exit;
}
$access_token_url = 'https://api.weixin.qq.com/sns/oauth2/refresh_token?appid='.$appid.'&grant_type=refresh_token&refresh_token='.$token->refresh_token;
//转成对象
$access_token = json_decode($this->https_request($access_token_url));
if (isset($access_token->errcode)) {
echo '<h1>错误:</h1>'.$access_token->errcode;
echo '<br/><h2>错误信息:</h2>'.$access_token->errmsg;
exit;
}
$user_info_url = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$access_token->access_token.'&openid='.$access_token->openid.'&lang=zh_CN';
//转成对象
$user_info = json_decode($this->https_request($user_info_url));
if (isset($user_info->errcode)) {
echo '<h1>错误:</h1>'.$user_info->errcode;
echo '<br/><h2>错误信息:</h2>'.$user_info->errmsg;
exit;
}
//打印用户信息
// echo '<pre>';
// print_r($user_info);
// echo '</pre>';
Ecshop 支付宝手机网页支付,针对ecshop wap手机版
<?php
/**
* ECSHOP 支付宝手机网页插件
*/
if (!defined('IN_ECS'))
{
die('Hacking attempt');
}
$payment_lang = ROOT_PATH . 'languages/' .$GLOBALS['_CFG']['lang']. '/payment/alipay_wap.php';
if (file_exists($payment_lang))
{
global $_LANG;
include_once($payment_lang);
}
/* 模块的基本信息 */
if (isset($set_modules) && $set_modules == TRUE)
{
$i = isset($modules) ? count($modules) : 0;
/* 代码 */
$modules[$i]['code'] = basename(__FILE__, '.php');
/* 描述对应的语言项 */
$modules[$i]['desc'] = 'alipay_wap_desc';
/* 是否支持货到付款 */
$modules[$i]['is_cod'] = '0';
/* 是否支持在线支付 */
$modules[$i]['is_online'] = '1';
/* 作者 */
$modules[$i]['author'] = 'ECSHOP TEAM';
/* 网址 */
$modules[$i]['website'] = 'http://www.alipay.com';
/* 版本号 */
$modules[$i]['version'] = '1.0.2';
/* 配置信息 共用?? */
$modules[$i]['config'] = array(
array('name' => 'alipay_account', 'type' => 'text', 'value' => ''),
array('name' => 'alipay_key', 'type' => 'text', 'value' => ''),
array('name' => 'alipay_partner', 'type' => 'text', 'value' => ''),
array('name' => 'alipay_pay_method', 'type' => 'select', 'value' => '')
);
return;
}
/**
* 类
*/
class alipay_wap
{
/**
* 构造函数
*
* @access public
* @param
*
* @return void
*/
function alipay()
{
}
function __construct()
{
$this->alipay();
}
/**
* 生成支付代码
* @param array $order 订单信息
* @param array $payment 支付方式信息
*/
function get_code($order, $payment)
{
if (!defined('EC_CHARSET'))
{
$charset = 'utf-8';
}
else
{
$charset = EC_CHARSET;
}
//合作身份者id,以2088开头的16位纯数字
$alipay_config['partner'] = $payment['alipay_partner'];
//签名方式 不需修改
$alipay_config['sign_type'] = '0001';
//安全检验码,以数字和字母组成的32位字符
//如果签名方式设置为“MD5”时,请设置该参数
//$alipay_config['key'] = $payment['alipay_key'];
//商户的私钥(后缀是.pen)文件相对路径
//如果签名方式设置为“0001”时,请设置该参数
$alipay_config['private_key_path'] = dirname(__FILE__)."/alipay_wap/key/rsa_private_key.pem";
//支付宝公钥(后缀是.pen)文件相对路径
//如果签名方式设置为“0001”时,请设置该参数
$alipay_config['ali_public_key_path']= dirname(__FILE__)."/alipay_wap/key/alipay_public_key.pem";
//↑↑↑↑↑↑↑↑↑↑请在这里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
//字符编码格式 目前支持 gbk 或 utf-8
$alipay_config['input_charset']= 'utf-8';
//ca证书路径地址,用于curl中ssl校验
//请保证cacert.pem文件在当前文件夹目录中
$alipay_config['cacert'] = dirname(__FILE__)."/alipay_wap/cacert.pem";
//访问模式,根据自己的服务器是否支持ssl访问,若支持请选择https;若不支持请选择http
$alipay_config['transport'] = 'http';
require_once(dirname(__FILE__)."/alipay_wap/lib/alipay_submit.class.php");
//返回格式
$format = "xml";
//必填,不需要修改
//返回格式
$v = "2.0";
//必填,不需要修改
//请求号
$req_id = date('Ymdhis');
//必填,须保证每次请求都是唯一
//**req_data详细信息**
//服务器异步通知页面路径
$notify_url = return_url(basename(__FILE__, '.php'));
//需http://格式的完整路径,不允许加?id=123这类自定义参数
//页面跳转同步通知页面路径
$call_back_url = return_url(basename(__FILE__, '.php'));
//需http://格式的完整路径,不允许加?id=123这类自定义参数
//操作中断返回地址
$merchant_url = $GLOBALS['ecs']->url();
//用户付款中途退出返回商户的地址。需http://格式的完整路径,不允许加?id=123这类自定义参数
//卖家支付宝帐户
$seller_email = $payment['alipay_account'];
//必填
//商户订单号
$out_trade_no = $order['order_sn'] . $order['log_id'];
//商户网站订单系统中唯一订单号,必填
//订单名称
$subject = $order['order_sn'];
//必填
//付款金额
$total_fee = $order['order_amount'];
//必填
//请求业务参数详细
$req_data = '<direct_trade_create_req><notify_url>' . $notify_url . '</notify_url><call_back_url>' . $call_back_url . '</call_back_url><seller_account_name>' . $seller_email . '</seller_account_name><out_trade_no>' . $out_trade_no . '</out_trade_no><subject>' . $subject . '</subject><total_fee>' . $total_fee . '</total_fee><merchant_url>' . $merchant_url . '</merchant_url></direct_trade_create_req>';
//必填
/************************************************************/
//构造要请求的参数数组,无需改动
$para_token = array(
"service" => "alipay.wap.trade.create.direct",
"partner" => trim($alipay_config['partner']),
"sec_id" => trim($alipay_config['sign_type']),
"format" => $format,
"v" => $v,
"req_id" => $req_id,
"req_data" => $req_data,
"_input_charset" => trim(strtolower($alipay_config['input_charset']))
);
//建立请求
$alipaySubmit = new AlipaySubmit($alipay_config);
$html_text = $alipaySubmit->buildRequestHttp($para_token);
//URLDECODE返回的信息
$html_text = urldecode($html_text);
//解析远程模拟提交后返回的信息
$para_html_text = $alipaySubmit->parseResponse($html_text);
//获取request_token
$request_token = $para_html_text['request_token'];
/**************************根据授权码token调用交易接口alipay.wap.auth.authAndExecute**************************/
//业务详细
$req_data = '<auth_and_execute_req><request_token>' . $request_token . '</request_token></auth_and_execute_req>';
//必填
//构造要请求的参数数组,无需改动
$parameter = array(
"service" => "alipay.wap.auth.authAndExecute",
"partner" => trim($alipay_config['partner']),
"sec_id" => trim($alipay_config['sign_type']),
"format" => $format,
"v" => $v,
"req_id" => $req_id,
"req_data" => $req_data,
"_input_charset" => trim(strtolower($alipay_config['input_charset']))
);
//建立请求
$alipaySubmit = new AlipaySubmit($alipay_config);
$html_text = $alipaySubmit->buildRequestForm($parameter, 'get', '进行付款');
return $html_text;
}
/**
* 响应操作
*/
function respond()
{
if (!empty($_POST))
{
foreach($_POST as $key => $data)
{
$_GET[$key] = $data;
}
}
log_write($_GET, 'alipay_wap');
$payment = get_payment($_GET['code']);
$seller_email = rawurldecode($_GET['seller_email']);
$order_sn = str_replace($_GET['subject'], '', $_GET['out_trade_no']);
$order_sn = trim($order_sn);
/* 检查数字签名是否正确 */
ksort($_GET);
reset($_GET);
//合作身份者id,以2088开头的16位纯数字
$alipay_config['partner'] = $payment['alipay_partner'];
//签名方式 不需修改
$alipay_config['sign_type'] = '0001';
//安全检验码,以数字和字母组成的32位字符
//如果签名方式设置为“MD5”时,请设置该参数
//$alipay_config['key'] = $payment['alipay_key'];
//商户的私钥(后缀是.pen)文件相对路径
//如果签名方式设置为“0001”时,请设置该参数
$alipay_config['private_key_path'] = dirname(__FILE__)."/alipay_wap/key/rsa_private_key.pem";
//支付宝公钥(后缀是.pen)文件相对路径
//如果签名方式设置为“0001”时,请设置该参数
$alipay_config['ali_public_key_path']= dirname(__FILE__)."/alipay_wap/key/alipay_public_key.pem";
//↑↑↑↑↑↑↑↑↑↑请在这里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
//字符编码格式 目前支持 gbk 或 utf-8
$alipay_config['input_charset']= 'utf-8';
//ca证书路径地址,用于curl中ssl校验
//请保证cacert.pem文件在当前文件夹目录中
$alipay_config['cacert'] = dirname(__FILE__)."/alipay_wap/cacert.pem";
//访问模式,根据自己的服务器是否支持ssl访问,若支持请选择https;若不支持请选择http
$alipay_config['transport'] = 'http';
require_once(dirname(__FILE__)."/alipay_wap/lib/alipay_notify.class.php");
//计算得出通知验证结果
$alipayNotify = new AlipayNotify($alipay_config);
$verify_result = $alipayNotify->verifyNotify();
if(!$verify_result) {//验证不成功
return false;
}
$notify_data = $alipayNotify->decrypt($_GET['notify_data']);
$doc = new DOMDocument();
$doc->loadXML($notify_data);
if( ! empty($doc->getElementsByTagName( "notify" )->item(0)->nodeValue) ) {
//商户订单号
$out_trade_no = $doc->getElementsByTagName( "out_trade_no" )->item(0)->nodeValue;
$out_trade_no = str_replace($_GET['subject'], '', $out_trade_no);
$out_trade_no = trim($out_trade_no);
//支付宝交易号
$trade_no = $doc->getElementsByTagName( "trade_no" )->item(0)->nodeValue;
//交易状态
$trade_status = $doc->getElementsByTagName( "trade_status" )->item(0)->nodeValue;
/* 检查支付的金额是否相符 */
if (!check_money($out_trade_no, $_GET['total_fee']))
{
return false;
}
if($_GET['trade_status'] == 'TRADE_FINISHED') {
/* 改变订单状态 */
order_paid($out_trade_no);
return true;
}else if ($_GET['trade_status'] == 'TRADE_SUCCESS') {
/* 改变订单状态 */
order_paid($out_trade_no, 2);
return true;
}else{
return false;
}
}
}
}
?>
一:添加文字水印 使用方法
require 'image.class.php'
$src="001.jpg";
$content="hello";
$font_url="my.ttf";
$size=20;
$image=new Image($src);
$color=array(
0=>255,
1=>255,
2=>255,
2=>20
);
$local=array(
'x'=>20,
'y'=>30
);
$angle=10;
$image->fontMark($content,$font_url,$size,$color,$local,$angle);
$image->show();
二:图片缩略图 使用方法:
require 'image.class.php'
$src="001.jpg";
$image=new Image($src);
$image->thumb(300,200);
$image->show();
三:image.class.php
class image{
private $info;
private $image;
public function __contruct($src){
$info= getimagesize($src);
$this->info=array(
'width'=> $info[0],
'height'=>$info[1],
'type'=>image_type_to_extension($info[2],false),
'mime'=>$info['mime'],
);
$fun="imagecreatefrom{$this->info['type']}";
$this->image= $fun($src);
}
//缩略图
public function thumd($width,$height){
$image_thumb= imagecreatetruecolor($width,$height);
imagecopyresampled($image_thumb,$this->image,0,0,0,0,$width,$height,$this->info['width'],$this->info['height']);
imagedestroy($this->image);
$this->image=$image_thumb;
}
//文字水印
public function fontMark($content,$font_url,$size,$color,$local,$angle){
$col=imagecolorallocatealpha($this->image,$color[0],$color[1],$color[2],$color[3]);
$text=imagettftext($this->image,$size,$angle,$local['x'],$local['y'],$col,$font_url,$content);
}
//输出图片
public function show()
{
header("Content-type:",$this->info['mime']);
$func="image{$this->info['type']}";
$func($this->image);
}
public function save($nwename){
$func="image{$this->info['type']}";
//从内存中取出图片显示
$func($this->image);
//保存图片
$func($this->image,$nwename.$this->info['type']);
}
public function _destruct(){
imagedestroy($this->image);
}
}
例子
<?php
try {
$client = new SoapClient("http://localhost:8080/Webtest/NewService?wsdl");
// $result = $client->__soapCall("operation",array(4));//fault
// $result = $client->__soapCall("operation",array("id"=>4));//fault
// $result = $client->operation(4);//fault
$result = $client->operation(array("id"=>4));//OK
$back = json_encode($result);
echo $back;
} catch (SoapFault $fault){
echo "Error: ",$fault->faultcode,", string: ",$fault->faultstring;
}
?>
//仅有标记为OK的那行可以成功返回数字4,其它返回的都是数字0(参数应该是没有传过去,服务器端id初始是0)。
//手册里soapcall的例子:
<?php
$client = new SoapClient("some.wsdl");
$client->SomeFunction($a, $b, $c);
$client->__soapCall("SomeFunction", array($a, $b, $c));
$client->__soapCall("SomeFunction", array($a, $b, $c), NULL,
new SoapHeader(), $output_headers);
$client = new SoapClient(null, array('location' => "http://localhost/soap.php",
'uri' => "http://test-uri/"));
$client->SomeFunction($a, $b, $c);
$client->__soapCall("SomeFunction", array($a, $b, $c));
$client->__soapCall("SomeFunction", array($a, $b, $c),
array('soapaction' => 'some_action',
'uri' => 'some_uri'));
?>
本文我们来分享用php如何识别用户是通过 PC、iPad 还是手机,然后我们还可以看看腾讯的通过JS语句判断WEB网站的访问端是电脑还是手机。
先我们来看看一段用php如何识别用户是通过 PC、iPad 还是手机来访问网站?
<?php
$uAgent = $_SERVER['HTTP_USER_AGENT'];
$osPat = "mozilla|m3gate|winwap|openwave|Windows NT|Windows 3.1|95|Blackcomb|98|ME|XWindow|ubuntu|Longhorn|AIX|Linux|AmigaOS|BEOS|HP-UX|OpenBSD|FreeBSD|NetBSD|OS\/2|OSF1|SUN";
if(preg_match("/($osPat)/i", $uAgent ))
{
echo "来着PC访问";
}
else
{
echo "其他终端访问";
}
?>
以下是腾讯的通过JS语句判断WEB网站的访问端是电脑还是手机
腾讯网的适配代码
如何判断访问网站的机器类型-如何判断ipad
JS 判断浏览器客户端类型(ipad,iphone,android)
<script type="text/javascript">
<!--
//平台、设备和操作系统
var system = {
win: false,
mac: false,
xll: false,
ipad:false
};
//检测平台
var p = navigator.platform;
system.win = p.indexOf("Win") == 0;
system.mac = p.indexOf("Mac") == 0;
system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
system.ipad = (navigator.userAgent.match(/iPad/i) != null)?true:false;
//跳转语句,如果是手机访问就自动跳转到wap.baidu.com页面
if (system.win || system.mac || system.xll||system.ipad) {
} else {
window.location.href = "http://www.jdpatro.com/3g/";
}
-->
</script>
腾讯网的适配代码
<script type="text/javascript">
if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){
if(window.location.href.indexOf("?mobile")<0){
try{
if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){
window.location.href="http://shipei.qq.com/index.htm";
}else if(/iPad/i.test(navigator.userAgent)){
}else{
window.location.href="http://shipei.qq.com/simple/s/index/"
}
}catch(e){}
}
}
</script>
<script type="text/javascript">
var browser = {
versions : function() {
var u = navigator.userAgent, app = navigator.appVersion;
return {//移动终端浏览器版本信息
trident : u.indexOf('Trident') > -1, //IE内核
presto : u.indexOf('Presto') > -1, //opera内核
webKit : u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
gecko : u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
mobile : !!u.match(/AppleWebKit.*Mobile.*/)
|| !!u.match(/AppleWebKit/), //是否为移动终端
ios : !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
android : u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
iPhone : u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者QQHD浏览器
iPad: u.indexOf('iPad') > -1, //是否iPad
webApp : u.indexOf('Safari') == -1,//是否web应该程序,没有头部与底部
google:u.indexOf('Chrome')>-1
};
}(),
language : (navigator.browserLanguage || navigator.language).toLowerCase()
}
document.writeln("语言版本: "+browser.language);
document.writeln(" 是否为移动终端: "+browser.versions.mobile);
</script>
如何判断访问网站的机器类型-如何判断ipad
如何判断是否是 iPad 浏览器呢,关键是看它的 User Agent 中是否有 iPad。iPad 使用的是 Safari Mobile 浏览器,他的的 User Agent 是:
Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10
function is_iPad(){
[object Object] [object Object] [object Object]var ua = navigator.userAgent.toLowerCase();
[object Object] [object Object] [object Object]if(ua.match(/iPad/i)=="ipad") {
[object Object] [object Object] [object Object] [object Object] [object Object] [object Object]return true;
[object Object] [object Object] [object Object]} else {
[object Object] [object Object] [object Object] [object Object] [object Object] [object Object]return false;
[object Object] [object Object] [object Object]}
}
$is_iPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad');
RewriteCond %{HTTP_USER_AGENT} ^.*iPad.*$
RewriteRule ^(.*)$ http://ipad.fairyfish.net [R=301]
JS 判断浏览器客户端类型(ipad,iphone,android)
<script type="text/javascript">
var bForcepc
= fGetQuery("dv") == "pc";
function
fBrowserRedirect(){
var sUserAgent = navigator.userAgent.toLowerCase();
var bIsIpad = sUserAgent.match(/ipad/i) ==
"ipad";
var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
var bIsMidp = sUserAgent.match(/midp/i) == "midp";
var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
var bIsAndroid = sUserAgent.match(/android/i) == "android";
var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
var bIsWM = sUserAgent.match(/windows mobile/i) == "windows
mobile";
if(bIsIpad){
var sUrl =
location.href;
if(!bForcepc){
window.location.href = "http://ipad.mail.163.com/";
}
}
if(bIsIphoneOs || bIsAndroid){
var sUrl =
location.href;
if(!bForcepc){
window.location.href = "http://smart.mail.163.com/";
}
}
if(bIsMidp||bIsUc7||bIsUc||bIsCE||bIsWM){
var sUrl =
location.href;
if(!bForcepc){
window.location.href = "http://m.mail.163.com/";
}
}
}
function
fGetQuery(name){//获取参数值
var sUrl = window.location.search.substr(1);
var r = sUrl.match(new RegExp("(^|&)" + name +
"=([^&]*)(&|$)"));
return (r == null ? null : (r[2]));
}
function
fShowVerBlock(){
if(bForcepc){
document.getElementByIdx_x("dv_block").style.display = "block";
}
else{
document.getElementByIdx_x("ad_block").style.display = "block";
}
}
fBrowserRedirect();
</script>
相关文章
- 在很多网站用户先访问一个要登录的页面,但当时没有登录后来登录了,等待用户登录成功之后肯定希望返回到上次访问的页面,下面我就来给大家介绍登录后跳转回原来要访问的页...2016-11-25
- php如何实现抓取网页图片,相较于手动的粘贴复制,使用小程序要方便快捷多了,喜欢编程的人总会喜欢制作一些简单有用的小软件,最近就参考了网上一个php抓取图片代码,封装了一个php远程抓取图片的类,测试了一下,效果还不错分享...2015-10-30
- 本文章完美的利用了php的curl功能实现模拟登录discuz以及模拟发帖,本教程供参考学习哦。 代码如下 复制代码 <?php $discuz_url = ‘ht...2016-11-25
- 批量更新mysql更新语句很简单,更新一条数据的某个字段,一般这样写:复制代码 代码如下:UPDATE mytable SET myfield = 'value' WHERE other_field = 'other_value';如果更新同一字段为同一个值,mysql也很简单,修改下where即...2013-10-04
- 获取网站icon,常用最简单的方法就是通过website/favicon.ico来获取,不过由于很多网站都是在页面里面设置favicon,所以此方法很多情况都不可用。 更好的办法是通过google提供的服务来实现:http://www.google.com/s2/favi...2014-06-07
- EXCEL数据上传到SQL SERVER中的方法需要注意到三点!注意点一:要把EXCEL数据上传到SQL SERVER中必须提前把EXCEL传到服务器上.做法: 在ASP.NET环境中,添加一个FileUpload上传控件后台代码的E.X: 复制代码 代码如下: if...2013-09-23
Ruby on Rails实现最基本的用户注册和登录功能的教程
这里我们主要以has_secure_password的用户密码验证功能为中心,来讲解Ruby on Rails实现最基本的用户注册和登录功能的教程,需要的朋友可以参考下...2020-06-30mac下Apache + MySql + PHP搭建网站开发环境
首先为什不自己分别搭建Apache,PHP和MySql的环境呢?这样自己可以了解更多知识,说起来也更酷。可也许因为我懒吧,我是那种“既然有现成的,用就是了”的人。君子生非异也,善假于物也。两千年前的荀子就教导我们,要善于利用工具...2014-06-07- 什么是SSO?单点登录SSO(Single Sign-On)是身份管理中的一部分。SSO的一种较为通俗的定义是:SSO是指访问同一服务器不同应用中的受保护资源的同一用户,只需要登录一次,即通过一个应用中的安全验证后,再访问其他应用中的受保护...2015-11-08
- 什么是SSO?单点登录SSO(Single Sign-On)是身份管理中的一部分。SSO的一种较为通俗的定义是:SSO是指访问同一服务器不同应用中的受保护资源的同一用户,只需要登录一次,即通过一个应用中的安全验证后,再访问其他应用中的受保护...2015-11-08
- 这篇文章主要为大家详细介绍了vue实现用户登录切换,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-04-22
- 【问题描述】:同一用户在同一时间多次登录如果不能检测出来,是危险的。因为,你无法知道是否有其他用户在登录你的账户。如何禁止同一用户多次登录呢? 【解决方案】 (1) 每次登录,身份认证成功后,重新产生一个session_id。 s...2015-11-24
- 我要实现的就是下图的这种样式,可参考下面这两个网站的留言板,他们的实现原理都是一样的畅言留言板样式:网易跟帖样式:原理 需要在评论表添加两个主要字段 id 和 pid ,其他字段随意添加,比如文章id、回复时间、回复内容、...2015-11-08
- 出现phpmyadmin不能登录是我在修改我mysql服务器密码之后导致的,后来百度了相关的原因,原来是修改了mysql密码之后我们还需要在phpmyadmin目录中去修改config.inc.php中...2016-11-25
网站广告怎么投放最好?首屏广告投放类型优化和广告位布局优化的案例
网站广告怎么投放最好?一个网站中广告位置最好的是哪几个地方呢,许多的朋友都不知道如何让自己的网站广告收效最好了,今天我们就一起来看看吧。 在说到联盟优化前,...2016-10-10- 我们都知道用php+mysql在web 页实现数据库资料全部显示是非常简单而有趣的,数据库资料很少的情况下页面显示还是让人满意的,但是当数据库资料非常多的情况下,页面的显示情况将会变的非常糟糕,下面就来介绍一下如何实现当...2015-11-08
- 由于国内好几个浏览器都是双核浏览器(蛋痛,做一个浏览器壳就说国产,而且使用率高),有时打开网页会出现不兼容模式,在极速模式下是好的,现在我们来用代码实现网页自动调用国内...2016-09-20
- 昨天有一朋友说自己的phpmyadmin不能登录并且无任何提示了,问我怎么解决,下面我来分享一下关于phpmyadmin不能登录问题总结. phpmyadmin不能登录没有提示 解决方法:...2016-11-25
- session在php中是一个非常重要的东西,像我们用户登录一般都使用到session这个东西,相对于cookie来说session 要安全很多,同时我们购物车经常使用session来做临时的记录保存哦。使用session保存页面登录信息1、数据库连接...2015-10-21
- cookie 的用途之一是存储用户在特定网站上的密码和 id。另外,也用于存储起始页的首选项。在提供个人化查看的网站上,将要求阁下的网络浏览器利用阁下计算机硬驱上的少量...2016-11-25