Presentation is loading. Please wait.

Presentation is loading. Please wait.

Cookie and Session Bayu Priyambadha, S.Kom.

Similar presentations


Presentation on theme: "Cookie and Session Bayu Priyambadha, S.Kom."— Presentation transcript:

1 Cookie and Session Bayu Priyambadha, S.Kom

2 What is Cookie? Data saving mechanism Saved in user/client computer
Containt of teks data Transmit as a HTTP Header Has an active time Has a function : Identification client Authentication client

3 PHP Cookie PHP function : Example : setcookie(name, value, expire);
$value = 'something from somewhere'; setcookie("TestCookie", $value, time()+3600);   ?>

4 Read Cookie Using : Example : $_COOKIE[“nama_cookie”] <?php
echo $_COOKIE("TestCookie");   ?>

5 Try This!!! <html> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php if (!isset($_COOKIE["nama_client"])) { ?> <form action="proses.php" method="post"> Nama : <input type="text" name="nama" /><br /> <input type="submit" value="Go" /> </form> <? } else echo "Ini dia nama client-nya : ".$_COOKIE["nama_client"]; </body> </html>

6 Try This!!! (2) <?php setcookie("nama_client",$_POST["nama"],time()+120); ?>

7 Session Session is same as cookie, but this mechanism store data to the server Must be started with : session_start() Example : <?php session_start(); $_SESSION['views'] = 1; echo "Pageviews = ". $_SESSION['views']; ?>

8


Download ppt "Cookie and Session Bayu Priyambadha, S.Kom."

Similar presentations


Ads by Google