Hallo an alle!
Ich habe seit 3 Tage über Cookies gemacht und habe nie geschafft. In Internet Google stand alles drauf, aber nicht so drauf. Ich muss nur ein Username in meine Homepage (2 Seite). Zuerst "Set" in erste Startseite und dann Willkommenseite "Get und Delete". Das ist kleine Cookie. Es funktiert gar nicht, weil ich Cookie nicht programieren kann. Ich brauche helfen. Vielen Dank!
--------------------------------------------------
index.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Cookie1 bei FitBeach</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="imagetoolbar" content="no">
<meta http-equiv="Content-Type" content="no-cache">
<meta name="description" content="FitBeach - Homepage">
<meta name="keywords" content="privately homepage, hearing-impaired hearing-impaired, my friends, photo albums, play, info, sun & sea, guest book">
<link rel="shortcut icon" href="favicon.ico">
<noscript>
<font color="#FF0000" face="Arial" size="5"><b><marquee><u>ACHTUNG:</u> Hier kann Passwort nicht eingeben. Bitte "JavaScript" aktivieren!</marquee></b></font>
</noscript>
<script language="JavaScript" type="text/javascript">
function write_cookie(FitBeach,username,1)
{
var a = new Date();
a = new Date(a.getTime() +1000*60);
// Verfalldatum: 1 Minute später
document.cookie = FitBeach + ' = ' + 1 + '; expires='+a.toGMTString()+ ';';
}
</head>
<body bgcolor="#B2CCD4">
<script language="JavaScript" type="text/javascript">
function submitentry()
{
password = document.password1.password2.value;
passcode = 1;
for(i = 0; i < password.length; i++)
{
passcode *= password.charCodeAt(i);
}
{
if (passcode=="7658280560")
{
var username = "Freund 1"
top.location.href="welcome.htm";
}
else if (passcode=="7814572000")
{
var username = "Freund 2"
top.location.href="welcome.htm";
}
else if (passcode=="7970863440")
{
var username = "Freund 3"
top.location.href="welcome.htm";
}
else
{
alert("Falsches Passwort!");
document.password1.reset();
document.password1.password2.focus();
window.location.reload();
}
}
}
</script>
<center>
<br>
<font color="#800080" face="Arial" size="5">
<b>Homepage bei FitBeach</b><br>
</font>
<br>
<font color="#800080" face="Arial" size="3">
(mit Cookies 'Set')<br>
</font>
<br>
<br>
<br>
<font color="#FF0000" face="Arial" size="4">
<b>PASSWORT:</b><br>
</font>
<form name="password1" onsubmit="submitentry(); return false">
<input type="password" name="password2" size="15">
<br>
<input type="submit" value="OK">
</form>
<br>
<font color="#0000FF" face="Arial" size="2">
<i>Passwort: test1, test2 oder test3</i><br>
</font>
<br>
<br>
<br>
<a href="http://www.html-world.de/artikel/art_j15.php" target="_blank">
<font color="#000000" face="Arial" size="2">
HTMLWorld - JavaScript Artikel: Cookies in JavaScript<br>
</font>
</a>
</center>
</body>
</html>
--------------------------------------------------
welcome.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Cookie2 bei FitBeach</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="imagetoolbar" content="no">
<meta http-equiv="Content-Type" content="no-cache">
<meta name="description" content="FitBeach - Homepage">
<meta name="keywords" content="privately homepage, hearing-impaired hearing-impaired, my friends, photo albums, play, info, sun & sea, guest book">
<link rel="shortcut icon" href="favicon.ico">
<noscript>
<font color="#FF0000" face="Arial" size="5"><b><marquee><u>ACHTUNG:</u> Bitte "JavaScript" aktivieren!</marquee></b></font>
</noscript>
<script language="JavaScript" type="text/javascript">
if (document.cookie(FitBeach)=="")
{
alert('Nanu! Diese Homepage welcome.htm ist verboten. Bitte zuerst Passwort eingeben.');
top.location.href="index.html";
}
// Wenn Cookie nicht drauf ist, dann index.html zurück.
function read_cookie(FitBeach)
{
var nameEQ = name + "=";
var ca = document.cookie.split(';');
var username = name
for(var i=0;i < ca.length;i++)
{
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
</script>
</head>
<body bgcolor="#B2CCD4">
<script language="JavaScript" type="text/javascript">
</script>
<center>
<br>
<font color="#800080" face="Arial" size="5">
<b>Willkommen!</b><br>
</font>
<br>
<font color="#800080" face="Arial" size="3">
(mit Cookies 'Get' und dann 'Delete')<br>
</font>
<br>
<br>
<br>
<font color="#FF00FF" face="Arial" size="4"><b>
<script language="JavaScript" type="text/javascript">
document.write("Hallo, " + username + "!");
// Username zeigen
</script>
<br><u>Cookie: </u><br>
<script language="JavaScript" type="text/javascript">
document.write(document.cookie);
// Test: Was steht Cookie drauf?
function delete_cookie(FitBeach)
{
createCookie(FitBeach,"",-1);
}
// Danach Cookie löschen.
</script>
</b></font>
<br>
<br>
<br>
<a href="http://www.html-world.de/artikel/art_j15.php" target="_blank">
<font color="#000000" face="Arial" size="2">
HTMLWorld - JavaScript Artikel: Cookies in JavaScript<br>
</font>
</a>
</center>
</body>
</html>
--------------------------------------------------