session ingelogd
Code (php)
Wat moet er bij
if ( isset($_COOKIE['.............'])){
staan.
Dit is mijn login.php, misschien kunnen jullie me met dat helpen om de juiste woord te vinden :)
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
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
<?
ob_start();
session_start();
include("config.php");
include("functions.php");
if(!isset($_COOKIE['last_active']))
{
if(isset($_SESSION['user_id']))
{
mysql_query("UPDATE tbl_users SET user_lastactive = NOW() WHERE user_id = '" . $_SESSION['user_id'] . "'") or die(mysql_error());
setcookie("last_active",true,time()+5);
}
}
if(!isset($_SESSION['user_id']))
{
if(isset($_POST['login']))
{
$query = mysql_query("SELECT * FROM tbl_users WHERE user_name = '" . $_POST['user'] . "' AND user_pass = '" . md5($_POST['pass']) . "'");
$result = mysql_num_rows($query);
if(empty($result))
{
echo "<script>alert('Hata.'); document.location.href=('login.php')</script>";
}
else
{
while($row = mysql_fetch_assoc($query))
{
$user_id = $row['user_id'];
}
$_SESSION['user_id'] = $user_id;
// Als ingelogd
$query = mysql_query("SELECT * FROM tbl_users WHERE user_id = '" . $_SESSION['user_id'] . "'");
while($row = mysql_fetch_assoc($query))
{
echo "Gebruikersnaam : <b>" . $row['user_name']. "</b>";
if($row['user_pm'])
{
$msg = mysql_result(mysql_query("SELECT COUNT(1) FROM tbl_msg WHERE msg_to = '" . $_SESSION['user_id'] . "'"),0);
if(empty($msg))
{
$msg = "<font color=\"#008000\">Empty</font>";
}
elseif($msg >= $cfg['max_msg'])
{
$msg = "<font color=\"#FF0000\">FULL</font>";
}
else
{
$msg = $msg . " / " . $cfg['max_msg'];
}
echo "<br>\n";
echo "Inbox : <b>". $msg ."</b> ( <a href=\"msg.php?act=inbox\">Bekijken</a> )";
}
}
echo "<br>\n<br>\n";
if(isset($_SESSION['admin_login']))
{
echo "<img src=\"images/icons/admin.gif\"> <a href=\"admin.php\">Admin</a>";
echo "<br>\n";
}
echo "<img src=\"images/icons/memberlist.gif\"> <a href=\"memberlist.php\">Ledenlijst</a>";
echo "<br>\n";
echo "<img src=\"images/icons/profile.gif\"> <a href=\"profile.php?act=edit_profile\">Verander Profiel</a>";
echo "<br>\n";
echo "<img src=\"images/icons/profile.gif\"> <a href=\"profile.php?act=view&user_id=" . $_SESSION['user_id'] . "\">Bekijk Profiel</a>";
echo "<br>\n";
echo "<img src=\"images/icons/logoff.gif\"> <a href=\"logoff.php\">Uitloggen</a>";
}
}
else
{
?>
<table border="0" width="100%">
<form method="POST" action="login.php">
<input type="hidden" value="1" name="login" />
<tr>
<td width="187"><b>Gebruikersnaam:</b> </td>
<td><input type="text" name="user" maxlength="15" size="31" /></td>
</tr>
<tr>
<td width="187"><b>Wachtwoord:</b></td>
<td><input type="password" name="pass" maxlength="15" size="31" /></td>
</tr>
</table>
<table border="0" width="100%" id="table74">
<tr>
<td> </td>
<td width="700"><input type="submit" value="Inloggen" /> </td>
</tr>
</form>
</table>
<address>
</address>
<table border="0" width="100%" id="table75">
<tr>
<td align="center">
<img src="images/icons/register.gif" alt="register" />
<a href="register.php">Registreren</a></td>
<td align="center">
<img src="images/icons/memberlist.gif" alt="memberlist" />
<a href="memberlist.php">Ledenlijst</a> </td>
</tr>
</table>
<?
}
}
else
{
$query = mysql_query("SELECT * FROM tbl_users WHERE user_id = '" . $_SESSION['user_id'] . "'");
while($row = mysql_fetch_assoc($query))
{
echo "Gebruikersnaam : <b>" . $row['user_name']. "</b>";
if($row['user_pm'])
{
$msg = mysql_result(mysql_query("SELECT COUNT(1) FROM tbl_msg WHERE msg_to = '" . $_SESSION['user_id'] . "'"),0);
if(empty($msg))
{
$msg = "<font color=\"#008000\">Empty</font>";
}
elseif($msg >= $cfg['max_msg'])
{
$msg = "<font color=\"#FF0000\">FULL</font>";
}
else
{
$msg = $msg . " / " . $cfg['max_msg'];
}
echo "<br>\n";
echo "Inbox : <b>". $msg ."</b> ( <a href=\"msg.php?act=inbox\">Bekijken</a> )";
}
}
echo "<br>\n<br>\n";
if(isset($_SESSION['admin_login']))
{
echo "<img src=\"images/icons/admin.gif\"> <a href=\"admin.php\">Admin</a>";
echo "<br>\n";
}
echo "<img src=\"images/icons/memberlist.gif\"> <a href=\"memberlist.php\">Ledenlijst</a>";
echo "<br>\n";
echo "<img src=\"images/icons/profile.gif\"> <a href=\"profile.php?act=edit_profile\">Verander Profiel</a>";
echo "<br>\n";
echo "<img src=\"images/icons/profile.gif\"> <a href=\"profile.php?act=view&user_id=" . $_SESSION['user_id'] . "\">Bekijk Profiel</a>";
echo "<br>\n";
echo "<img src=\"images/icons/logoff.gif\"> <a href=\"logoff.php\">Uitloggen</a>";
}
?>
</body>
</html>
ob_start();
session_start();
include("config.php");
include("functions.php");
if(!isset($_COOKIE['last_active']))
{
if(isset($_SESSION['user_id']))
{
mysql_query("UPDATE tbl_users SET user_lastactive = NOW() WHERE user_id = '" . $_SESSION['user_id'] . "'") or die(mysql_error());
setcookie("last_active",true,time()+5);
}
}
if(!isset($_SESSION['user_id']))
{
if(isset($_POST['login']))
{
$query = mysql_query("SELECT * FROM tbl_users WHERE user_name = '" . $_POST['user'] . "' AND user_pass = '" . md5($_POST['pass']) . "'");
$result = mysql_num_rows($query);
if(empty($result))
{
echo "<script>alert('Hata.'); document.location.href=('login.php')</script>";
}
else
{
while($row = mysql_fetch_assoc($query))
{
$user_id = $row['user_id'];
}
$_SESSION['user_id'] = $user_id;
// Als ingelogd
$query = mysql_query("SELECT * FROM tbl_users WHERE user_id = '" . $_SESSION['user_id'] . "'");
while($row = mysql_fetch_assoc($query))
{
echo "Gebruikersnaam : <b>" . $row['user_name']. "</b>";
if($row['user_pm'])
{
$msg = mysql_result(mysql_query("SELECT COUNT(1) FROM tbl_msg WHERE msg_to = '" . $_SESSION['user_id'] . "'"),0);
if(empty($msg))
{
$msg = "<font color=\"#008000\">Empty</font>";
}
elseif($msg >= $cfg['max_msg'])
{
$msg = "<font color=\"#FF0000\">FULL</font>";
}
else
{
$msg = $msg . " / " . $cfg['max_msg'];
}
echo "<br>\n";
echo "Inbox : <b>". $msg ."</b> ( <a href=\"msg.php?act=inbox\">Bekijken</a> )";
}
}
echo "<br>\n<br>\n";
if(isset($_SESSION['admin_login']))
{
echo "<img src=\"images/icons/admin.gif\"> <a href=\"admin.php\">Admin</a>";
echo "<br>\n";
}
echo "<img src=\"images/icons/memberlist.gif\"> <a href=\"memberlist.php\">Ledenlijst</a>";
echo "<br>\n";
echo "<img src=\"images/icons/profile.gif\"> <a href=\"profile.php?act=edit_profile\">Verander Profiel</a>";
echo "<br>\n";
echo "<img src=\"images/icons/profile.gif\"> <a href=\"profile.php?act=view&user_id=" . $_SESSION['user_id'] . "\">Bekijk Profiel</a>";
echo "<br>\n";
echo "<img src=\"images/icons/logoff.gif\"> <a href=\"logoff.php\">Uitloggen</a>";
}
}
else
{
?>
<table border="0" width="100%">
<form method="POST" action="login.php">
<input type="hidden" value="1" name="login" />
<tr>
<td width="187"><b>Gebruikersnaam:</b> </td>
<td><input type="text" name="user" maxlength="15" size="31" /></td>
</tr>
<tr>
<td width="187"><b>Wachtwoord:</b></td>
<td><input type="password" name="pass" maxlength="15" size="31" /></td>
</tr>
</table>
<table border="0" width="100%" id="table74">
<tr>
<td> </td>
<td width="700"><input type="submit" value="Inloggen" /> </td>
</tr>
</form>
</table>
<address>
</address>
<table border="0" width="100%" id="table75">
<tr>
<td align="center">
<img src="images/icons/register.gif" alt="register" />
<a href="register.php">Registreren</a></td>
<td align="center">
<img src="images/icons/memberlist.gif" alt="memberlist" />
<a href="memberlist.php">Ledenlijst</a> </td>
</tr>
</table>
<?
}
}
else
{
$query = mysql_query("SELECT * FROM tbl_users WHERE user_id = '" . $_SESSION['user_id'] . "'");
while($row = mysql_fetch_assoc($query))
{
echo "Gebruikersnaam : <b>" . $row['user_name']. "</b>";
if($row['user_pm'])
{
$msg = mysql_result(mysql_query("SELECT COUNT(1) FROM tbl_msg WHERE msg_to = '" . $_SESSION['user_id'] . "'"),0);
if(empty($msg))
{
$msg = "<font color=\"#008000\">Empty</font>";
}
elseif($msg >= $cfg['max_msg'])
{
$msg = "<font color=\"#FF0000\">FULL</font>";
}
else
{
$msg = $msg . " / " . $cfg['max_msg'];
}
echo "<br>\n";
echo "Inbox : <b>". $msg ."</b> ( <a href=\"msg.php?act=inbox\">Bekijken</a> )";
}
}
echo "<br>\n<br>\n";
if(isset($_SESSION['admin_login']))
{
echo "<img src=\"images/icons/admin.gif\"> <a href=\"admin.php\">Admin</a>";
echo "<br>\n";
}
echo "<img src=\"images/icons/memberlist.gif\"> <a href=\"memberlist.php\">Ledenlijst</a>";
echo "<br>\n";
echo "<img src=\"images/icons/profile.gif\"> <a href=\"profile.php?act=edit_profile\">Verander Profiel</a>";
echo "<br>\n";
echo "<img src=\"images/icons/profile.gif\"> <a href=\"profile.php?act=view&user_id=" . $_SESSION['user_id'] . "\">Bekijk Profiel</a>";
echo "<br>\n";
echo "<img src=\"images/icons/logoff.gif\"> <a href=\"logoff.php\">Uitloggen</a>";
}
?>
</body>
</html>
Gewijzigd op 01/01/1970 01:00:00 door Giga
dit stamt uit van de tijd van de Dino's ofzo :P
Gebruik sessions.
dus:
Code (php)
voor zolang als dat je de browser openhoud, blijft de sessie bestaan.
Zo kan je doen:
$_SESSION["hallo"]="hallo";
Suc-6 ;-)
Ik ben nog een beginner, ik zie die waarde niet in login.php waar kan ik die waarde vinden, waar staat ie, of zie jij hem in login.php?
Groetjes...
user_id
giga schreef op 19.06.2007 23:21:
Dat doet hij niet omdat volgens mij als ik goed zit te kijken attans word vij weinig sessions ook daarwerkelijk eerst aangemaakt voordat ze gebruikt worden ...
Dus, wat voor session moet ik er in zetten?
hiervoor moeten wel de wachtwoord gecript in de database staan..
Bijvoorbeeld zo:
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
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
<?PHP
if($_POST['username'] <> "" and $_POST['password'] <> "")
{
/// Geposte waarde in variable zetten
$username = $_POST['username'];
$password = $_POST['password'];
// Controleren met database
$sql = mysql_query("SELECT * FROM users WHERE username = '".$username."'") or die ('niet controlle '. mysql_error());
$res = mysql_fetch_assoc($sql);
if(!$res)
{
print 'Username bestaad niet';
return false;
}
elseif($username = $res['username'] and md5($password) <> $res['password'])
{
print 'Password is niet correct';
return false;
}
elseif($username = $res['username'] and md5($password) = $res['password'])
{
$_SESSION['gegevens'] = $res;
print 'U bent nu ingelogd';
///// REST CODE
}
?>
if($_POST['username'] <> "" and $_POST['password'] <> "")
{
/// Geposte waarde in variable zetten
$username = $_POST['username'];
$password = $_POST['password'];
// Controleren met database
$sql = mysql_query("SELECT * FROM users WHERE username = '".$username."'") or die ('niet controlle '. mysql_error());
$res = mysql_fetch_assoc($sql);
if(!$res)
{
print 'Username bestaad niet';
return false;
}
elseif($username = $res['username'] and md5($password) <> $res['password'])
{
print 'Password is niet correct';
return false;
}
elseif($username = $res['username'] and md5($password) = $res['password'])
{
$_SESSION['gegevens'] = $res;
print 'U bent nu ingelogd';
///// REST CODE
}
?>
Nu heb je dus de $_SESSION['gegevens'] gevuld
Ik hoop dat je hier wat aan hebt!
Groetjes
Gewijzigd op 01/01/1970 01:00:00 door Marco PHPJunky