Last active
October 29, 2017 12:58
-
-
Save ydatech/bbfe3c9ceef992ee23efd32a668984c6 to your computer and use it in GitHub Desktop.
Stateless vs Stateful : Tutorial Yudasukmana.web.id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Contoh stateful | |
session_start(); | |
// Dapatkan informasi username dari query parameter kemudian simpan di session | |
// Request pertama kita mengirimkan informasi username melalui query paramater | |
// http://localhost:8080/stateful.php?username=ydatech | |
// Dalam request kedua dan seterusnya kita tidak perlu lagi mengirimkan info username | |
// melalui query parameter karena sudah tersimpan di session | |
// http://localhost:8080/stateful.php | |
function whoAmI(){ | |
if(isset($_GET['username'])){ | |
$_SESSION['username'] = $_GET['username']; | |
} | |
if(isset($_SESSION['username'])){ | |
$username = $_SESSION['username']; | |
echo $username; | |
}else{ | |
throw new Exception("I don't know who you are"); | |
} | |
} | |
whoAmI(); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Contoh StateLess | |
function whoAmI(){ | |
// Dapatkan informasi username dari query parameter | |
// Setiap kali kita ingin mengakses program ini maka kita harus mengirim informasi username | |
// melalui query parameter disetiap request yang dilakukan | |
// Contoh http://localhost:8080/stateless.php?username=ydatech | |
if(isset($_GET['username'])){ | |
$username = $_GET['username']; | |
echo $username; | |
}else{ | |
throw new Exception("I don't know who you are"); | |
} | |
} | |
whoAmI(); | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment