Some Basic Concepts of COOKIES "Beberpa Konsep Dasar Coockies" post new 2011


Some Basic Concepts of COOKIES


Beberpa Konsep Dasar Coockies

What is a Cookie?

A cookie is often used to identify a user. A cookie is a small file that the server
embeds on the user’s computer. Each time the same computer requests a page with a browser, it will send the cookie
too. With ASP, you can both create and retrieve cookie values.

How to Create a Cookie?

The "Response.Cookies" command is used to create cookies.
Note: The Response.Cookies command must appear BEFORE the <html> tag.
In the example below, we will create a cookie named "firstname" and assign the value "Alex" to it:
<%
Response.Cookies("firstname")="Alex"
%>
It is also possible to assign properties to a cookie, like setting a date when the cookie should expire:
<%
Response.Cookies("firstname")="Alex"
Response.Cookies("firstname").Expires=#May 10,2012#
%>

How to Retrieve a Cookie Value?

The "Request.Cookies" command is used to retrieve a cookie value.
In the example below, we retrieve the value of the cookie named "firstname" and display it on a page:
<%
fname=Request.Cookies("firstname")
response.write("Firstname=" & fname)
%>
Output: Firstname=Alex

A Cookie with Keys

If a cookie contains a collection of multiple values, we say that the cookie has Keys.
In the example below, we will create a cookie collection named "user".
The "user" cookie has Keys that contains information about a user:
<%
Response.Cookies("user")("firstname")="John"
Response.Cookies("user")("lastname")="Smith"
Response.Cookies("user")("country")="Norway"
Response.Cookies("user")("age")="25"
%>

Read all Cookies

Look at the following code:
<%
Response.Cookies("firstname")="Alex"
Response.Cookies("user")("firstname")="John"
Response.Cookies("user")("lastname")="Smith"
Response.Cookies("user")("country")="Norway"
Response.Cookies("user")("age")="25"
%>
Assume that your server has sent all the cookies above to a user.
Now we want to read all the cookies sent to a user. The example below shows
how to do it (note that the code below checks if a cookie has Keys with the HasKeys property):
<html>
<body>
<%
dim x,y
for each x in Request.Cookies
response.write("<p>")
if Request.Cookies(x).HasKeys then
for each y in Request.Cookies(x)
response.write(x & ":" & y & "=" & Request.Cookies(x)(y))
response.write("<br />")
next
else
Response.Write(x & "=" & Request.Cookies(x) & "<br />")
end if
response.write "</p>"
next
%>
</body>
</html>
Output:
firstname=Alex
user:firstname=John
user:lastname=Smith
user:country=Norway
user:age=25

Translate Into Indonesian
Apa itu Cookie?
Cookie sering digunakan untuk mengidentifikasi pengguna. Cookie adalah file kecil yang serverkomprehensif pada komputer pengguna. Setiap kali permintaan komputer yang sama halaman dengan browser, ia akan mengirim cookiejuga. Dengan ASP, Anda berdua bisa membuat dan mengambil nilai cookie.
><><><><><><
Cara Membuat Cookie?
 "Response.Cookies" perintah ini digunakan untuk membuat cookie.
Catatan: Perintah Response.
Cookies harus muncul SEBELUM tag <html>.
Pada contoh di bawah, kita akan menciptakan sebuah cookie bernama "firstname" dan menetapkan nilai "Alex" untuk itu:
<%
Response.Cookies ("firstname") = "Alex"
%>
Hal ini juga mungkin untuk menetapkan properti untuk cookie, seperti pengaturan tanggal ketika cookie harus berakhir:
<%
Response.Cookies ("firstname") = "Alex"
Response.Cookies ("Nama depan"). Habis = # May 10,2012 #
%>
><><><><><>
Cara Ambil Nilai Cookie?
 "Request.Cookies" Perintah ini digunakan untuk mengambil nilai cookie.
Pada contoh di bawah, kita mengambil nilai dari cookie bernama "firstname" dan menampilkannya pada satu halaman:
<%
fname=Request.Cookies("firstname")
response.write("Firstname=" & fname)
%>
Output: Firstname=Alex
><<><><><

Sebuah Cookie dengan Tombol
Jika cookie berisi kumpulan beberapa nilai, kita mengatakan bahwa cookie telah Keys.Pada contoh di bawah, kita akan membuat koleksi cookie bernama "pengguna"."Pengguna" cookie telah Keys yang berisi informasi tentang pengguna:
<%
Response.Cookies("user")("firstname")="John"
Response.Cookies("user")("lastname")="Smith"
Response.Cookies("user")("country")="Norway"
Response.Cookies("user")("age")="25"
%>

><><><><><>
Baca semua CookieLihatlah kode berikut:
<%
Response.Cookies ("firstname") = "Alex"
Response.Cookies ("user") ("firstname") = "John"
Response.Cookies ("user") ("NamaBelakang") = "Smith"
Response.Cookies ("user") ("negara") = "Norwegia"
Response.Cookies ("user") ("umur") = "25"
%>
Asumsikan bahwa server Anda telah mengirimkan semua cookie di atas untuk pengguna.Sekarang kita ingin membaca semua cookie dikirim ke pengguna. Contoh di bawah ini menunjukkanbagaimana melakukannya (perhatikan bahwa kode di bawah ini memeriksa apakah cookie telah Tombol dengan properti HasKeys)
:<html>
<body>
<%
redup x, y
untuk setiap x di Request.
Cookiesresponse.write ("<p>")
jika Request.Cookies (x). HasKeys kemudian
untuk setiap y dalam Request.Cookies (x)
response.write (x & ":" & y & "=" & Request.
Cookies (x) (y))response.write ("<br />")
selanjutnyalainResponse.
Write (x & "=" & Request.Cookies (x) & "<br />")
akhir jika
response.write "</ p>"selanjutnya
%>
</ body>
</ html>
Output:
firstname=Alex
user:firstname=John
user:lastname=Smith
user:country=Norway
user:age=25

by Rafi Aldiansyah Asikin
Jika ingin mengcopy artikel ini sertakan alamat blog ini
Terima Kasih
Previous
Next Post »