|
 |
|
รบกวนสอบถามเกี่ยวกับการใช้ นำค่าจาก Java Script ไปใช้ต่อใน PHP |
|
 |
|
|
 |
 |
|
รบกวนสอบถามเกี่ยวกับการใช้ นำค่าจาก Java Script ไปใช้ต่อใน PHP
ผมลอง Code ที่เพื่อนๆเผยแพร่ไว้ ในการใช้ Facebook Login แล้วถ้าผมอยากได้ค่าที่ได้เช่น ชื่อ อีเมล์ ไปใช้งานต่อใน php เช่นประกาศ session หรืออื่นๆ พี่ๆมีคำแนะนำยังไงบ้างครับ
Code (PHP)
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>LOG IN</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<link rel='stylesheet prefetch' href='http://fonts.googleapis.com/css?family=Raleway'>
<link rel='stylesheet prefetch' href='http://weloveiconfonts.com/api/?family=fontawesome'>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<br>
<br>
<br>
<br>
<form action="#" id="login-form">
<div class="heading">Login to Application</div>
<center><div class="right">
<br>
<div class="connect">Connect with</div>
<div id="fb-root"></div>
<script src="js/facebook.js"></script>
<div align="center">
<br>
<br>
<div id="status">
<br>
<img src="http://hayageek.com/examples/oauth/facebook/oauth-javascript/LoginWithFacebook.png" style="cursor:pointer;" onClick="Login()"/>
</div>
<br/><br/><br/><br/><br/>
</div>
</div></center>
<br>
</form>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'id', // App ID
channelUrl : 'url', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.Event.subscribe('auth.authResponseChange', function(response)
{
if (response.status === 'connected')
{
document.getElementById("message").innerHTML += "<br>Connected to Facebook";
//SUCCESS
}
else if (response.status === 'not_authorized')
{
document.getElementById("message").innerHTML += "<br>Failed to Connect";
//FAILED
} else
{
document.getElementById("message").innerHTML += "<br>Logged Out";
//UNKNOWN ERROR
}
});
};
function Login()
{
FB.login(function(response) {
if (response.authResponse)
{
getPhoto();
getUserInfo();
} else
{
console.log('User cancelled login or did not fully authorize.');
}
},{scope: 'email'});
}
function getPhoto() {
FB.api('/me/picture?type=normal', function(response) {
var str="<br><center><img src='"+response.data.url+"'/><br></center>";
document.getElementById("status").innerHTML+=str;
});
}
function getUserInfo() {
FB.api('/me?fields=id,name,email', function(response) {
var str="สวัสดีคุณ "+response.name+"<br><br>";
str +="<b>Member Information </b><br><br>";
str +="Facebook Name: "+response.name+"<br>";
str +="id: "+response.id+"<br>";
str +="Email: "+response.email+"<br><br>";
str +="<input type='button' value='Logout' onclick='Logout();'/><br><br";
document.getElementById("status").innerHTML=str;
});
}
function getShowUser() {
getPhoto();
getUserInfo();
}
function Logout()
{
FB.logout(function(){document.location.reload();});
}
// Load the SDK asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
</body>
</html>
Tag : PHP, MySQL, JavaScript

|
|
 |
 |
 |
 |
Date :
2018-09-10 01:21:46 |
By :
ParotZ |
View :
619 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
request ส่งค่าเข้าไปเก็บ ใน server เลยครับ
|
 |
 |
 |
 |
Date :
2018-09-10 03:39:39 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|