Config versnellen
Ik heb mijn config die bij elke pagina geladen wordt...
Het enige probleem is dat de pagina's daardoor heel sloom laden.
Weet iemand wat het probleem is en hoe ik dat kan verhelpen?
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
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
<?php /* ------------------------- */
error_reporting(E_PARSE);
if(!(@mysql_connect("$server","$usernm","$passww") && @mysql_select_db("$database"))) {
echo"<script> location.href = 'wrong.php?s=offline' </script>";
exit;
}
session_start();
if(isset($_SESSION['login'])) {
$dbres = mysql_query("SELECT *,UNIX_TIMESTAMP(`pc`) AS `pc`,UNIX_TIMESTAMP(`transport`) AS `transport`,UNIX_TIMESTAMP(`bc`) AS `bc`,UNIX_TIMESTAMP(`slaap`) AS `slaap`,UNIX_TIMESTAMP(`kc`) AS `kc`,UNIX_TIMESTAMP(`start`) AS `start`,UNIX_TIMESTAMP(`crime`) AS `crime`,UNIX_TIMESTAMP(`ac`) AS `ac` FROM `users` WHERE `login`='{$_SESSION['login']}'");
$data = mysql_fetch_object($dbres);
$huis = $data->stad;
$ip = $_SERVER['REMOTE_ADDR'];
if($data->zak < 0){ mysql_query("UPDATE `users` SET `status`='dood',`schulden`='{$ip}',`adminkill`='1',`reden`='Negatief geld bedrag op zak' WHERE `login`='{$data->login}'"); echo"<script> location.href = 'begin.php' </script>"; }
if($data->bank < 0){ mysql_query("UPDATE `users` SET `status`='dood',`schulden`='{$ip}',`adminkill`='1',`reden`='Negatief geld bedrag op bank' WHERE `login`='{$data->login}'"); echo"<script> location.href = 'begin.php' </script>"; }
include("rangen.php");
include("tijden.php");
include("rangmsg.php");
mysql_query("UPDATE `users` SET `online`=NOW() WHERE `login`='{$data->login}'");
mysql_query("UPDATE `users` SET `status`='dood' WHERE `health` < 1");
mysql_query("UPDATE `users` SET `se`='100' WHERE `se` > 100");
if ($data->status != levend) {
$dood = mysql_query("SELECT * FROM `vermoord` WHERE `login`='{$data->login}'");
$dinfo = mysql_fetch_object($dood);
$kmsg = $dinfo->msg;
$naam = $data->login;
if ($dinfo->msg == NULL) { $kmsg = "<i>Geen</i>";}
session_unset($_SESSION['pass']);
session_unset($_SESSION['login']);
echo"<script> location.href = 'wrong.php?s=dood&r=$kmsg&l=$naam' </script>";
exit;
}
}
$dbre = mysql_query("SELECT *, UNIX_TIMESTAMP(`time`) AS `getime` FROM `jail` WHERE `login`='{$data->login}'");
$jisin = mysql_num_rows($dbre);
$jail = mysql_fetch_object($dbre);
$tim = ($jail->getime - time());
if ($jisin == 1) {
if ($tim == 1) { $time = gmdate('s', $tim); $word = seconde; $boete = $jail->boete; }
elseif ($tim < 61) { $time = gmdate('s', $tim); $word = seconden; $boete = $jail->boete; }
else { $time = gmdate('i:s', $tim); $word = minuten; $boete = $jail->boete; }
}
mysql_query("DELETE FROM `jail` WHERE UNIX_TIMESTAMP(`time`)-UNIX_TIMESTAMP(NOW()) < 0");
$ip = $_SERVER['REMOTE_ADDR'];
$iban = mysql_fetch_object(mysql_query("SELECT * FROM `bans` WHERE `IP`='$ip'"));
$lban = mysql_fetch_object(mysql_query("SELECT * FROM `bans` WHERE `IP`='$ip' OR `login`='{$data->login}'"));
$ban = ($data->login) ? $lban : $iban;
$banreden = $ban->reden;
if ($ban->reden == NULL) { $banreden = "<i>Geen</i>";}
if ($ban) {
session_unset($_SESSION['pass']);
session_unset($_SESSION['login']);
echo"<script> location.href = 'wrong.php?s=verbannen&r=$banreden' </script>";
exit;
}
if ($data->xp < 10) { $jailtime = (TIME() + 20); $boete = 250; }
elseif ($data->xp < 20) { $jailtime = (TIME() + 40); $boete = 500; }
elseif ($data->xp < 50) { $jailtime = (TIME() + 60); $boete = 750; }
elseif ($data->xp < 150) { $jailtime = (TIME() + 90); $boete = 1000; }
elseif ($data->xp < 500) { $jailtime = (TIME() + 120); $boete = 5000; }
elseif ($data->xp < 1000) { $jailtime = (TIME() + 180); $boete = 7500; }
elseif ($data->xp < 2000) { $jailtime = (TIME() + 190); $boete = 12500; }
elseif ($data->xp < 3000) { $jailtime = (TIME() + 230); $boete = 25000; }
elseif ($data->xp < 4500) { $jailtime = (TIME() + 270); $boete = 50000; }
elseif ($data->xp < 6000) { $jailtime = (TIME() + 320); $boete = 60000; }
elseif ($data->xp < 8000) { $jailtime = (TIME() + 370); $boete = 75000; }
elseif ($data->xp < 11000) { $jailtime = (TIME() + 420); $boete = 85000; }
elseif ($data->xp < 15000) { $jailtime = (TIME() + 480); $boete = 100000; }
elseif ($data->xp < 20000) { $jailtime = (TIME() + 540); $boete = 125000; }
elseif ($data->xp < 30000) { $jailtime = (TIME() + 600); $boete = 150000; }
elseif ($data->xp >= 30000) { $jailtime = (TIME() + 650); $boete = 175000; }
if (!$data->famillie) { $famillie = "Geen";
}
else { $famillie = $data->famillie;
}
function check_login() { return TRUE; }
$uur1 = mysql_query("SELECT UNIX_TIMESTAMP(`time`) AS `time`,`name` FROM `tijden` WHERE `name`='uur'");
$uur = mysql_fetch_object($uur1);
if($uur->time - time() < 0) {
$wachtwoorduur = "geheim";
$uurtijd = ($uur->time + 3600);
mysql_query("UPDATE `tijden` SET `time`=FROM_UNIXTIME($uurtijd) WHERE `name`='uur'");
mysql_query("UPDATE `users` SET `energie` = `energie`-1");
include("tijden-uur.php");
}
$dag1 = mysql_query("SELECT UNIX_TIMESTAMP(`time`) AS `time`,`name` FROM `tijden` WHERE `name`='dag'");
$dag = mysql_fetch_object($dag1);
if($dag->time - time() < 0) {
$wachtwoorddag = "geheim";
$dagtijd = ($dag->time + 86400);
mysql_query("UPDATE `tijden` SET `time`=FROM_UNIXTIME($dagtijd) WHERE `name`='dag'");
include("tijden-dag.php");
}
$loterij1 = mysql_query("SELECT UNIX_TIMESTAMP(`time`) AS `time`,`name` FROM `tijden` WHERE `name`='loterij'");
$loterij = mysql_fetch_object($loterij1);
if($loterij->time - time() < 0) {
$wachtwoordloterij = "geheim";
$loterijtijd = ($loterij->time + 259200);
mysql_query("UPDATE `tijden` SET `time`=FROM_UNIXTIME($loterijtijd) WHERE `name`='loterij'");
include("tijden-loterij.php");
}
$week1 = mysql_query("SELECT UNIX_TIMESTAMP(`time`) AS `time`,`name` FROM `tijden` WHERE `name`='week'");
$week = mysql_fetch_object($week1);
if($week->time - time() < 0) {
$wachtwoordweek = "geheim";
$weektijd = ($week->time + 604800);
mysql_query("UPDATE `tijden` SET `time`=FROM_UNIXTIME($weektijd) WHERE `name`='week'");
include("tijden-week.php");
}
/* ------------------------- */
?>
error_reporting(E_PARSE);
if(!(@mysql_connect("$server","$usernm","$passww") && @mysql_select_db("$database"))) {
echo"<script> location.href = 'wrong.php?s=offline' </script>";
exit;
}
session_start();
if(isset($_SESSION['login'])) {
$dbres = mysql_query("SELECT *,UNIX_TIMESTAMP(`pc`) AS `pc`,UNIX_TIMESTAMP(`transport`) AS `transport`,UNIX_TIMESTAMP(`bc`) AS `bc`,UNIX_TIMESTAMP(`slaap`) AS `slaap`,UNIX_TIMESTAMP(`kc`) AS `kc`,UNIX_TIMESTAMP(`start`) AS `start`,UNIX_TIMESTAMP(`crime`) AS `crime`,UNIX_TIMESTAMP(`ac`) AS `ac` FROM `users` WHERE `login`='{$_SESSION['login']}'");
$data = mysql_fetch_object($dbres);
$huis = $data->stad;
$ip = $_SERVER['REMOTE_ADDR'];
if($data->zak < 0){ mysql_query("UPDATE `users` SET `status`='dood',`schulden`='{$ip}',`adminkill`='1',`reden`='Negatief geld bedrag op zak' WHERE `login`='{$data->login}'"); echo"<script> location.href = 'begin.php' </script>"; }
if($data->bank < 0){ mysql_query("UPDATE `users` SET `status`='dood',`schulden`='{$ip}',`adminkill`='1',`reden`='Negatief geld bedrag op bank' WHERE `login`='{$data->login}'"); echo"<script> location.href = 'begin.php' </script>"; }
include("rangen.php");
include("tijden.php");
include("rangmsg.php");
mysql_query("UPDATE `users` SET `online`=NOW() WHERE `login`='{$data->login}'");
mysql_query("UPDATE `users` SET `status`='dood' WHERE `health` < 1");
mysql_query("UPDATE `users` SET `se`='100' WHERE `se` > 100");
if ($data->status != levend) {
$dood = mysql_query("SELECT * FROM `vermoord` WHERE `login`='{$data->login}'");
$dinfo = mysql_fetch_object($dood);
$kmsg = $dinfo->msg;
$naam = $data->login;
if ($dinfo->msg == NULL) { $kmsg = "<i>Geen</i>";}
session_unset($_SESSION['pass']);
session_unset($_SESSION['login']);
echo"<script> location.href = 'wrong.php?s=dood&r=$kmsg&l=$naam' </script>";
exit;
}
}
$dbre = mysql_query("SELECT *, UNIX_TIMESTAMP(`time`) AS `getime` FROM `jail` WHERE `login`='{$data->login}'");
$jisin = mysql_num_rows($dbre);
$jail = mysql_fetch_object($dbre);
$tim = ($jail->getime - time());
if ($jisin == 1) {
if ($tim == 1) { $time = gmdate('s', $tim); $word = seconde; $boete = $jail->boete; }
elseif ($tim < 61) { $time = gmdate('s', $tim); $word = seconden; $boete = $jail->boete; }
else { $time = gmdate('i:s', $tim); $word = minuten; $boete = $jail->boete; }
}
mysql_query("DELETE FROM `jail` WHERE UNIX_TIMESTAMP(`time`)-UNIX_TIMESTAMP(NOW()) < 0");
$ip = $_SERVER['REMOTE_ADDR'];
$iban = mysql_fetch_object(mysql_query("SELECT * FROM `bans` WHERE `IP`='$ip'"));
$lban = mysql_fetch_object(mysql_query("SELECT * FROM `bans` WHERE `IP`='$ip' OR `login`='{$data->login}'"));
$ban = ($data->login) ? $lban : $iban;
$banreden = $ban->reden;
if ($ban->reden == NULL) { $banreden = "<i>Geen</i>";}
if ($ban) {
session_unset($_SESSION['pass']);
session_unset($_SESSION['login']);
echo"<script> location.href = 'wrong.php?s=verbannen&r=$banreden' </script>";
exit;
}
if ($data->xp < 10) { $jailtime = (TIME() + 20); $boete = 250; }
elseif ($data->xp < 20) { $jailtime = (TIME() + 40); $boete = 500; }
elseif ($data->xp < 50) { $jailtime = (TIME() + 60); $boete = 750; }
elseif ($data->xp < 150) { $jailtime = (TIME() + 90); $boete = 1000; }
elseif ($data->xp < 500) { $jailtime = (TIME() + 120); $boete = 5000; }
elseif ($data->xp < 1000) { $jailtime = (TIME() + 180); $boete = 7500; }
elseif ($data->xp < 2000) { $jailtime = (TIME() + 190); $boete = 12500; }
elseif ($data->xp < 3000) { $jailtime = (TIME() + 230); $boete = 25000; }
elseif ($data->xp < 4500) { $jailtime = (TIME() + 270); $boete = 50000; }
elseif ($data->xp < 6000) { $jailtime = (TIME() + 320); $boete = 60000; }
elseif ($data->xp < 8000) { $jailtime = (TIME() + 370); $boete = 75000; }
elseif ($data->xp < 11000) { $jailtime = (TIME() + 420); $boete = 85000; }
elseif ($data->xp < 15000) { $jailtime = (TIME() + 480); $boete = 100000; }
elseif ($data->xp < 20000) { $jailtime = (TIME() + 540); $boete = 125000; }
elseif ($data->xp < 30000) { $jailtime = (TIME() + 600); $boete = 150000; }
elseif ($data->xp >= 30000) { $jailtime = (TIME() + 650); $boete = 175000; }
if (!$data->famillie) { $famillie = "Geen";
}
else { $famillie = $data->famillie;
}
function check_login() { return TRUE; }
$uur1 = mysql_query("SELECT UNIX_TIMESTAMP(`time`) AS `time`,`name` FROM `tijden` WHERE `name`='uur'");
$uur = mysql_fetch_object($uur1);
if($uur->time - time() < 0) {
$wachtwoorduur = "geheim";
$uurtijd = ($uur->time + 3600);
mysql_query("UPDATE `tijden` SET `time`=FROM_UNIXTIME($uurtijd) WHERE `name`='uur'");
mysql_query("UPDATE `users` SET `energie` = `energie`-1");
include("tijden-uur.php");
}
$dag1 = mysql_query("SELECT UNIX_TIMESTAMP(`time`) AS `time`,`name` FROM `tijden` WHERE `name`='dag'");
$dag = mysql_fetch_object($dag1);
if($dag->time - time() < 0) {
$wachtwoorddag = "geheim";
$dagtijd = ($dag->time + 86400);
mysql_query("UPDATE `tijden` SET `time`=FROM_UNIXTIME($dagtijd) WHERE `name`='dag'");
include("tijden-dag.php");
}
$loterij1 = mysql_query("SELECT UNIX_TIMESTAMP(`time`) AS `time`,`name` FROM `tijden` WHERE `name`='loterij'");
$loterij = mysql_fetch_object($loterij1);
if($loterij->time - time() < 0) {
$wachtwoordloterij = "geheim";
$loterijtijd = ($loterij->time + 259200);
mysql_query("UPDATE `tijden` SET `time`=FROM_UNIXTIME($loterijtijd) WHERE `name`='loterij'");
include("tijden-loterij.php");
}
$week1 = mysql_query("SELECT UNIX_TIMESTAMP(`time`) AS `time`,`name` FROM `tijden` WHERE `name`='week'");
$week = mysql_fetch_object($week1);
if($week->time - time() < 0) {
$wachtwoordweek = "geheim";
$weektijd = ($week->time + 604800);
mysql_query("UPDATE `tijden` SET `time`=FROM_UNIXTIME($weektijd) WHERE `name`='week'");
include("tijden-week.php");
}
/* ------------------------- */
?>
Een aantal dingen:
- Waarom gebruik je UNIX_TIMESTAMP als je ook gewoon met data en tijden kunt werken?
- Je controleert nergens of je queries wel gelukt zijn.
- Backtics en accolades horen niet thuis in een query.
- Variabelen hoor je buiten quotes te zetten.
En bovenal, waarom zou je dit script op elke pagina moeten includen?
Tip: Ga de boel herschrijven, maar ga vooral eerst een goed ontwerp maken en de boel logisch opzetten. Bovenstaand script mag echt niet meer dan 0.5 tot 1 seconde tijd kosten en dat is dan eigenlijk al erg langzaam.
-intergers (getallen) moeten niet tussen ' ' (single quotes)
-sommige delen van het script hoef je maar 1x per uur/dag/week/maand uit te voeren, mischien CRON gebruiken?