simpel login systeem
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
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
<?php
session_start();
$username="bruno"; // jouw gebruikersnaam
$password="nathalie"; // jouw wachtwoord
$username1="mathias"; // jouw gebruikersnaam
$password1="test"; // jouw wachtwoord
if(!empty($_POST)) {
$_SESSION["username"]=$_POST["username"];
$_SESSION["password"]=$_POST["password"];
if(( $_SESSION["username"]!=$username) || ($_SESSION["password"]!=$password)) {
die("Je hebt een verkeerde gebruikersnaam of wachtwoord ingevoerd!<br> <a href=\"login.php\">Terug</a>");
session_destroy();
}else{
header("Location: invoeren.php");
}
}else{
}
?>
<html>
<body>
<center>
<b>Welkom bij de easyconcept login pagina !</b>
</br></br></br>
<form method=post action="<?php $PHP_SELF ?>">
Gebruikersnaam: <input name=username name=username><br>
Wachtwoord: <input name=password type=password name=password><br>
<input type=submit value="Inloggen!"> </center>
</form>
</body>
</html>
session_start();
$username="bruno"; // jouw gebruikersnaam
$password="nathalie"; // jouw wachtwoord
$username1="mathias"; // jouw gebruikersnaam
$password1="test"; // jouw wachtwoord
if(!empty($_POST)) {
$_SESSION["username"]=$_POST["username"];
$_SESSION["password"]=$_POST["password"];
if(( $_SESSION["username"]!=$username) || ($_SESSION["password"]!=$password)) {
die("Je hebt een verkeerde gebruikersnaam of wachtwoord ingevoerd!<br> <a href=\"login.php\">Terug</a>");
session_destroy();
}else{
header("Location: invoeren.php");
}
}else{
}
?>
<html>
<body>
<center>
<b>Welkom bij de easyconcept login pagina !</b>
</br></br></br>
<form method=post action="<?php $PHP_SELF ?>">
Gebruikersnaam: <input name=username name=username><br>
Wachtwoord: <input name=password type=password name=password><br>
<input type=submit value="Inloggen!"> </center>
</form>
</body>
</html>
zoals je ziet controleert hij alleen maar de $username en $password, hoe kan ik ervoor zorgen dat ik meerdere gebruikers kan toevoegen ?
ik heb al verschillende manieren geprobeerd door meerdere users bij $username en $password te zetten maar het lukt niet. is hier een simpele oplossing voor ?
Code (php)
oftewel : op regel 24 een else if zetten dat als je username hetzelfde is als username2 enz enz gelijk is, dat het dan ook goed is..
Edit:
effe regelnummer zoeken
Edit:
edit2: je gebruikt $PHP_SELF ?
doe eens..
doe eens..
Gewijzigd op 01/01/1970 01:00:00 door Chris
Parse error: syntax error, unexpected T_ELSE in C:\wamp\www\bruno\login.php on line 25
dat is inderdaad wel wat handiger ;)
maar ik had het echt graag op deze manier gehad ... alles zit al in mijn code verwerkt enzo, als het geen moeite is ...
post het script eens wat je nu hebt?
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
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
<?php
session_start();
$username="bruno"; // jouw gebruikersnaam
$password="nathalie"; // jouw wachtwoord
$username1="mathias"; // jouw gebruikersnaam
$password1="test"; // jouw wachtwoord
if(!empty($_POST)) {
$_SESSION["username"]=$_POST["username"];
$_SESSION["password"]=$_POST["password"];
if(( $_SESSION["username"]!=$username) || ($_SESSION["password"]!=$password)) {
else if(( $__SESSION['username']!=$username1) || ($_SESSION['password']!=$password1)) {
die("Je hebt een verkeerde gebruikersnaam of wachtwoord ingevoerd!<br> <a href=\"login.php\">Terug</a>");
session_destroy();
}else{
header("Location: invoeren.php");
}
}else{
}
?>
<html>
<body>
<center>
<b>Welkom bij de easyconcept login pagina !</b>
</br></br></br>
<form method=post action="<?php $PHP_SELF ?>">
Gebruikersnaam: <input name=username name=username><br>
Wachtwoord: <input name=password type=password name=password><br>
<input type=submit value="Inloggen!"> </center>
</form>
</body>
</html>
session_start();
$username="bruno"; // jouw gebruikersnaam
$password="nathalie"; // jouw wachtwoord
$username1="mathias"; // jouw gebruikersnaam
$password1="test"; // jouw wachtwoord
if(!empty($_POST)) {
$_SESSION["username"]=$_POST["username"];
$_SESSION["password"]=$_POST["password"];
if(( $_SESSION["username"]!=$username) || ($_SESSION["password"]!=$password)) {
else if(( $__SESSION['username']!=$username1) || ($_SESSION['password']!=$password1)) {
die("Je hebt een verkeerde gebruikersnaam of wachtwoord ingevoerd!<br> <a href=\"login.php\">Terug</a>");
session_destroy();
}else{
header("Location: invoeren.php");
}
}else{
}
?>
<html>
<body>
<center>
<b>Welkom bij de easyconcept login pagina !</b>
</br></br></br>
<form method=post action="<?php $PHP_SELF ?>">
Gebruikersnaam: <input name=username name=username><br>
Wachtwoord: <input name=password type=password name=password><br>
<input type=submit value="Inloggen!"> </center>
</form>
</body>
</html>
met de error:
Parse error: syntax error, unexpected T_ELSE in C:\wamp\www\bruno\login.php on line 25
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
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
<?php
session_start();
$username="bruno"; // jouw gebruikersnaam
$password="nathalie"; // jouw wachtwoord
$username1="mathias"; // jouw gebruikersnaam
$password1="test"; // jouw wachtwoord
if(!empty($_POST)) {
$_SESSION["username"]=$_POST["username"];
$_SESSION["password"]=$_POST["password"];
if(( $_SESSION["username"]!=$username) || ($_SESSION["password"]!=$password)) {
die("Je hebt een verkeerde gebruikersnaam of wachtwoord ingevoerd!<br> <a href=\"login.php\">Terug</a>");
session_destroy();
header("Location: invoeren.php");
}else if(( $__SESSION['username']!=$username1) || ($_SESSION['password']!=$password1)) {
die("Je hebt een verkeerde gebruikersnaam of wachtwoord ingevoerd!<br> <a href=\"login.php\">Terug</a>");
session_destroy();
header("Location: invoeren.php");
}
}else{
}
?>
<html>
<body>
<center>
<b>Welkom bij de easyconcept login pagina !</b>
</br></br></br>
<form method=post action="<?php $PHP_SELF ?>">
Gebruikersnaam: <input name=username name=username><br>
Wachtwoord: <input name=password type=password name=password><br>
<input type=submit value="Inloggen!"> </center>
</form>
</body>
</html>
session_start();
$username="bruno"; // jouw gebruikersnaam
$password="nathalie"; // jouw wachtwoord
$username1="mathias"; // jouw gebruikersnaam
$password1="test"; // jouw wachtwoord
if(!empty($_POST)) {
$_SESSION["username"]=$_POST["username"];
$_SESSION["password"]=$_POST["password"];
if(( $_SESSION["username"]!=$username) || ($_SESSION["password"]!=$password)) {
die("Je hebt een verkeerde gebruikersnaam of wachtwoord ingevoerd!<br> <a href=\"login.php\">Terug</a>");
session_destroy();
header("Location: invoeren.php");
}else if(( $__SESSION['username']!=$username1) || ($_SESSION['password']!=$password1)) {
die("Je hebt een verkeerde gebruikersnaam of wachtwoord ingevoerd!<br> <a href=\"login.php\">Terug</a>");
session_destroy();
header("Location: invoeren.php");
}
}else{
}
?>
<html>
<body>
<center>
<b>Welkom bij de easyconcept login pagina !</b>
</br></br></br>
<form method=post action="<?php $PHP_SELF ?>">
Gebruikersnaam: <input name=username name=username><br>
Wachtwoord: <input name=password type=password name=password><br>
<input type=submit value="Inloggen!"> </center>
</form>
</body>
</html>
Oja, een tip: het is makkelijker werken als je tabs gebruikt ;)
Zoals dit :
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
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
<?php
session_start();
$username="bruno"; // jouw gebruikersnaam
$password="nathalie"; // jouw wachtwoord
$username1="mathias"; // jouw gebruikersnaam
$password1="test"; // jouw wachtwoord
if(!empty($_POST)) {
$_SESSION["username"]=$_POST["username"];
$_SESSION["password"]=$_POST["password"];
if(( $_SESSION["username"]!=$username) || ($_SESSION["password"]!=$password)) {
die("Je hebt een verkeerde gebruikersnaam of wachtwoord ingevoerd!<br> <a href=\"login.php\">Terug</a>");
session_destroy();
header("Location: invoeren.php");
}else if(( $__SESSION['username']!=$username1) || ($_SESSION['password']!=$password1)) {
die("Je hebt een verkeerde gebruikersnaam of wachtwoord ingevoerd!<br> <a href=\"login.php\">Terug</a>");
session_destroy();
header("Location: invoeren.php");
}
}else{
// laat inlogpagina zien?
?>
<html>
<body>
<center>
<b>Welkom bij de easyconcept login pagina !</b>
</br></br></br>
<form method=post action="<?php $SERVER['PHP_SELF']; ?>">
Gebruikersnaam: <input name=username name=username><br>
Wachtwoord: <input name=password type=password name=password><br>
<input type=submit value="Inloggen!"> </center>
</form>
</center>
</body>
</html>
<?php
}
?>
session_start();
$username="bruno"; // jouw gebruikersnaam
$password="nathalie"; // jouw wachtwoord
$username1="mathias"; // jouw gebruikersnaam
$password1="test"; // jouw wachtwoord
if(!empty($_POST)) {
$_SESSION["username"]=$_POST["username"];
$_SESSION["password"]=$_POST["password"];
if(( $_SESSION["username"]!=$username) || ($_SESSION["password"]!=$password)) {
die("Je hebt een verkeerde gebruikersnaam of wachtwoord ingevoerd!<br> <a href=\"login.php\">Terug</a>");
session_destroy();
header("Location: invoeren.php");
}else if(( $__SESSION['username']!=$username1) || ($_SESSION['password']!=$password1)) {
die("Je hebt een verkeerde gebruikersnaam of wachtwoord ingevoerd!<br> <a href=\"login.php\">Terug</a>");
session_destroy();
header("Location: invoeren.php");
}
}else{
// laat inlogpagina zien?
?>
<html>
<body>
<center>
<b>Welkom bij de easyconcept login pagina !</b>
</br></br></br>
<form method=post action="<?php $SERVER['PHP_SELF']; ?>">
Gebruikersnaam: <input name=username name=username><br>
Wachtwoord: <input name=password type=password name=password><br>
<input type=submit value="Inloggen!"> </center>
</form>
</center>
</body>
</html>
<?php
}
?>
Gewijzigd op 01/01/1970 01:00:00 door Chris
nop dit werkt ook niet, ik kan nu met geen enkele gebruikersnaam meer inloggen
Ik weet niet waar je dit script vandaan heb (boek, tutorial) maar het werkt in ider geval niet....
inderdaad, ik bedoel het werkt wel maar alleen maar met 1 gebruikersnaam
De elseif staat op de verkeerde plaats. Daarnaast sla je een wachtwoord nooit op in een sessievariabele, nergens voor nodig. Je gebruikt alleen een sessievariabele om aan te tonen dat je ingelogd bent en eventueel een om de gebruikersnaam in op te slaan.
Probeer tevens netjes te scripten door in te springen. Daar wordt je code een stuk overzichtelijker van.
Onderstaande is jouw script aangepast naar een werkende variant...
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
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
<?php
error_reporting(E_ALL);
session_start();
$users = array (
array (
'username' => 'bruno',
'password' => 'nathalie' ),
array (
'username' => 'mathias',
'password' => 'test' )
);
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
foreach($users as $user)
{
if($_POST['username'] == $user['username'] && $_POST['password'] == $user['password'])
{
$_SESSION['logged_in'] = true;
$_SESSION['username'] = $user['username'];
break;
}
}
if(!isset($_SESSION['logged_in']))
{
echo 'Je hebt geen geldigde gebruikersnaam of wachtwoord ingevoerd';
}
else
{
echo 'Je bent ingelogd';
}
}
?>
<html>
<body>
<center>
<b>Welkom bij de easyconcept login pagina !</b>
</br></br></br>
<form method=post action="<?php echo $_SERVER['PHP_SELF']; ?>">
Gebruikersnaam: <input name=username name=username><br>
Wachtwoord: <input name=password type=password name=password><br>
<input type=submit value="Inloggen!"> </center>
</form>
</body>
</html>
error_reporting(E_ALL);
session_start();
$users = array (
array (
'username' => 'bruno',
'password' => 'nathalie' ),
array (
'username' => 'mathias',
'password' => 'test' )
);
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
foreach($users as $user)
{
if($_POST['username'] == $user['username'] && $_POST['password'] == $user['password'])
{
$_SESSION['logged_in'] = true;
$_SESSION['username'] = $user['username'];
break;
}
}
if(!isset($_SESSION['logged_in']))
{
echo 'Je hebt geen geldigde gebruikersnaam of wachtwoord ingevoerd';
}
else
{
echo 'Je bent ingelogd';
}
}
?>
<html>
<body>
<center>
<b>Welkom bij de easyconcept login pagina !</b>
</br></br></br>
<form method=post action="<?php echo $_SERVER['PHP_SELF']; ?>">
Gebruikersnaam: <input name=username name=username><br>
Wachtwoord: <input name=password type=password name=password><br>
<input type=submit value="Inloggen!"> </center>
</form>
</body>
</html>
toch bedankt voor de hulp !