html页面代码:
<meta charset="utf-8">
<meta property="wb:webmaster" content="2e1bcfc697808c9f" />
<html xmlns:wb="http://open.weibo.com/wb">
<script src="http://tjs.sjs.sinajs.cn/open/api/js/wb.js?appkey=4116105834&debug=true" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
WB2.anyWhere(function (W) {
W.widget.connectButton({
id: "wb_connect_btn",
type: ‘3,2‘,
callback: {
login: function (o) { //登录后的回调函数
//alert("login: " + o.screen_name) location screen_name id
var ajax = new XMLHttpRequest();
ajax.onreadystatechange=function(){
if (ajax.readyState==4){
//接收数据
alert(ajax.responseText);
//history.go(0);
//document.getElementById("sppwd").innerHTML = ajax.responseText;
}
}
//与服务器建立连接
ajax.open("get","sinaadd.php?oid="+o.id+"&screen_name="+o.screen_name+"&location="+o.location);
//处理请求
ajax.send(null);
},
logout: function () { //退出后的回调函数
alert(‘logout‘);
}
}
});
});
</script>
<div id="wb_connect_btn"></div>
</html>
php页面代码:
<?php
$uid=$_GET[‘oid‘];
$screen_name=$_GET[‘screen_name‘];
$location=$_GET[‘location‘];
$db = new PDO("mysql:host=blog.bwphp.cn;dbname=wangbao","wangbao", "1234",array(PDO::MYSQL_ATTR_INIT_COMMAND => ‘SET NAMES \‘utf8\‘‘));
$db->query("set names utf8");
$addsql = "insert into sina_oauth(uid,screen_name,location) values(‘$uid‘,‘$screen_name‘,‘$location‘)";
$add = $db->exec($addsql);
if($add){
echo "用户信息以成功入库";
}else{
$db->errorInfo();
}
?>
原文地址:http://10182603.blog.51cto.com/10172603/1651529