probleem met cookies inlog systeem
Ik ben bezig met een inlog scriptje, het werkt allemaal, behalve de cookies. Als ik de cookies niet aanvink krijg je een error undefined index cookie on line 53??! als ik hem aanvink krijg ik geen error, er komt wel een gecodeerd wachtwoord in de database te staan, maar het werkt niet!!!
hier is het scriptje:
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
include("htmltop.php");
include_once("connect.php");
if(isset($_SESSION['user_id'])) {
header("Location: stats.php");
}else{
if(isset($_COOKIE['user_id'])) {
// Read cookie, make session
$sql = "SELECT id,admin,password,active FROM `account` WHERE id='".$_COOKIE['user_id']."'";
$query = mysql_query($sql);
$row = mysql_fetch_object($query);
$id = htmlspecialchars($row->id);
$status = htmlspecialchars($row->admin);
$dbpass = htmlspecialchars($row->password);
$actief = htmlspecialchars($row->active);
if($dbpass == $_COOKIE['user_password'] AND $actief == 1) {
$_SESSION['user_id'] = $id;
$_SESSION['user_status'] = $status;
?>
<script language="Javascript" type="text/javascript">
window.location="http://www.mysite.nl/stats.php";
</script>
<?
}else{
echo "de cookie is niet correct.";
setcookie("user_id", "", time() - 3600);
setcookie("user_password", "", time() - 3600);
}
}
else{
if(isset($_POST['submit'])) {
// Login
$sql = "SELECT id,username,password,admin,active,cookie_pass FROM `account` WHERE username='".$_POST['username']."'";
$query = mysql_query($sql);
$count = mysql_num_rows($query);
if($count == 1) {
$row = mysql_fetch_object($query);
$dbpass = htmlspecialchars($row->password);
$userpass = md5($_POST['password']);
$cookiepass = htmlspecialchars($row->cookie_pass);
$userid = htmlspecialchars($row->id);
$userstatus = htmlspecialchars($row->admin);
$useractief = htmlspecialchars($row->active);
if($dbpass == $userpass) {
if($useractief == 1) {
$_SESSION['user_id'] = $userid;
$_SESSION['user_status'] = $userstatus;
if($_POST['cookie'] == "do") {
if($cookiepass == "") {
$cookiecode = mt_srand((double)microtime()*100000);
while(strlen($cookiecode) <= 10) {
$i = chr(mt_rand (0,255));
if(eregi("^[a-z0-9]$", $i)) {
$cookiecode = $cookiecode.$i;
}
}
$sql = "UPDATE `account` SET cookie_pass = '".$cookiecode."' WHERE username = '".$_POST['username']."' LIMIT 1";
mysql_query($sql);
$cookiepass = $cookiecode;
}
setcookie("cookie_id", $userid, time() + 365 * 86400);
setcookie("cookie_pass", $cookiepass, time() + 365 * 86400);
}
echo "U bent succesvol aangemeld, u wordt nu doorgelinkt. Gebeurt er niets? klik dan <a href='stats.php'>hier</a>.";
?>
<script language="Javascript" type="text/javascript">
window.location="http://www.mysite.nl/stats.php";
</script>
<?
}else{
echo "Uw account is nog niet geactiveerd, check uw mailbox voor de activatielink.";
}
}else{
echo "Uw ingevulde wachtwoord klopt niet";
}
}else{
echo "uw ingevulde gebruikersnaam klopt niet";
}
}
else{
?>
<form method="post" action="login.php">
<table width=95% border=0 align=center cellpadding=0 cellspacing=0>
<tr valign=top>
<td width=5%>
<IMG src="images/mysite.jpg" width="189" height="94">
</td>
<td width=95% valign=top>
<table width=100% cellpadding=1>
<tr>
<td><div> </div></td>
</tr>
<tr>
<table width=100% align=center cellpadding=0 cellspacing=0 bgcolor=#C3D9FF>
<tr><td>
<div id="bar">
welkom op mysite!
</div>
</td>
</tr>
</table>
<table>
<tr>
<td id="text">
menu 1 | menu 2
</td>
</tr>
</table>
</tr>
</table>
</td>
</tr>
</table>
<table width=94% align=center cellpadding=5 cellspacing=1>
<tr>
<td id="text" width=75% valign=top>
intro
</td>
<td valign=top>
<div class="Login">
<div class="title">Aanmelden</div>
<div style="padding-top: 20px;">
<table width="100%" border="0" cellspacing="0" cellpading="2"><tr>
<td align="right">Gebruikersnaam</td>
<td><label for="username">
<input id="username" name="username" class="field" maxlength=256>
</td>
</tr><tr>
<td align="right">Wachtwoord</td>
<td><label for="password">
<input id="password" name="password" type="password" class="field" maxlength=256>
</td>
</tr><tr>
<td> </td>
<td><input class="submit" type="submit" name="submit" value="Aanmelden" /><br><br></td>
</tr>
<tr>
<td colspan="2" class="box"><input id="cookie" type="checkbox" name="cookie" value="do" />Onthoud mijn gegegevens</td>
</tr>
<tr><td colspan="2" class="box"><a href="forgotpass.php">Ik ben mijn wachtwoord vergeten</a></td></tr>
</table>
</div>
</div>
</td>
</tr>
</table>
<br>
<table width=95% align=center>
<tr>
<td>
<div align=center id="bar">
copyright@2009 mysite
</div>
</td>
</tr>
</table>
</form>
<?
}
}
}
include("htmlbottom.php");
?>
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
include("htmltop.php");
include_once("connect.php");
if(isset($_SESSION['user_id'])) {
header("Location: stats.php");
}else{
if(isset($_COOKIE['user_id'])) {
// Read cookie, make session
$sql = "SELECT id,admin,password,active FROM `account` WHERE id='".$_COOKIE['user_id']."'";
$query = mysql_query($sql);
$row = mysql_fetch_object($query);
$id = htmlspecialchars($row->id);
$status = htmlspecialchars($row->admin);
$dbpass = htmlspecialchars($row->password);
$actief = htmlspecialchars($row->active);
if($dbpass == $_COOKIE['user_password'] AND $actief == 1) {
$_SESSION['user_id'] = $id;
$_SESSION['user_status'] = $status;
?>
<script language="Javascript" type="text/javascript">
window.location="http://www.mysite.nl/stats.php";
</script>
<?
}else{
echo "de cookie is niet correct.";
setcookie("user_id", "", time() - 3600);
setcookie("user_password", "", time() - 3600);
}
}
else{
if(isset($_POST['submit'])) {
// Login
$sql = "SELECT id,username,password,admin,active,cookie_pass FROM `account` WHERE username='".$_POST['username']."'";
$query = mysql_query($sql);
$count = mysql_num_rows($query);
if($count == 1) {
$row = mysql_fetch_object($query);
$dbpass = htmlspecialchars($row->password);
$userpass = md5($_POST['password']);
$cookiepass = htmlspecialchars($row->cookie_pass);
$userid = htmlspecialchars($row->id);
$userstatus = htmlspecialchars($row->admin);
$useractief = htmlspecialchars($row->active);
if($dbpass == $userpass) {
if($useractief == 1) {
$_SESSION['user_id'] = $userid;
$_SESSION['user_status'] = $userstatus;
if($_POST['cookie'] == "do") {
if($cookiepass == "") {
$cookiecode = mt_srand((double)microtime()*100000);
while(strlen($cookiecode) <= 10) {
$i = chr(mt_rand (0,255));
if(eregi("^[a-z0-9]$", $i)) {
$cookiecode = $cookiecode.$i;
}
}
$sql = "UPDATE `account` SET cookie_pass = '".$cookiecode."' WHERE username = '".$_POST['username']."' LIMIT 1";
mysql_query($sql);
$cookiepass = $cookiecode;
}
setcookie("cookie_id", $userid, time() + 365 * 86400);
setcookie("cookie_pass", $cookiepass, time() + 365 * 86400);
}
echo "U bent succesvol aangemeld, u wordt nu doorgelinkt. Gebeurt er niets? klik dan <a href='stats.php'>hier</a>.";
?>
<script language="Javascript" type="text/javascript">
window.location="http://www.mysite.nl/stats.php";
</script>
<?
}else{
echo "Uw account is nog niet geactiveerd, check uw mailbox voor de activatielink.";
}
}else{
echo "Uw ingevulde wachtwoord klopt niet";
}
}else{
echo "uw ingevulde gebruikersnaam klopt niet";
}
}
else{
?>
<form method="post" action="login.php">
<table width=95% border=0 align=center cellpadding=0 cellspacing=0>
<tr valign=top>
<td width=5%>
<IMG src="images/mysite.jpg" width="189" height="94">
</td>
<td width=95% valign=top>
<table width=100% cellpadding=1>
<tr>
<td><div> </div></td>
</tr>
<tr>
<table width=100% align=center cellpadding=0 cellspacing=0 bgcolor=#C3D9FF>
<tr><td>
<div id="bar">
welkom op mysite!
</div>
</td>
</tr>
</table>
<table>
<tr>
<td id="text">
menu 1 | menu 2
</td>
</tr>
</table>
</tr>
</table>
</td>
</tr>
</table>
<table width=94% align=center cellpadding=5 cellspacing=1>
<tr>
<td id="text" width=75% valign=top>
intro
</td>
<td valign=top>
<div class="Login">
<div class="title">Aanmelden</div>
<div style="padding-top: 20px;">
<table width="100%" border="0" cellspacing="0" cellpading="2"><tr>
<td align="right">Gebruikersnaam</td>
<td><label for="username">
<input id="username" name="username" class="field" maxlength=256>
</td>
</tr><tr>
<td align="right">Wachtwoord</td>
<td><label for="password">
<input id="password" name="password" type="password" class="field" maxlength=256>
</td>
</tr><tr>
<td> </td>
<td><input class="submit" type="submit" name="submit" value="Aanmelden" /><br><br></td>
</tr>
<tr>
<td colspan="2" class="box"><input id="cookie" type="checkbox" name="cookie" value="do" />Onthoud mijn gegegevens</td>
</tr>
<tr><td colspan="2" class="box"><a href="forgotpass.php">Ik ben mijn wachtwoord vergeten</a></td></tr>
</table>
</div>
</div>
</td>
</tr>
</table>
<br>
<table width=95% align=center>
<tr>
<td>
<div align=center id="bar">
copyright@2009 mysite
</div>
</td>
</tr>
</table>
</form>
<?
}
}
}
include("htmlbottom.php");
?>
alvast bedankt!
Gewijzigd op 01/01/1970 01:00:00 door Wouter bakker
Gewijzigd op 01/01/1970 01:00:00 door wouter bakker
Je script in je post is nu niet echt leesbaar. Pas je post even aan en gebruik en tags om je code heen. Om php code zet je uiteraard dit:Gebruik je knop om dit te doen.
SanThe.
Gewijzigd op 01/01/1970 01:00:00 door - SanThe -
zie 1e bericht
Wil iemand misschien ook de mysql gegevens (zelf uitproberen)???
3x posten achter elkaar? Gebruik de edit knop om je post te wijzigen.