Inloggen met google op eigensite
Gelukkig nieuwjaar!!!
Ik heb een probleem bij het schrijven van een systeem waarmee je kan registreren en inloggen met Google.
Ik heb van de site http://www.a2zwebhelp.com/login-with-google een code gevonden die ik nu gebruik alleen Google zecht: "Fout:invalid_request. Error in parsing the OpenID auth request."
Wat is er fout?
hier onder ziet je de code:
login-google.php:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
include('connection.php');
if($_POST['register']){
$fname = mysql_real_escape_string($_POST['fname']);
$lname = mysql_real_escape_string($_POST['lname']);
$email = mysql_real_escape_string($_POST['email']);
$passcode = mysql_real_escape_string($_POST['passcode']);
$loginwith = mysql_real_escape_string($_POST['loginwith']);
$status = 'active';
$mysql = mysql_query("insert into register set fastname = '".$fname."',
lastname = '".$lname."',
email = '".$email."',
passcode = '".$passcode."',
loginwith = '".$loginwith."',
status = '".$status."'");
header('Location:myaccount.php');
}
/* Login With Google */
require_once 'google/openid.php';
$googleid = new LightOpenID("localhost");
$googleid->identity = 'https://www.google.com/accounts/o8/id';
$googleid->required = array(
'namePerson/first',
'namePerson/last',
'contact/email',
);
$googleid->returnUrl = 'localhost/login-google.php';
if ($googleid->mode == 'cancel') {
echo "User has canceled authentication !";
} elseif($googleid->validate()) {
$data = $googleid->getAttributes();
$email = $data['contact/email'];
$firstname = $data['namePerson/first'];
$lastname = $data['namePerson/last'];
$Identity = explode("=",$googleid->identity);
$userid = $Identity[1];
$loginwith = 'Google';
$sql = mysql_query("select userid from register where passcode='".$userid."'");
$numrow = mysql_num_rows($sql);
if($numrow > 0){
header('Location:myaccount.php');
exit();
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Login With Google</title>
<meta http-equiv="content-type" content="text/html;charset=UTF-8">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="content">
<div class="login_left">
<span class="linkedin"><a href="<?php echo $googleid->authUrl() ?>"><img border="0" src="images/login_with_google.png" width="273" height="60"></a> </span><br/>
</div>
<form method="POST" action="?register=true">
<div class="login_right">
<label>First Name</label> <span class="txtbox"> <input type="text" name="fname" class="input_box" placeholder="Enter First Name" autocomplete="off" required value="<?php print $firstname; ?>"> </span>
<label>Last Name</label> <span class="txtbox"> <input type="text" name="lname" class="input_box" placeholder="Enter Last Name" autocomplete="off" required value="<?php print $lastname; ?>"> </span>
<label>Email</label> <span class="txtbox"> <input type="email" name="email" class="input_box" placeholder="Enter Email Address" autocomplete="off" value="<?php print $email; ?>"></span>
<?php if($loginwith ==""){ ?>
<label>Password</label> <span class="txtbox"> <input type="password" name="password" class="input_box" placeholder="Enter Password" required></span>
<?php } ?>
<input type="hidden" name="passcode" value="<?php print $userid; ?>"></span>
<input type="hidden" name="loginwith" value="<?php print $loginwith?>"></span>
<div class="submit_box"><input type="submit" value="Submit" name="register"> </div>
<div>
</form>
</div>
</body>
</html>
include('connection.php');
if($_POST['register']){
$fname = mysql_real_escape_string($_POST['fname']);
$lname = mysql_real_escape_string($_POST['lname']);
$email = mysql_real_escape_string($_POST['email']);
$passcode = mysql_real_escape_string($_POST['passcode']);
$loginwith = mysql_real_escape_string($_POST['loginwith']);
$status = 'active';
$mysql = mysql_query("insert into register set fastname = '".$fname."',
lastname = '".$lname."',
email = '".$email."',
passcode = '".$passcode."',
loginwith = '".$loginwith."',
status = '".$status."'");
header('Location:myaccount.php');
}
/* Login With Google */
require_once 'google/openid.php';
$googleid = new LightOpenID("localhost");
$googleid->identity = 'https://www.google.com/accounts/o8/id';
$googleid->required = array(
'namePerson/first',
'namePerson/last',
'contact/email',
);
$googleid->returnUrl = 'localhost/login-google.php';
if ($googleid->mode == 'cancel') {
echo "User has canceled authentication !";
} elseif($googleid->validate()) {
$data = $googleid->getAttributes();
$email = $data['contact/email'];
$firstname = $data['namePerson/first'];
$lastname = $data['namePerson/last'];
$Identity = explode("=",$googleid->identity);
$userid = $Identity[1];
$loginwith = 'Google';
$sql = mysql_query("select userid from register where passcode='".$userid."'");
$numrow = mysql_num_rows($sql);
if($numrow > 0){
header('Location:myaccount.php');
exit();
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Login With Google</title>
<meta http-equiv="content-type" content="text/html;charset=UTF-8">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="content">
<div class="login_left">
<span class="linkedin"><a href="<?php echo $googleid->authUrl() ?>"><img border="0" src="images/login_with_google.png" width="273" height="60"></a> </span><br/>
</div>
<form method="POST" action="?register=true">
<div class="login_right">
<label>First Name</label> <span class="txtbox"> <input type="text" name="fname" class="input_box" placeholder="Enter First Name" autocomplete="off" required value="<?php print $firstname; ?>"> </span>
<label>Last Name</label> <span class="txtbox"> <input type="text" name="lname" class="input_box" placeholder="Enter Last Name" autocomplete="off" required value="<?php print $lastname; ?>"> </span>
<label>Email</label> <span class="txtbox"> <input type="email" name="email" class="input_box" placeholder="Enter Email Address" autocomplete="off" value="<?php print $email; ?>"></span>
<?php if($loginwith ==""){ ?>
<label>Password</label> <span class="txtbox"> <input type="password" name="password" class="input_box" placeholder="Enter Password" required></span>
<?php } ?>
<input type="hidden" name="passcode" value="<?php print $userid; ?>"></span>
<input type="hidden" name="loginwith" value="<?php print $loginwith?>"></span>
<div class="submit_box"><input type="submit" value="Submit" name="register"> </div>
<div>
</form>
</div>
</body>
</html>
Toevoeging op 01/01/2014 14:36:17:
Weet iemand iets?
Gewijzigd op 01/01/2014 13:05:59 door Patrick vollenbroek
.
Weet iemand iets?