Inloggen probleem
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
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
<?php
// Start session and check if user is already logged in, if it is stop them to login again
session_start();
if($_SESSION['s_logged_n'] == 'true'){
echo "You are already registered user";
// Else show login form
} else {
?>
<form action="login.php" method="post">
<table width="600" border="0" cellspacing="0" cellpadding="4">
<tr>
<td width="196">Username:</td>
<td width="388"><label for="username"></label>
<input type="text" name="username" id="username"></td>
</tr>
<tr>
<td>Password:</td>
<td><label for="password"></label>
<input type="password" name="password" id="password"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="login" id="login" value="Login"></td>
</tr>
</table>
</form>
<?php
}
?>
// Start session and check if user is already logged in, if it is stop them to login again
session_start();
if($_SESSION['s_logged_n'] == 'true'){
echo "You are already registered user";
// Else show login form
} else {
?>
<form action="login.php" method="post">
<table width="600" border="0" cellspacing="0" cellpadding="4">
<tr>
<td width="196">Username:</td>
<td width="388"><label for="username"></label>
<input type="text" name="username" id="username"></td>
</tr>
<tr>
<td>Password:</td>
<td><label for="password"></label>
<input type="password" name="password" id="password"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="login" id="login" value="Login"></td>
</tr>
</table>
</form>
<?php
}
?>
En hier is mijn login.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
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
<?php
// Start session and check if user is already registered and logged in then say so if it is
session_start();
if ($_SESSION['s_logged_n'] == 'true'){
echo "You are already registered user";
// Else if login button is pressed start the code
} else {
if (isset($_POST['login'])){
// If username or password fields are left blank output it
if ((empty($username)) || (empty($password))){
echo "You must fill in username and password";
// Else if everything is ok continue with code
} else {
// Include config file
include "config.php";
// Define variables
$username = $_POST['username'];
$password = $_POST['password'];
// Add some slashes and trim's and put md5 to password
$username = addslashes(trim($username));
$password = addslashes(trim($password));
$password = md5($password);
// Query the table
$query = "SELECT * FROM users WHERE username = '$username' AND password = '$password' LIMIT 1";
$result = mysql_query($query);
$resulted = mysql_fetch_array($result);
// Check if user is activated
if ($resulted['activated'] == 1){
$count = mysql_num_rows($result);
// Check for single line to be selected
if ($count == 1){
// If everything is good proceed with login and start session, register s_logged_n and s_username
session_start();
$_SESSION['s_logged_n'] = 'true';
$_SESSION['s_username'] = $username;
// Echo successfull message
echo "You have successfully logged in, you may visit <a href=\"index.php\">index</a> page now.";
}
} else {
// If user miss username or pass or have not activated account say so
echo "Invalid username/password or your account is not yet activated";
}
}
} else {
// If someone just tries to open login.php stop them
echo "You must login over form";
}
}
?>
// Start session and check if user is already registered and logged in then say so if it is
session_start();
if ($_SESSION['s_logged_n'] == 'true'){
echo "You are already registered user";
// Else if login button is pressed start the code
} else {
if (isset($_POST['login'])){
// If username or password fields are left blank output it
if ((empty($username)) || (empty($password))){
echo "You must fill in username and password";
// Else if everything is ok continue with code
} else {
// Include config file
include "config.php";
// Define variables
$username = $_POST['username'];
$password = $_POST['password'];
// Add some slashes and trim's and put md5 to password
$username = addslashes(trim($username));
$password = addslashes(trim($password));
$password = md5($password);
// Query the table
$query = "SELECT * FROM users WHERE username = '$username' AND password = '$password' LIMIT 1";
$result = mysql_query($query);
$resulted = mysql_fetch_array($result);
// Check if user is activated
if ($resulted['activated'] == 1){
$count = mysql_num_rows($result);
// Check for single line to be selected
if ($count == 1){
// If everything is good proceed with login and start session, register s_logged_n and s_username
session_start();
$_SESSION['s_logged_n'] = 'true';
$_SESSION['s_username'] = $username;
// Echo successfull message
echo "You have successfully logged in, you may visit <a href=\"index.php\">index</a> page now.";
}
} else {
// If user miss username or pass or have not activated account say so
echo "Invalid username/password or your account is not yet activated";
}
}
} else {
// If someone just tries to open login.php stop them
echo "You must login over form";
}
}
?>
Het gaat om het stukje waar hij zegt: Als username en password empty zijn, echo dan : You must fill in username and password.
Maar ik heb het dus wel ingevuld, en beide velden zijn gewoon ingevuld. Kunnen jullie in 1 van deze 2 php's een fout vinden?
Gewijzigd op 04/01/2011 16:11:33 door Bas IJzelendoorn
zet dit achter regel 8 van je login.php
edit:
never mind, vervang in login.php dit:
Code (php)
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
// If username or password fields are left blank output it
if ((empty($username)) || (empty($password))){
echo "You must fill in username and password";
// Else if everything is ok continue with code
} else {
// Include config file
include "config.php";
// Define variables
$username = $_POST['username'];
$password = $_POST['password'];
if ((empty($username)) || (empty($password))){
echo "You must fill in username and password";
// Else if everything is ok continue with code
} else {
// Include config file
include "config.php";
// Define variables
$username = $_POST['username'];
$password = $_POST['password'];
naar dit:
Code (php)
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
// Define variables
$username = $_POST['username'];
$password = $_POST['password'];
// If username or password fields are left blank output it
if((empty($username) || (empty($password)){
echo "You must fill in username and password";
// Else if everything is ok continue with code
} else {
// Include config file
include("config.php");
$username = $_POST['username'];
$password = $_POST['password'];
// If username or password fields are left blank output it
if((empty($username) || (empty($password)){
echo "You must fill in username and password";
// Else if everything is ok continue with code
} else {
// Include config file
include("config.php");
Gewijzigd op 04/01/2011 16:10:57 door Bas IJzelendoorn
// Echo successfull message
echo "You have successfully logged in, you may visit <a href=\"index.php\">index</a> page now.";
Enig idee hoe dit kan?
Ik heb dit script gedownload, dus niet zelf gemaakt, dus ik probeer het zo goed mogelijk te snappen...
Toevoeging op 04/01/2011 16:49:06:
Oke, sorry dat was mijn eigen fout, heb het nu opgelost, ik had jou vervanging er zo in geplakt, dus het ging allemaal een beetje dubbel! Dankje! Alles werkt nu goed!