Menu laat niet goed na inloggen
Deze controleerd het login form
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
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
<?php
$host="localhost"; // Host name
$username="admin"; // Mysql username
$password="//"; // Mysql password
$db_name="//"; // Database name
$tbl_name="//"; // Table name
mysql_connect("$host", "$username", "$password");
mysql_select_db("$db_name");
// username and password sent from form
$username=$_POST['username'];
$password=$_POST['password'];
// To protect MySQL injection (more detail about MySQL injection)
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$sql="SELECT * FROM $tbl_name WHERE Username ='$username' AND Password='$password'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $email and $password, table row must be 1 row
if($count==1){
// Register $email, $password and redirect to file "login_success.php"
session_start();
session_register("user");
session_register("mypassword");
echo 'U bent ingelogd';
}
else {
echo "Wrong Username or Password";
}
?>
$host="localhost"; // Host name
$username="admin"; // Mysql username
$password="//"; // Mysql password
$db_name="//"; // Database name
$tbl_name="//"; // Table name
mysql_connect("$host", "$username", "$password");
mysql_select_db("$db_name");
// username and password sent from form
$username=$_POST['username'];
$password=$_POST['password'];
// To protect MySQL injection (more detail about MySQL injection)
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$sql="SELECT * FROM $tbl_name WHERE Username ='$username' AND Password='$password'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $email and $password, table row must be 1 row
if($count==1){
// Register $email, $password and redirect to file "login_success.php"
session_start();
session_register("user");
session_register("mypassword");
echo 'U bent ingelogd';
}
else {
echo "Wrong Username or Password";
}
?>
En dit is het menu
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
if(!session_is_registered(user)){
print ' <li id="current"><a href="/">Home</a></li>
<li><a href="/login.php">Login</a></li>
<li><a href="about.php">over</a></li>
';
} else {
print ' <li id="current"><a href="/">Home</a></li>
<li id="current"><a href="/logout.php">Afmelden</a></li> ';
}
?>
if(!session_is_registered(user)){
print ' <li id="current"><a href="/">Home</a></li>
<li><a href="/login.php">Login</a></li>
<li><a href="about.php">over</a></li>
';
} else {
print ' <li id="current"><a href="/">Home</a></li>
<li id="current"><a href="/logout.php">Afmelden</a></li> ';
}
?>
Het klopt ook dat er geen md5 beveiliging op zit, omdat ik eerst nog zoek naar de fout in het menu
Gebruik $_SESSION['...'].
En zorg dat je wachtwoorden met SHA1 encrypt.