PDA

View Full Version : Apa maksud cookies??



manasayatau
14-09-12, 01:50 PM
Saya nak tanya soalan basic ... apa itu cookies dan apa fungsi dia???

PenyuGentle
14-09-12, 02:10 PM
cookies ada lah sejenis biskut, sedap dimakan bila rangup... bila lemau jadi tidak sdap, hilang enaknya... miahahahaha... google la ok x?

A message given to a Web browser (http://www.webopedia.com/TERM/B/browser.html) by a Web server (http://www.webopedia.com/TERM/W/Web_server.html). The browser stores the message in a text file (http://www.webopedia.com/TERM/T/text_file.html). The message is then sent back to the server each time the browser requests a page from the server.
Also see session cookie (http://www.webopedia.com/TERM/S/session_cookie.html) and persistent cookie (http://www.webopedia.com/TERM/P/persistent_cookie.html).
The main purpose of cookies is to identify users and possibly prepare customized Web pages (http://www.webopedia.com/TERM/W/web_page.html) for them. When you enter a Web site (http://www.webopedia.com/TERM/W/web_site.html) using cookies, you may be asked to fill out a form providing such information as your name and interests. This information is packaged into a cookie and sent to your Web browser which stores it for later use. The next time you go to the same Web site, your browser will send the cookie to the Web server. The server can use this information to present you with custom Web pages. So, for example, instead of seeing just a generic welcome page you might see a welcome page with your name on it.

private
14-09-12, 05:28 PM
cookies = identiti yang memegang/mengandungi maklumat-maklumat tentang sesuatu objek/request/session dan sebagainya.

Ia diperlukan oleh web/server/identifier/caller/function dan sebagainya utk communicate atau sebagai rujukan atau sbg pengenalan.

cth pengunaan cookies yg paling mudah ialah masa login.

apabila user login, maka webserver akan create satu session iaitu session_start() utk pegang dan check maklumat username dan password agar sama dgn rekod yang ada dlm database semasa kita register.. So jika maklumat username dan password sama, maka session tu akan menghasilkan cookies dlm btk md5 or other encrypted text format..dan cookies ni akan disimpan kt webserver dan browser kita. Setelah user klik logout, maka cookies ni akan terhapus dgn session_destroy().

cth code login:


<?php
session_start();
if(!session_is_registered(username)){
echo 'Login berjaya';
}
?>

cth code logout :


<?php
session_start();
session_destroy();
?>