inlog systeem zonder gebruikerslijst
Het enige probleem is dat ik niet weet hoe je zoiets schrijft
zou iemand bij dit script hieronder zo'n pagina kunnen schrijven?
Alvast bedankt
Groeten gerjan
#######################
### database.sql ###
#######################
CREATE TABLE `maaking_users` (
`userid` int(11) NOT NULL auto_increment,
`username` varchar(10) NOT NULL default '',
`password` varchar(50) NOT NULL default '',
`email` varchar(50) NOT NULL default '',
`fullname` varchar(50) default NULL,
`ipaddress` varchar(50) NOT NULL default '',
`lastlogin` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`userid`)
) TYPE=MyISAM AUTO_INCREMENT=4 ;
#######################
### config.php ###
#######################
//skip the config file if somebody call it from the browser.
if (eregi("config.php", $_SERVER['SCRIPT_NAME'])) {
Header("Location: index.php"); die();
}
//your databse hostname.
$dbhost = "localhost";
//your database username.
$dbuname = "";
//your db password
$dbpass = "";
$dbname = "database_name_here";
//don't change unless you change this value in the db.
$prefix = "maaking";
//change this
$site_name = "maaking.com user login system";
$site_email = "[email protected]";
$site_url = "http://www.maaking.com/";
//added new code to fix compatibility issues.
//09-Nov-2005
$phpver = phpversion();
if ($phpver < '4.1.0') {
$_GET = $HTTP_GET_VARS;
$_POST = $HTTP_POST_VARS;
$_SERVER = $HTTP_SERVER_VARS;
}
if ($phpver >= '4.0.4pl1' && strstr($_SERVER["HTTP_USER_AGENT"],'compatible')) {
if (extension_loaded('zlib')) {
ob_end_clean();
ob_start('ob_gzhandler');
}
} else if ($phpver > '4.0') {
if (strstr($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip')) {
if (extension_loaded('zlib')) {
$do_gzip_compress = TRUE;
ob_start(array('ob_gzhandler',5));
ob_implicit_flush(0);
header('Content-Encoding: gzip');
}
}
}
$phpver = explode(".", $phpver);
$phpver = "$phpver[0]$phpver[1]";
if ($phpver >= 41) {
$PHP_SELF = $_SERVER['PHP_SELF'];
}
if (!ini_get("register_globals")) {
import_request_variables('GPC');
}
include("mysql.class.php");
$db = new sql_db($dbhost, $dbuname, $dbpass, $dbname, false);
if(!$db->db_connect_id) {
include("header.php");
echo "<br><font color=red><h3><br><center>Error:</b><br><hr><br>
<b>Connection to database faild</center>
<br><br><br><br><br><br><br><br><br>";
include("footer.php");
exit();
}
//global function for checkig user is logged in or not.
//you will notice we will use it everwhere in the script.
function is_logged_in($user) {
global $db,$prefix;
if(!is_array($user)) {
$user = explode("|", base64_decode($user));
$uid = "$user[0]";
$pwd = "$user[2]";
} else {
$uid = "$user[0]";
$pwd = "$user[2]";
}
$uid = addslashes($uid);
$uid = intval($uid);
if ($uid != "" AND $pwd != "") {
$result = mysql_query("SELECT password FROM ".$prefix."_users WHERE userid='$uid'");
$row = mysql_fetch_array($result);
$pass = $row['password'];
if($pass == $pwd && $pass != "") {
return 1;
}
}
return 0;
}
?>
#################################
# -----------Users login system------------ #
#################################
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
<?PHP
include ("config.php");
// the Default function.
//note for functions: if you want to include a value of some variables inside the funtions,
//then you have to GLOBAL it first.
function index($user) {
global $db, $prefix;
//check if the user is logged in or not.
if (is_logged_in($user)) {
include("header.php");
//if the user is logged in then read the cookies.
$cookie_read = explode("|", base64_decode($user));
//define variables to hold cookie values.
$userid = $cookie_read[0];
$username = $cookie_read[1];
$password = $cookie_read[2];
$ipaddress = $cookie_read[3];
$lastlogin_date = $cookie_read[4];
$lastlogin_time = $cookie_read[5];
//print wilcome message
echo "Welcome <b>$username</b>, Last login from: [$ipaddress] on [$lastlogin_date @ $lastlogin_time] (<a href=users.php?maa=Logout>Logout</a>)";
echo "<br><br><br><br>";
include("footer.php");
}else{
//if the user is not logged in then show the login form.
// header("Location: users.php?maa=Login"); die();
include("header.php");
login_form();
include("footer.php");
}
}
#########
## login ##
#########
//the login form
function login_form(){
global $username,$user_err,$pass_err,$error_msg;
echo "<center><font class=\"title\">Please enter your username and password to log in.</font></center>\n";
echo "
<center>
<form method=\"POST\" action=\"users.php\" name=\"loginform\">
<table border=\"0\" cellspacing=\"2\" cellpadding=\"4\">
<tr>
<td bgcolor=\"#E2E2E2\">Username: </td>
<td bgcolor=\"#E2E2E2\"><input type=\"text\" name=\"username\" value=\"$username\" size=\"11\"> $user_err</td>
</tr>
<tr>
<td bgcolor=\"#E2E2E2\">Password: </td>
<td bgcolor=\"#E2E2E2\"><input type=\"password\" name=\"password\" size=\"11\"> $pass_err</td>
</tr>
<tr>
<td colspan=2>Remember me for 2 weeks <input type=\"checkbox\" name=\"remember\" value=\"ON\"></td>
</tr>
<tr>
<td> </td>
<td> <input type=\"hidden\" name=\"maa\" value=\"do_login\">
<input type=\"submit\" value=\"Login\"></p>
</td>
</tr>
</table> $error_msg
</form>[ <a href=\"users.php?maa=Register\">Register New!</a> <img src=\"images/register.gif\"> ] [ <a href=\"users.php?maa=Forgot_pwd\">Forgot password?.</a> <img src=\"images/forgot_pwd.gif\"> ]<br><br>";
}
//a login function to call the login form.
function Login(){
include("header.php");
login_form();
include("footer.php");
}
//this function will do the login for you.
function do_login(){
global $prefix,$db,$username,$password, $remember, $user_err,$pass_err,$error_msg,$REMOTE_ADDR;
//prevent some SQL injections.
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
//check username and password fields.
if((!$username) || (!$password)){
include("header.php");
$reqmsg= "(<font class=error>Required!</font>)";
if(trim(empty($username))){
$user_err= $reqmsg;
}
if(empty($password)){
$pass_err= $reqmsg;
}
//$error_msg = "<center><font class=\"error\">Error:</font></center>\n";
login_form();
include("footer.php");
exit();
}
//encyrpt password for more Security
$md5_pass = md5($password);
$sql = mysql_query("SELECT * FROM ".$prefix."_users WHERE username='$username' AND password='$md5_pass'");
$login_check = mysql_num_rows($sql);
///////////////////////////////////////////////////////////////////////
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
$userid = $row['userid'];
$username = $row['username'];
$password = $row['password'];
$ipaddress = $row['ipaddress'];
$lastlogin = explode(" ", $row['lastlogin']);
$lastlogin_date = $lastlogin[0];
$lastlogin_time = $lastlogin[1];
$info = base64_encode("$userid|$username|$password|$ipaddress|$lastlogin_date|$lastlogin_time");
if (isset($remember)){
setcookie("user","$info",time()+1209600);
}else{
setcookie("user","$info",0);
}
mysql_query("UPDATE ".$prefix."_users SET ipaddress='$REMOTE_ADDR', lastlogin=NOW() WHERE userid='$userid'") or die (mysql_error());
echo "Login success please wait..........";
echo "<META HTTP-EQUIV=Refresh CONTENT=\"2; URL=users.php\">";
//header("Location: users.php");
}
}else{
//include("header.php");
$error_msg = "<font class=error>Login error. Please check username/password.</font>";
unset($username);
unset($password);
include("header.php");
login_form();
include("footer.php");
exit();
}
}
##########
## logout ##
#########
function Logout($user) {
$cookie = explode("|", base64_decode($user));
$result = mysql_query("SELECT password FROM ".$prefix."_users WHERE username='$cookie[1]'");
$row = mysql_fetch_array($result);
$pass = $row['password'];
if ($cookie[2] == $pass && $pass != "") {
return $cookie;
} else {
unset($user);
unset($cookie);
}
setcookie("user");
$user = "";
header("Location: users.php");
}
##########
# Register #
#########
function Register(){
include("header.php");
register_form();
include("footer.php");
}
function register_form(){
global $username, $password, $email, $fullname, $user_taken_err, $email_taken_err;
echo "<center><font class=\"title\">Registration form</font></center><br>\n";
echo "<center>Fields marked with a * are required.
<form name=\"RegisterForm\" method=\"POST\" action=\"users.php\" onsubmit='return CheckRegisterForm(RegisterForm)'>
<table align=\"center\" border=\"1\" width=\"400\" id=\"table1\" cellpadding=\"2\" bordercolor=\"#C0C0C0\">
<tr>
<td width=\"100\" align=\"right\">Username:</td>
<td><input type=\"text\" name=\"username\" size=\"18\" value=\"$username\"> * $user_taken_err</td>
</tr>
<tr>
<td align=\"right\">Password:</td>
<td><input type=\"password\" name=\"password\" size=\"18\" value=\"$password\"> *</td>
</tr>
<tr>
<td align=\"right\">Email:</td>
<td><input type=\"text\" name=\"email\" size=\"27\" value=\"$email\"> * $email_taken_err</td>
</tr>
<tr>
<td align=\"right\">Full Name:</td>
<td><input type=\"text\" name=\"fullname\" size=\"27\" value=\"$fullname\"></td>
</tr>
<tr>
<td> </td>
<td> <input type=\"hidden\" name=\"maa\" value=\"do_Register\">
<input type=\"submit\" value=\"Register\"></td>
</tr>
</table></form>";
}
function do_Register(){
global $db, $prefix, $username, $password, $email, $fullname, $user_taken_err, $email_taken_err;
global $site_name, $site_email, $site_url;
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$email = mysql_real_escape_string($_POST['email']);
$fullname = mysql_real_escape_string($_POST['fullname']);
//this function will check fields incase of javascript not working.
if((!$username) || (!$password) || (!$email)){
if(trim(empty($username))){
}
if(empty($password)){
}
if(trim(empty($email))){
}
//print the error message and load the form.
include("header.php");
echo "<center><font class=\"error\">Error:<br>Please fill all fields.</font></center>\n";
register_form();
include("footer.php");
exit();
}
/*--nothing empty? lets do the register-------------------------------------------------------------*/
$sql_email_check = mysql_query("SELECT email FROM ".$prefix."_users WHERE email='$email'");
$sql_username_check = mysql_query("SELECT username FROM ".$prefix."_users WHERE username='$username'");
$email_check = mysql_num_rows($sql_email_check);
$username_check = mysql_num_rows($sql_username_check);
if(($email_check > 0) || ($username_check > 0)){
//define error message for usage in multi plces.
$exist_msg= "<font class=\"error\">(Already Taken!.)</font>";
if($email_check > 0){
$email_taken_err = $exist_msg;
unset($email);
}
if($username_check > 0){
$user_taken_err = $exist_msg;
unset($username);
}
//if the username or email already been taken load the form and print errors.
include("header.php");
register_form();
include("footer.php");
exit();
}
$md5_password = md5($password);
$result = mysql_query("INSERT INTO ".$prefix."_users ( username,password,email,fullname)
VALUES('$username','$md5_password','$email','$fullname')") or die ("Error in registration sql:". mysql_error());
$subject = "Your info at $site_name";
$message = "
Welcome to $site_name
Please keep this email for your records. Your account information is as follows:
----------------------------
Username: $username
Password: $password
----------------------------
Your account is currently active. You can use it by visiting the following link:
$site_url
Please do not forget your password as it has been encrypted in our database and we cannot retrieve it for you. However, should you forget your password you can request a new one which will be sent to your email.
Thank you for registering.
--
- $site_name
$site_url
This email was automatically generated.
Please do not respond to this email or it will ignored.";
if(!mail($email,$subject,$message, "FROM: $site_name <$site_email>")){
die ("Faild sending registration email, please report this to the webmaster ($site_email)");
}else{
include("header.php");
echo "registration was successfull.....!! you can now log in";
login_form();
include("footer.php");
}
}
##############
# Forgot Password #
#############
function Forgot_pwd_form(){
global $error_msg;
echo "<center><font class=\"title\">Send me a new password</font>
<form method='POST' action='users.php'>
<table border='0' cellpadding='4'>
<tr>
<td bgcolor='#E2E2E2'>Username:</td>
<td bgcolor='#E2E2E2'><input type='text' name='username' size='11'></td>
</tr>
<tr>
<td bgcolor='#E2E2E2'>Email:</td>
<td bgcolor='#E2E2E2'><input type='text' name='email' size='11'></td>
</tr>
<tr>
<td> </td>
<td>
<input type='hidden' name='maa' value='do_Forgot_pwd'>
<input type='submit' value='Send password'></p>
</td>
</tr>
</table><center>$error_msg</center>
</form>";
}
function Forgot_pwd(){
global $user, $prefix, $db;
include("header.php");
Forgot_pwd_form();
include("footer.php");
}
function do_Forgot_pwd(){
global $user, $prefix, $db, $email, $username, $error_msg, $site_name ,$site_email, $site_url;
$username = mysql_real_escape_string($_POST['username']);
$email = mysql_real_escape_string($_POST['email']);
$result = mysql_query("SELECT * FROM ".$prefix."_users WHERE username='$username' AND email='$email'");
$check = mysql_num_rows($result);
if($check == 1){
function new_pwd() {
$chars = "abchefghjkmnpqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
$i = 0;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pwd = $pwd . $tmp;
$i++;
}
return $pwd;
}
$new_pwd = new_pwd();
$md5_password = md5($new_pwd);
$sql = mysql_query("UPDATE ".$prefix."_users SET password='$md5_password' WHERE email='$email'");
$subject = "New password";
$message = "
Hello $username,
You are receiving this email because you have (or someone pretending to be you has) requested a new password be sent for your account on $site_name.
Here it is below.
--------------------------
Username: $username
Password: $new_pwd
--------------------------
You may login below:
$site_url
You can of course change this password yourself via the profile page. If you have any difficulties please contact the webmaster.
--
-Thanks
$site_name
This email was automatically generated.
Please do not respond to this email or it will ignored.";
mail($email,$subject,$message, "FROM: $site_name <$site_email>");
include("header.php");
echo "Your New Pass has been emailed to your email.";
echo "<br>please wait...";
include("footer.php");
}else{
include("header.php");
Forgot_pwd_form();
echo "<center><font class=\"error\">Error: Wrong username/email</font></center><br>";
include("footer.php");
}
}
##############################
# a switch for switching between functions #
##############################
switch ($maa){
case "Forgot_pwd":
Forgot_pwd();
break;
case "do_Forgot_pwd":
do_Forgot_pwd();
break;
case "Register":
Register();
break;
case "do_Register":
do_Register();
break;
case "Logout":
Logout($user);
break;
case "Login":
Login();
break;
case "do_login":
do_login();
break;
Default:
index($user);
Break;
}
?>
include ("config.php");
// the Default function.
//note for functions: if you want to include a value of some variables inside the funtions,
//then you have to GLOBAL it first.
function index($user) {
global $db, $prefix;
//check if the user is logged in or not.
if (is_logged_in($user)) {
include("header.php");
//if the user is logged in then read the cookies.
$cookie_read = explode("|", base64_decode($user));
//define variables to hold cookie values.
$userid = $cookie_read[0];
$username = $cookie_read[1];
$password = $cookie_read[2];
$ipaddress = $cookie_read[3];
$lastlogin_date = $cookie_read[4];
$lastlogin_time = $cookie_read[5];
//print wilcome message
echo "Welcome <b>$username</b>, Last login from: [$ipaddress] on [$lastlogin_date @ $lastlogin_time] (<a href=users.php?maa=Logout>Logout</a>)";
echo "<br><br><br><br>";
include("footer.php");
}else{
//if the user is not logged in then show the login form.
// header("Location: users.php?maa=Login"); die();
include("header.php");
login_form();
include("footer.php");
}
}
#########
## login ##
#########
//the login form
function login_form(){
global $username,$user_err,$pass_err,$error_msg;
echo "<center><font class=\"title\">Please enter your username and password to log in.</font></center>\n";
echo "
<center>
<form method=\"POST\" action=\"users.php\" name=\"loginform\">
<table border=\"0\" cellspacing=\"2\" cellpadding=\"4\">
<tr>
<td bgcolor=\"#E2E2E2\">Username: </td>
<td bgcolor=\"#E2E2E2\"><input type=\"text\" name=\"username\" value=\"$username\" size=\"11\"> $user_err</td>
</tr>
<tr>
<td bgcolor=\"#E2E2E2\">Password: </td>
<td bgcolor=\"#E2E2E2\"><input type=\"password\" name=\"password\" size=\"11\"> $pass_err</td>
</tr>
<tr>
<td colspan=2>Remember me for 2 weeks <input type=\"checkbox\" name=\"remember\" value=\"ON\"></td>
</tr>
<tr>
<td> </td>
<td> <input type=\"hidden\" name=\"maa\" value=\"do_login\">
<input type=\"submit\" value=\"Login\"></p>
</td>
</tr>
</table> $error_msg
</form>[ <a href=\"users.php?maa=Register\">Register New!</a> <img src=\"images/register.gif\"> ] [ <a href=\"users.php?maa=Forgot_pwd\">Forgot password?.</a> <img src=\"images/forgot_pwd.gif\"> ]<br><br>";
}
//a login function to call the login form.
function Login(){
include("header.php");
login_form();
include("footer.php");
}
//this function will do the login for you.
function do_login(){
global $prefix,$db,$username,$password, $remember, $user_err,$pass_err,$error_msg,$REMOTE_ADDR;
//prevent some SQL injections.
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
//check username and password fields.
if((!$username) || (!$password)){
include("header.php");
$reqmsg= "(<font class=error>Required!</font>)";
if(trim(empty($username))){
$user_err= $reqmsg;
}
if(empty($password)){
$pass_err= $reqmsg;
}
//$error_msg = "<center><font class=\"error\">Error:</font></center>\n";
login_form();
include("footer.php");
exit();
}
//encyrpt password for more Security
$md5_pass = md5($password);
$sql = mysql_query("SELECT * FROM ".$prefix."_users WHERE username='$username' AND password='$md5_pass'");
$login_check = mysql_num_rows($sql);
///////////////////////////////////////////////////////////////////////
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
$userid = $row['userid'];
$username = $row['username'];
$password = $row['password'];
$ipaddress = $row['ipaddress'];
$lastlogin = explode(" ", $row['lastlogin']);
$lastlogin_date = $lastlogin[0];
$lastlogin_time = $lastlogin[1];
$info = base64_encode("$userid|$username|$password|$ipaddress|$lastlogin_date|$lastlogin_time");
if (isset($remember)){
setcookie("user","$info",time()+1209600);
}else{
setcookie("user","$info",0);
}
mysql_query("UPDATE ".$prefix."_users SET ipaddress='$REMOTE_ADDR', lastlogin=NOW() WHERE userid='$userid'") or die (mysql_error());
echo "Login success please wait..........";
echo "<META HTTP-EQUIV=Refresh CONTENT=\"2; URL=users.php\">";
//header("Location: users.php");
}
}else{
//include("header.php");
$error_msg = "<font class=error>Login error. Please check username/password.</font>";
unset($username);
unset($password);
include("header.php");
login_form();
include("footer.php");
exit();
}
}
##########
## logout ##
#########
function Logout($user) {
$cookie = explode("|", base64_decode($user));
$result = mysql_query("SELECT password FROM ".$prefix."_users WHERE username='$cookie[1]'");
$row = mysql_fetch_array($result);
$pass = $row['password'];
if ($cookie[2] == $pass && $pass != "") {
return $cookie;
} else {
unset($user);
unset($cookie);
}
setcookie("user");
$user = "";
header("Location: users.php");
}
##########
# Register #
#########
function Register(){
include("header.php");
register_form();
include("footer.php");
}
function register_form(){
global $username, $password, $email, $fullname, $user_taken_err, $email_taken_err;
echo "<center><font class=\"title\">Registration form</font></center><br>\n";
echo "<center>Fields marked with a * are required.
<form name=\"RegisterForm\" method=\"POST\" action=\"users.php\" onsubmit='return CheckRegisterForm(RegisterForm)'>
<table align=\"center\" border=\"1\" width=\"400\" id=\"table1\" cellpadding=\"2\" bordercolor=\"#C0C0C0\">
<tr>
<td width=\"100\" align=\"right\">Username:</td>
<td><input type=\"text\" name=\"username\" size=\"18\" value=\"$username\"> * $user_taken_err</td>
</tr>
<tr>
<td align=\"right\">Password:</td>
<td><input type=\"password\" name=\"password\" size=\"18\" value=\"$password\"> *</td>
</tr>
<tr>
<td align=\"right\">Email:</td>
<td><input type=\"text\" name=\"email\" size=\"27\" value=\"$email\"> * $email_taken_err</td>
</tr>
<tr>
<td align=\"right\">Full Name:</td>
<td><input type=\"text\" name=\"fullname\" size=\"27\" value=\"$fullname\"></td>
</tr>
<tr>
<td> </td>
<td> <input type=\"hidden\" name=\"maa\" value=\"do_Register\">
<input type=\"submit\" value=\"Register\"></td>
</tr>
</table></form>";
}
function do_Register(){
global $db, $prefix, $username, $password, $email, $fullname, $user_taken_err, $email_taken_err;
global $site_name, $site_email, $site_url;
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$email = mysql_real_escape_string($_POST['email']);
$fullname = mysql_real_escape_string($_POST['fullname']);
//this function will check fields incase of javascript not working.
if((!$username) || (!$password) || (!$email)){
if(trim(empty($username))){
}
if(empty($password)){
}
if(trim(empty($email))){
}
//print the error message and load the form.
include("header.php");
echo "<center><font class=\"error\">Error:<br>Please fill all fields.</font></center>\n";
register_form();
include("footer.php");
exit();
}
/*--nothing empty? lets do the register-------------------------------------------------------------*/
$sql_email_check = mysql_query("SELECT email FROM ".$prefix."_users WHERE email='$email'");
$sql_username_check = mysql_query("SELECT username FROM ".$prefix."_users WHERE username='$username'");
$email_check = mysql_num_rows($sql_email_check);
$username_check = mysql_num_rows($sql_username_check);
if(($email_check > 0) || ($username_check > 0)){
//define error message for usage in multi plces.
$exist_msg= "<font class=\"error\">(Already Taken!.)</font>";
if($email_check > 0){
$email_taken_err = $exist_msg;
unset($email);
}
if($username_check > 0){
$user_taken_err = $exist_msg;
unset($username);
}
//if the username or email already been taken load the form and print errors.
include("header.php");
register_form();
include("footer.php");
exit();
}
$md5_password = md5($password);
$result = mysql_query("INSERT INTO ".$prefix."_users ( username,password,email,fullname)
VALUES('$username','$md5_password','$email','$fullname')") or die ("Error in registration sql:". mysql_error());
$subject = "Your info at $site_name";
$message = "
Welcome to $site_name
Please keep this email for your records. Your account information is as follows:
----------------------------
Username: $username
Password: $password
----------------------------
Your account is currently active. You can use it by visiting the following link:
$site_url
Please do not forget your password as it has been encrypted in our database and we cannot retrieve it for you. However, should you forget your password you can request a new one which will be sent to your email.
Thank you for registering.
--
- $site_name
$site_url
This email was automatically generated.
Please do not respond to this email or it will ignored.";
if(!mail($email,$subject,$message, "FROM: $site_name <$site_email>")){
die ("Faild sending registration email, please report this to the webmaster ($site_email)");
}else{
include("header.php");
echo "registration was successfull.....!! you can now log in";
login_form();
include("footer.php");
}
}
##############
# Forgot Password #
#############
function Forgot_pwd_form(){
global $error_msg;
echo "<center><font class=\"title\">Send me a new password</font>
<form method='POST' action='users.php'>
<table border='0' cellpadding='4'>
<tr>
<td bgcolor='#E2E2E2'>Username:</td>
<td bgcolor='#E2E2E2'><input type='text' name='username' size='11'></td>
</tr>
<tr>
<td bgcolor='#E2E2E2'>Email:</td>
<td bgcolor='#E2E2E2'><input type='text' name='email' size='11'></td>
</tr>
<tr>
<td> </td>
<td>
<input type='hidden' name='maa' value='do_Forgot_pwd'>
<input type='submit' value='Send password'></p>
</td>
</tr>
</table><center>$error_msg</center>
</form>";
}
function Forgot_pwd(){
global $user, $prefix, $db;
include("header.php");
Forgot_pwd_form();
include("footer.php");
}
function do_Forgot_pwd(){
global $user, $prefix, $db, $email, $username, $error_msg, $site_name ,$site_email, $site_url;
$username = mysql_real_escape_string($_POST['username']);
$email = mysql_real_escape_string($_POST['email']);
$result = mysql_query("SELECT * FROM ".$prefix."_users WHERE username='$username' AND email='$email'");
$check = mysql_num_rows($result);
if($check == 1){
function new_pwd() {
$chars = "abchefghjkmnpqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
$i = 0;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pwd = $pwd . $tmp;
$i++;
}
return $pwd;
}
$new_pwd = new_pwd();
$md5_password = md5($new_pwd);
$sql = mysql_query("UPDATE ".$prefix."_users SET password='$md5_password' WHERE email='$email'");
$subject = "New password";
$message = "
Hello $username,
You are receiving this email because you have (or someone pretending to be you has) requested a new password be sent for your account on $site_name.
Here it is below.
--------------------------
Username: $username
Password: $new_pwd
--------------------------
You may login below:
$site_url
You can of course change this password yourself via the profile page. If you have any difficulties please contact the webmaster.
--
-Thanks
$site_name
This email was automatically generated.
Please do not respond to this email or it will ignored.";
mail($email,$subject,$message, "FROM: $site_name <$site_email>");
include("header.php");
echo "Your New Pass has been emailed to your email.";
echo "<br>please wait...";
include("footer.php");
}else{
include("header.php");
Forgot_pwd_form();
echo "<center><font class=\"error\">Error: Wrong username/email</font></center><br>";
include("footer.php");
}
}
##############################
# a switch for switching between functions #
##############################
switch ($maa){
case "Forgot_pwd":
Forgot_pwd();
break;
case "do_Forgot_pwd":
do_Forgot_pwd();
break;
case "Register":
Register();
break;
case "do_Register":
do_Register();
break;
case "Logout":
Logout($user);
break;
case "Login":
Login();
break;
case "do_login":
do_login();
break;
Default:
index($user);
Break;
}
?>
################
### Javascript.js ###
################
function validateEmail(emailAddress) {
var match = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$/.test(emailAddress);
return match;
}
function CheckRegisterForm(RegisterForm)
{
if (RegisterForm.username.value == "" ) { alert( "Please choose a username!" );
RegisterForm.username.focus();
return false; }
if (RegisterForm.password.value == "" ) { alert( "Please choose a password!" );
RegisterForm.password.focus();
return false; }
if (RegisterForm.email.value == "" ) { alert( "Please enter your email address." );
RegisterForm.email.focus();
return false; }
checkEmail = RegisterForm.email.value
if ((checkEmail.indexOf('@') < 0) || ((checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.')))
{alert("Your emails address is invalid!.");
RegisterForm.email.focus();
return false; }
// return true;
}
function CheckTellForm(tellform)
{
if (tellform.name.value == "" ) { alert( "ÇáÑÌÇÁ ÃÏÎá ÇáÅÓã ÈÇáßÇãá" );
tellform.name.focus();
return false; }
if (tellform.email.value == "" ) { alert( "ÃÏÎá ÇáÈÑíÏ ÇáÅáßÊÑæäí" );
tellform.email.focus();
return false; }
checkEmail = tellform.email.value
if ((checkEmail.indexOf('@') < 0) || ((checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.')))
{alert("ÇáÈÑíÏ ÇáÅáßÊÑæäí ÎØÃ!.");
tellform.email.focus();
return false; }
if (tellform.fname.value == "" ) { alert( "ÃÏÎá ÅÓã ÕÏíÞß" );
tellform.fname.focus();
return false; }
if (tellform.femail.value == "" ) { alert( "ÃÏÎá ÇáÈÑíÏ ÇáÇáßÊÑæäí ÇáÎÇÕ ÈÕÏíÞß" );
tellform.femail.focus();
return false; }
checkEmail = tellform.femail.value
if ((checkEmail.indexOf('@') < 0) || ((checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.')))
{alert("ÇáÈÑíÏ ÇáÅáßÊÑæäí ÎØÃ!.");
tellform.femail.focus();
return false; }
// return true;
}
var newwindow;
function pop(url)
{
newwindow=window.open(url,'poppage', 'toolbars=0, scrollbars=1, location=0, statusbars=1, menubars=0, resizable=0, width=500, height=400');
if (window.focus) {newwindow.focus()}
}
function popimg(url)
{
newwindow=window.open(url,'name','height=500,width=650,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,status=yes');
if (window.focus) {newwindow.focus()}
}
<!-- ;
var newwindow;
var wheight = 0, wwidth = 0;
function viewimg(url, title, iwidth, iheight, colour) {
var pwidth, pheight;
if ( !newwindow || newwindow.closed ) {
pwidth=iwidth+30;
pheight=iheight+30;
newwindow=window.open('','htmlname','width=' + pwidth +',height=' +pheight + ',resizable=1,top=50,left=10');
wheight=iheight;
wwidth=iwidth;
}
if (wheight!=iheight || wwidth!=iwidth ) {
pwidth=iwidth+30;
pheight=iheight+60;
newwindow.resizeTo(pwidth, pheight);
wheight=iheight;
wwidth=iwidth;
}
newwindow.document.clear();
newwindow.focus();
newwindow.document.writeln('<html> <head> <title>' + title + '<\/title> <\/head> <body bgcolor= \"' + colour + '\"> <center>');
newwindow.document.writeln('<a titl="ÅÖÛØ ÇáÕæÑÉ ááÅÛáÇÞ" href="javascript:window.close();"><img src=' + url + ' border=0></a>');
newwindow.document.writeln('<\/center> <\/body> <\/html>');
newwindow.document.close();
newwindow.focus();
}
// Routines to tidy up popup windows when page is left
// Call with an onUnload="tidy5()" in body tag
function tidy5() {
if (newwindow && !newwindow.closed) { newwindow.close(); }
}
#########
## Einde ##
########
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
$query = "SELECT * FROM maaking_users ORDER BY username ASC";
$resultaat = mysql_query($query) or die(mysql_error());
$aantal = mysql_num_rows($resultaat);
if($aantal >= 1)
{
while($rij = mysql_fetch_array($resultaat))
{
$naam = stripslashes($rij['username']);
$id = stripslashes($rij['userid']);
//echoén
}
}
?>
$query = "SELECT * FROM maaking_users ORDER BY username ASC";
$resultaat = mysql_query($query) or die(mysql_error());
$aantal = mysql_num_rows($resultaat);
if($aantal >= 1)
{
while($rij = mysql_fetch_array($resultaat))
{
$naam = stripslashes($rij['username']);
$id = stripslashes($rij['userid']);
//echoén
}
}
?>
Gewijzigd op 19/01/2006 15:09:00 door Arjan Kapteijn
Zoek eens op gegevens uit datbase halen.
Warning: mysql_query(): Access denied for user: '******@localhost' (Using password: NO)
Warning: mysql_query(): A link to the server could not be established
Access denied for user: '******@localhost' (Using password: NO)
Het is natuurlijk wel handig om eerst een verbinding te maken met de database...
Sorry ben niet zo bekend met php
mysql_connect();, maar in jou systeem zit al een OOP oplossing verwerkt.
Normaal met ik snap er nog helemaal niks van? :S:S:S:S
ik vind het nog niet echt duidelijk
zo werkt het dus niet. Spijk eerst je kennis es op van PHP en SQL, connection maken is stap 1
Code (php)
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
<?php
$dbserver = '';
$dbgebruiker = '';
$dbwachtwoord = '';
$dbtabel = '';
mysql_connect($dbserver, $dbgebruiker, $dbwachtwoord) or die('Kan geen verbinding maken met de database server.<br>');
mysql_select_db($dbtabel) or die('Kan geen verbinding maken met de database tabel.<br>');
?>
$dbserver = '';
$dbgebruiker = '';
$dbwachtwoord = '';
$dbtabel = '';
mysql_connect($dbserver, $dbgebruiker, $dbwachtwoord) or die('Kan geen verbinding maken met de database server.<br>');
mysql_select_db($dbtabel) or die('Kan geen verbinding maken met de database tabel.<br>');
?>
ben hier gekomen om php te kunnen leren, met soms wat hulp van andere. zoals hier
heb al wel wat dingen gemaakt met php maar ik kom helaas nog niet overal uit
dit is toevallig 1 van die dingen
ik vind het best als je me niet wilt helpen, maar zeg dan niks over wat ik wel en niet moet doen
lijkt me duidelijk
Hulp is komen met een niet werkend voorbeeld... nu plemp je een enorm script neer, waarvan alleen de eerste 10 regels van belang zijn en vervolgens verwacht je dat er een antwoord uit komt rollen...
Geef ik je een werkend voorbeeld (had ook kunnen zeggen 'ophalen en echoén) en is het nog niet goed...
En ja dit is phpHULP, dus wat we doen is helpen... maar jij vraagt niet om hulp! Ik geef een link naar de handleiding met duidelijke voorbeelden en dan is het nog niet goed!
Kijk eens bij jezelf, ipv bij ons. En de volgende keer niet meer tegen 'ons' uitvallen en oppassen wat je zegt.
Dank je wel Arjan
als je eerst een basis cursus php neemt hoe een variabel werkt, echo dan ben je al wat verder. Zijn er genoeg op internet te vinden.
Hulp geven doen we hier ook , maar als je niet eens de moeite neemt om je een beetje in te lezen in de basis , hoeft het van mij persoonlijk niet.
Een script downloaden , hierop gooien en maar verwachten dat wij het allemaal voor je regelen is niet de bedoeling.
Ik wil je best helpen maar als je al niet weet wat een connection met een database inhoudt, en je dan zo reageerd van nou ik snap het niet en ik wil het niet snappen want jullie weten het al, mja dan ist jammer voor je
---
[/rant]
wes:
[rant]
Hulp geven doen we hier ook , maar als je niet eens de moeite neemt om je een beetje in te lezen in de basis , hoeft het van mij persoonlijk niet.
Een script downloaden , hierop gooien en maar verwachten dat wij het allemaal voor je regelen is niet de bedoeling.
Ik wil je best helpen maar als je al niet weet wat een connection met een database inhoudt, en je dan zo reageerd van nou ik snap het niet en ik wil het niet snappen want jullie weten het al, mja dan ist jammer voor je
---
[/rant]
Hulp geven doen we hier ook , maar als je niet eens de moeite neemt om je een beetje in te lezen in de basis , hoeft het van mij persoonlijk niet.
Een script downloaden , hierop gooien en maar verwachten dat wij het allemaal voor je regelen is niet de bedoeling.
Ik wil je best helpen maar als je al niet weet wat een connection met een database inhoudt, en je dan zo reageerd van nou ik snap het niet en ik wil het niet snappen want jullie weten het al, mja dan ist jammer voor je
---
[/rant]
Aangezien ik er ook niets over weet, DB, connection, Mysqurrelr, etc. begin ik er ook niet over. Lijkt me voortaan een goeie en ook een aanradertje voor de rest. Ik houd het bij PHP basic en easy scripting. Tot nu toe al erg veel gehad aan enkel PHP-koning hier.
--
als je een taart wil bakken kijk je toch eerst zelf waar alles ligt en hoe het moet
mijn verontschuldigingen, ik zeg soms eerst dingen, voordat ik er bij nadenk. kan er soms niks aan doen