Cookies
deze tut gelezen, maar ik snap er eigenlijk nog niks van..
ik wil mijn site namelijk cookie based maken,
zodat je maar 1x hoeft in te loggen enzo..
maar hoe werkt dan zoiets?
ik heb ik wil mijn site namelijk cookie based maken,
zodat je maar 1x hoeft in te loggen enzo..
maar hoe werkt dan zoiets?
//login
}
if($_POST['password'] == "goed"){
setcookie("loggedin", "ik ben wel ingelogd!", time()+3600*24,"/",".phphulp.nl",0);
}
edit: PS: dit is niet de meest veilige manier ^^,
En verder kun je ook sessions gebruiken, daarmee blijft iemand ingelogd totdat hij zijn browser afsluit.
PPS: hou er wel rekeing mee dat er mensen zijn die cookies uitzetten. Dus je site cookie-based maken is ook niet echt een goed idee, nee, maak hem liever cookie-enabled.
Gewijzigd op 10/05/2005 20:25:00 door Jelmer -
mja.. maar werkt dat cookie-enebled anders dan?
Ja, dan werkt het ook wanneer een bezoeker geen cookies accepteerd. Oftewel een combinatie van sessions en cookies.
edit: hoe haal ik da gegeven van username uit de cookie om te gebruiken in bijv. een query?
Gewijzigd op 12/05/2005 10:52:00 door Yme-Jan
Warning: Cannot modify header information - headers already sent by (output started at /usr/opt/usr/wa4o6920633/DOMAIN/HTML/ts/level/home.php:17) in /usr/opt/usr/wa4o6920633/DOMAIN/HTML/ts/php/login.php on line 15
Code (php)
hij maakt de cookie niet aan.
Fout 2:
wil ik inloggen met sessie:
Code (php)
hij kijkt of de cookie bestaat, besaat niet.
echter de sessie bestaat wel,
tog staat er Niet ingelogd..
hoe kan ik er voor zorgen dat hij de 1 met rust laat als die er niet is..
Edit:
Fout 2 is opgelost
Gewijzigd op 12/05/2005 11:28:00 door Yme-Jan
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
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
<?php
if($session){
echo "You are already logged in.";
}else{
#########################################
if($_SERVER['REQUEST_METHOD'] == POST){
$username = $_POST['username'];
$password = md5($_POST['password']);
$b_cookie = $_POST['cookie'];
$query = mysql_query("SELECT * FROM `ts_members` WHERE `username`='$username' AND `password`='$password'");
$check = mysql_fetch_object($query);
if(mysql_num_rows($query) != 0 && $check->activated == 1){
if($b_cookie == ON){
setcookie("treadstone", "$username", time()+3600*24,"/",".a4o.nl",1);
}else{
$_SESSION['ts'] = $username;
}
echo "<table width=\"90%\" cellSpacing=\"0\" cellPadding=\"2\" border=\"1\" bordercolor=\"#000000\" style=\"border-collapse: collapse\" align=\"center\">";
echo "<tr><td><b>Login</b></td></tr>";
echo "<tr><td>You are logged in successfully. $b_cookie </td></tr>";
echo "</table>";
echo "<meta http-equiv=\"refresh\" content=\"1; url=index.php\">";
}else{
echo "<table width=\"90%\" cellSpacing=\"0\" cellPadding=\"2\" border=\"1\" bordercolor=\"#000000\" style=\"border-collapse: collapse\" align=\"center\">";
echo "<tr><td><b>ERROR</b></td></tr>";
echo "<tr><td>Login Failure:<br>
1. Wrong Username or Password<br>
2. Empty Fields<br>
3. Account UnActivated";
echo "</table>";
}
}else{
?>
if($session){
echo "You are already logged in.";
}else{
#########################################
if($_SERVER['REQUEST_METHOD'] == POST){
$username = $_POST['username'];
$password = md5($_POST['password']);
$b_cookie = $_POST['cookie'];
$query = mysql_query("SELECT * FROM `ts_members` WHERE `username`='$username' AND `password`='$password'");
$check = mysql_fetch_object($query);
if(mysql_num_rows($query) != 0 && $check->activated == 1){
if($b_cookie == ON){
setcookie("treadstone", "$username", time()+3600*24,"/",".a4o.nl",1);
}else{
$_SESSION['ts'] = $username;
}
echo "<table width=\"90%\" cellSpacing=\"0\" cellPadding=\"2\" border=\"1\" bordercolor=\"#000000\" style=\"border-collapse: collapse\" align=\"center\">";
echo "<tr><td><b>Login</b></td></tr>";
echo "<tr><td>You are logged in successfully. $b_cookie </td></tr>";
echo "</table>";
echo "<meta http-equiv=\"refresh\" content=\"1; url=index.php\">";
}else{
echo "<table width=\"90%\" cellSpacing=\"0\" cellPadding=\"2\" border=\"1\" bordercolor=\"#000000\" style=\"border-collapse: collapse\" align=\"center\">";
echo "<tr><td><b>ERROR</b></td></tr>";
echo "<tr><td>Login Failure:<br>
1. Wrong Username or Password<br>
2. Empty Fields<br>
3. Account UnActivated";
echo "</table>";
}
}else{
?>
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
<?
echo "<table width=\"90%\" cellSpacing=\"0\" cellPadding=\"2\" border=\"1\" bordercolor=\"#000000\" style=\"border-collapse: collapse\" align=\"center\">";
echo "<tr><td width=\"25%\">Username:</td>";
echo "<td width=\"75%\" align=\"center\"><input type=\"text\" style=\"width: 90%\" name=\"username\"></td></tr>";
echo "<tr><td width=\"25%\">Password:</td>";
echo "<td width=\"75%\" align=\"center\"><input type=\"password\" style=\"width: 90%\" name=\"password\"></td></tr>";
echo "<tr><td width=\"25%\">Remember Me:</td>";
echo "<td width=\"75%\" align=\"center\"><input type=\"checkbox\" name=\"cookie\" value=\"ON\"></td></tr>";
echo "<tr><td colspan=\"2\"><input type=\"submit\" value=\"Login\"></td></tr>";
echo "</table>";
echo "</form>";
} }
?>
echo "<table width=\"90%\" cellSpacing=\"0\" cellPadding=\"2\" border=\"1\" bordercolor=\"#000000\" style=\"border-collapse: collapse\" align=\"center\">";
echo "<tr><td width=\"25%\">Username:</td>";
echo "<td width=\"75%\" align=\"center\"><input type=\"text\" style=\"width: 90%\" name=\"username\"></td></tr>";
echo "<tr><td width=\"25%\">Password:</td>";
echo "<td width=\"75%\" align=\"center\"><input type=\"password\" style=\"width: 90%\" name=\"password\"></td></tr>";
echo "<tr><td width=\"25%\">Remember Me:</td>";
echo "<td width=\"75%\" align=\"center\"><input type=\"checkbox\" name=\"cookie\" value=\"ON\"></td></tr>";
echo "<tr><td colspan=\"2\"><input type=\"submit\" value=\"Login\"></td></tr>";
echo "</table>";
echo "</form>";
} }
?>
hier zit de fout op regel 15:
Warning: Cannot modify header information - headers already sent by (output started at /usr/opt/usr/wa4o6920633/DOMAIN/HTML/ts/level/home.php:17) in /usr/opt/usr/wa4o6920633/DOMAIN/HTML/ts/php/login.php on line 15
regel 15 is de setcookie...
weet iemand mss hoe ik dit kan verhelpen?
Heb je de php faq op deze pagina al gelezen?
:|
[faq] [/faq]