Professional Documents
Culture Documents
State Handling
$_COOKIE["cookie-name"];
<?php
$user = $_COOKIE["user"];
?>
Questions About Cookie
§ Is it secure?
§ Is it OK to put sensitive data into cookie?
§ How to secure it?
Session
Session
§ With session, users are allowed to store
information on the server for later use (i.e.
username, shopping item, question answer, etc)
§ Session information is stored temporarily on the
server and will be deleted if it is destroyed or after
the user has left the website for a specified time.
Session (2)
§ Sessions work by creating a unique id
(PHPSESSID) for each visitor and store variables
based on this PHPSESSID.
§ While variables contained in a session stored
securely on the server, this PHPSESSID value is
stored on the client computer as a cookie in order
to be able to keep track with the client, if cookies
are disabled, PHPSESSID value is stored in the
URL as a query string.
Using Session
§ Starting session
<?php session_start(); ?>
§ Storing session
<?php
session_start(); // don't forget!
$_SESSION['status']=1;
?>
§ Retrieving a session variable (in another PHP file)
<?php
session_start();
echo "User status " . $_SESSION['status'];
?>
Using Sessions
§ Removing one session variable
<?php
session_start(); // don't forget!
if(isset($_SESSION['status']))
unset($_SESSION['status']);
?>
§ Destroying the whole user’s session
<?php
session_destroy();
?>
Questions?
Questions?
Tugas
§ Kembangkan file form yang dibuat dengan
menambahkan input untuk upload file gambar.
§ Tampilkan isian yang dimasukkan ke dalam form
melalui sebuah file tampil.php dengan format
tampilan seperti yang disepakati di kelas.
§ Silakan "percantik" tampilan dengan
menggunakan CSS
Tugas
§ Simpan file form.html, tampil.php, dan *.css yang
digunakan ke dalam 1 file:
tugas-post-upload.zip
§ Kirim sebagai attachment email dengan subject:
PW: Tugas 4 - Tugas Post Upload
§ Kirim sebelum
Senin, 27 Maret 2017 pukul 20:00 WIB
§ Tugas ini adalah tugas perorangan.
Tugas A
§ Buatlah sebuah program berbasis web dengan
menggunakan PHP yang mencatat berapa kali
sebuah halaman web tertentu dibuka.
§ Buat sebuah program lain yang menampilkan
kapan saja halaman web tersebut dibuka.
§ Gunakan SESSION atau COOKIE.
Tugas B
§ Buatlah sebuah program berbasis web dengan
menggunakan PHP yang mencatat web browser
apa yang digunakan pengguna.
§ Tampilkan pesan ucapan selamat
pagi/siang/sore/malam sesuai kapan halaman
tersebut diakses beserta web browser yang
digunakan.
§ Gunakan SESSION atau COOKIE
Tugas A atau B
§ Subject Email: PW: Tugas 5 - State
§ Sebelum: 4 April 2017 02:00 WIB
§ Tugas ini adalah tugas maksimal per-2-orangan.
§ Kirimkan file:
§ PHP, HTML, dan CSS
§ Beserta screenshot-nya
§ Dalam 1 file ZIP: tugas-state.zip