同步两个 table user_id 并感谢使用 twitter oauth 向用户确认
sync two table user_id and thanks confirmation to user with twitter oauth
所以这是我昨天提出的问题的后续问题,已解决。
但现在我有另一个问题。我一直在尝试从链接的同一数据库中的 2 个不同的 table 获取 user_id,因此当用户验证他们的推特时,它会显示一个内页,上面写着 *你已经链接了你的推特! "username" 所以来自所有页面的 2 table 布局和代码如下:
用户table:这个table用于twitter oauth
ID,user_id,oauth_provider,oauth_uid,用户名,fname,lname,区域设置,oauth_token,oauth_secret,图片、创建、修改
积分table:这个table是积分和youtube的东西,(这个table user_id已经得到我的 phpBB 数据库中的数据来自 phpbb_users table.)
user_id,用户名,yt_channelTitle,积分,user_email,access_token,refresh_token,channel_id,上传,每日投票
twitter oauth functions.php 文件:
function checkUsers($user_id,$oauth_provider,$oauth_uid,$username,$fname,$lname,$locale,$oauth_token,$oauth_secret,$profile_image_url){
$prevQuery = mysqli_query($this->connect,"SELECT * FROM $this->tableName WHERE oauth_provider = '".$oauth_provider."' AND oauth_uid = '".$oauth_uid."'") or die(mysqli_error($this->connect));
if(mysqli_num_rows($prevQuery) > 0){
$update = mysqli_query($this->connect,"UPDATE $this->tableName SET oauth_token = '".$oauth_token."', oauth_secret = '".$oauth_secret."', modified = '".date("Y-m-d H:i:s")."', user_id = '".$user_id."' WHERE oauth_provider = '".$oauth_provider."' AND oauth_uid = '".$oauth_uid."' AND user_id = '".$user_id."' ") or die(mysqli_error($this->connect));
}else{
$insert = mysqli_query($this->connect,"INSERT INTO $this->tableName SET oauth_provider = '".$oauth_provider."', oauth_uid = '".$oauth_uid."', username = '".$username."', fname = '".$fname."', lname = '".$lname."', locale = '".$locale."', oauth_token = '".$oauth_token."', oauth_secret = '".$oauth_secret."', picture = '".$profile_image_url."', created = '".date("Y-m-d H:i:s")."', modified = '".date("Y-m-d H:i:s")."', user_id = '".$user_id."' ") or die(mysqli_error($this->connect));
}
$query = mysqli_query($this->connect,"SELECT * FROM $this->tableName WHERE oauth_provider = '".$oauth_provider."' AND oauth_uid = '".$oauth_uid."'") or die(mysqli_error($this->connect));
$result = mysqli_fetch_array($query);
return $result;
}
twitteroauth process.php 文件:
include_once("../inc/header_session.php");
#$user_id = getUserInfo($id,$user->data['user_id']);
$user_id = intval($user->data['user_id']);
if($connection->http_code == '200' && $user_id != 1)
{
//Redirect user to twitter
$_SESSION['status'] = 'verified';
$_SESSION['request_vars'] = $access_token;
//Insert user into the database
$user_info = $connection->get('account/verify_credentials');
$user_id = $user->data['user_id'];
$name = explode(" ",$user_info->name);
$fname = isset($name[0])?$name[0]:'';
$lname = isset($name[1])?$name[1]:'';
$db_user = new Users();
$db_user->checkUsers($user_info->user_id,'twitter',$user_info->id,$user_info->screen_name,$fname,$lname,$user_info->lang,$access_token['oauth_token'],$access_token['oauth_token_secret'],$user_info->profile_image_url,$user_info);
//Unset no longer needed request tokens
unset($_SESSION['token']);
unset($_SESSION['token_secret']);
header('Location: /twitter.php');
}else{
die("error, try again later!");
}
现在 twitter.php 页面 https://www.tubenations.com/twitter.php
if ($user_login == 1){
echo '<h1 class="icon fa-twitter"> Twitter Page!</h1>';
$user_id = intval($user->data['user_id']);
include "twitter/includes/functions.php";
#$user_info = checkUsers($user_id,$oauth_provider,$oauth_uid,$username,$fname,$lname,$locale,$oauth_token,$oauth_secret,$profile_image_url);
echo $oauth_uid;
if (empty($user_info['oauth_uid'] == 1))
{
echo '
<div class="row">
<div class="8u">
<br />
<div class="twitterInfo2">IMPORTANT ANNOUNCEMENT: We are currently trying to setup a twitter authentication system, so that users have to authenticate their twitter accounts
in order for them to be displayed on this page. So please bear with us! <br /></div>
On this page you can find all of our users Twitter accounts in one useful page, feel free to follow who you like the look off.<br />
We made this page as an extra feature, so it makes it easier to follow people!<br />
<strong>'.$user_info['oauth_uid'].'</strong>
<hr>
<div class="twitterInfo2">In order for you to appear on this page you need to authenticate your twitter account by clicking below! <br /></div>
<a href="/twitter/process.php"><img src="/twitter/images/sign-in-with-twitter.png" width="151" height="24" border="0" /></a>
<hr>
</div>
<div class="4u">
<a class="twitter-timeline" data-dnt="true" href="https://twitter.com/TubeNations" data-widget-id="635542971107143680">Tweets by @TubeNations</a>
</div>
</div>';
}
else
{
echo '
<div class="row">
<div class="8u">
<br />
<div class="twitterInfo2">IMPORTANT ANNOUNCEMENT: We are currently trying to setup a twitter authentication system, so that users have to authenticate their twitter accounts
in order for them to be displayed on this page. So please bear with us! <br /></div>
On this page you can find all of our users Twitter accounts in one useful page, feel free to follow who you like the look off.<br />
We made this page as an extra feature, so it makes it easier to follow people!<br />
<hr>
<div class="twitterInfo2">You have already linked your twitter! <strong>'.$user_info['oauth_uid'].'</strong><br /> </div>
<hr>';
echo getTwitterInfo();
echo ' </div>
<div class="4u">
<a class="twitter-timeline" data-dnt="true" href="https://twitter.com/TubeNations" data-widget-id="635542971107143680">Tweets by @TubeNations</a>
</div>
</div>';
}
echo '</div>';
}
我尝试了很多不同的组合,但都失败了......
如果我遗漏了您需要的更多代码或信息,请告诉我
我设法自己解决了。所以我想我会 post 我自己的答案 :)
所以我基本上使用了来自其他函数的变量,并在下面的 process.php 文件中使用了它。
user->data['user_id']
然后我将我的 user_id 行移动到我的 sql 用户 table 的末尾,我还在末尾添加了所有额外的 SQL 插入functions.php 文件中的每一行
user_id = '".$tn_userid."'
然后为了解决 Twitter 页面的问题,我做了一个函数来从用户那里获取数据 table:
function getUserTwitterInfo($id){
$mysqli = db_connect();
$query = "SELECT * FROM `**HIDDEN**`.`users` WHERE `user_id`= ? ";
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$id = mysqli_real_escape_string($mysqli,$id);
if ($stmt = $mysqli->prepare($query)){
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
while ($myrow = $result->fetch_assoc()) {
$user_info = $myrow;
}
$stmt->close();
}
$mysqli->close();
return $user_info;
然后我刚刚在 Twitter 页面上声明了它:
if ($user_login == 1){
echo '<h1 class="icon fa-twitter"> Twitter Page!</h1>';
#$user_id = intval($user->data['user_id']);
include "twitter/includes/functions.php";
$id = $phpbb_user_id;
$user_info = getUserTwitterInfo($id);
#echo $oauth_uid;
if ($user_info['user_id'] == 0)
{
echo '
现在我很高兴我成功了 :) 有点遗憾我没有得到答案 posted :(
所以这是我昨天提出的问题的后续问题,已解决。
但现在我有另一个问题。我一直在尝试从链接的同一数据库中的 2 个不同的 table 获取 user_id,因此当用户验证他们的推特时,它会显示一个内页,上面写着 *你已经链接了你的推特! "username" 所以来自所有页面的 2 table 布局和代码如下:
用户table:这个table用于twitter oauth
ID,user_id,oauth_provider,oauth_uid,用户名,fname,lname,区域设置,oauth_token,oauth_secret,图片、创建、修改
积分table:这个table是积分和youtube的东西,(这个table user_id已经得到我的 phpBB 数据库中的数据来自 phpbb_users table.)
user_id,用户名,yt_channelTitle,积分,user_email,access_token,refresh_token,channel_id,上传,每日投票
twitter oauth functions.php 文件:
function checkUsers($user_id,$oauth_provider,$oauth_uid,$username,$fname,$lname,$locale,$oauth_token,$oauth_secret,$profile_image_url){
$prevQuery = mysqli_query($this->connect,"SELECT * FROM $this->tableName WHERE oauth_provider = '".$oauth_provider."' AND oauth_uid = '".$oauth_uid."'") or die(mysqli_error($this->connect));
if(mysqli_num_rows($prevQuery) > 0){
$update = mysqli_query($this->connect,"UPDATE $this->tableName SET oauth_token = '".$oauth_token."', oauth_secret = '".$oauth_secret."', modified = '".date("Y-m-d H:i:s")."', user_id = '".$user_id."' WHERE oauth_provider = '".$oauth_provider."' AND oauth_uid = '".$oauth_uid."' AND user_id = '".$user_id."' ") or die(mysqli_error($this->connect));
}else{
$insert = mysqli_query($this->connect,"INSERT INTO $this->tableName SET oauth_provider = '".$oauth_provider."', oauth_uid = '".$oauth_uid."', username = '".$username."', fname = '".$fname."', lname = '".$lname."', locale = '".$locale."', oauth_token = '".$oauth_token."', oauth_secret = '".$oauth_secret."', picture = '".$profile_image_url."', created = '".date("Y-m-d H:i:s")."', modified = '".date("Y-m-d H:i:s")."', user_id = '".$user_id."' ") or die(mysqli_error($this->connect));
}
$query = mysqli_query($this->connect,"SELECT * FROM $this->tableName WHERE oauth_provider = '".$oauth_provider."' AND oauth_uid = '".$oauth_uid."'") or die(mysqli_error($this->connect));
$result = mysqli_fetch_array($query);
return $result;
}
twitteroauth process.php 文件:
include_once("../inc/header_session.php");
#$user_id = getUserInfo($id,$user->data['user_id']);
$user_id = intval($user->data['user_id']);
if($connection->http_code == '200' && $user_id != 1)
{
//Redirect user to twitter
$_SESSION['status'] = 'verified';
$_SESSION['request_vars'] = $access_token;
//Insert user into the database
$user_info = $connection->get('account/verify_credentials');
$user_id = $user->data['user_id'];
$name = explode(" ",$user_info->name);
$fname = isset($name[0])?$name[0]:'';
$lname = isset($name[1])?$name[1]:'';
$db_user = new Users();
$db_user->checkUsers($user_info->user_id,'twitter',$user_info->id,$user_info->screen_name,$fname,$lname,$user_info->lang,$access_token['oauth_token'],$access_token['oauth_token_secret'],$user_info->profile_image_url,$user_info);
//Unset no longer needed request tokens
unset($_SESSION['token']);
unset($_SESSION['token_secret']);
header('Location: /twitter.php');
}else{
die("error, try again later!");
}
现在 twitter.php 页面 https://www.tubenations.com/twitter.php
if ($user_login == 1){
echo '<h1 class="icon fa-twitter"> Twitter Page!</h1>';
$user_id = intval($user->data['user_id']);
include "twitter/includes/functions.php";
#$user_info = checkUsers($user_id,$oauth_provider,$oauth_uid,$username,$fname,$lname,$locale,$oauth_token,$oauth_secret,$profile_image_url);
echo $oauth_uid;
if (empty($user_info['oauth_uid'] == 1))
{
echo '
<div class="row">
<div class="8u">
<br />
<div class="twitterInfo2">IMPORTANT ANNOUNCEMENT: We are currently trying to setup a twitter authentication system, so that users have to authenticate their twitter accounts
in order for them to be displayed on this page. So please bear with us! <br /></div>
On this page you can find all of our users Twitter accounts in one useful page, feel free to follow who you like the look off.<br />
We made this page as an extra feature, so it makes it easier to follow people!<br />
<strong>'.$user_info['oauth_uid'].'</strong>
<hr>
<div class="twitterInfo2">In order for you to appear on this page you need to authenticate your twitter account by clicking below! <br /></div>
<a href="/twitter/process.php"><img src="/twitter/images/sign-in-with-twitter.png" width="151" height="24" border="0" /></a>
<hr>
</div>
<div class="4u">
<a class="twitter-timeline" data-dnt="true" href="https://twitter.com/TubeNations" data-widget-id="635542971107143680">Tweets by @TubeNations</a>
</div>
</div>';
}
else
{
echo '
<div class="row">
<div class="8u">
<br />
<div class="twitterInfo2">IMPORTANT ANNOUNCEMENT: We are currently trying to setup a twitter authentication system, so that users have to authenticate their twitter accounts
in order for them to be displayed on this page. So please bear with us! <br /></div>
On this page you can find all of our users Twitter accounts in one useful page, feel free to follow who you like the look off.<br />
We made this page as an extra feature, so it makes it easier to follow people!<br />
<hr>
<div class="twitterInfo2">You have already linked your twitter! <strong>'.$user_info['oauth_uid'].'</strong><br /> </div>
<hr>';
echo getTwitterInfo();
echo ' </div>
<div class="4u">
<a class="twitter-timeline" data-dnt="true" href="https://twitter.com/TubeNations" data-widget-id="635542971107143680">Tweets by @TubeNations</a>
</div>
</div>';
}
echo '</div>';
}
我尝试了很多不同的组合,但都失败了...... 如果我遗漏了您需要的更多代码或信息,请告诉我
我设法自己解决了。所以我想我会 post 我自己的答案 :)
所以我基本上使用了来自其他函数的变量,并在下面的 process.php 文件中使用了它。
user->data['user_id']
然后我将我的 user_id 行移动到我的 sql 用户 table 的末尾,我还在末尾添加了所有额外的 SQL 插入functions.php 文件中的每一行
user_id = '".$tn_userid."'
然后为了解决 Twitter 页面的问题,我做了一个函数来从用户那里获取数据 table:
function getUserTwitterInfo($id){
$mysqli = db_connect();
$query = "SELECT * FROM `**HIDDEN**`.`users` WHERE `user_id`= ? ";
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$id = mysqli_real_escape_string($mysqli,$id);
if ($stmt = $mysqli->prepare($query)){
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
while ($myrow = $result->fetch_assoc()) {
$user_info = $myrow;
}
$stmt->close();
}
$mysqli->close();
return $user_info;
然后我刚刚在 Twitter 页面上声明了它:
if ($user_login == 1){
echo '<h1 class="icon fa-twitter"> Twitter Page!</h1>';
#$user_id = intval($user->data['user_id']);
include "twitter/includes/functions.php";
$id = $phpbb_user_id;
$user_info = getUserTwitterInfo($id);
#echo $oauth_uid;
if ($user_info['user_id'] == 0)
{
echo '
现在我很高兴我成功了 :) 有点遗憾我没有得到答案 posted :(