Praktikum 7.1
simpan program dengan nama login.php
<?php
session_start();
if ( isset( $_POST["login"]) ) {
login();
} elseif ( isset ( $_GET["action"]) and $_GET["action"] == "logout") {
logout();
}elseif ( isset ( $_SESSION["username"])) {
displayPage();
}else{
displayLoginForm();
}
function login(){
$username = "ikhwan";
$passwd = "one";
if (isset ( $_POST["username"]) and isset ($_POST["password"])) {
echo $_POST ["username"];
if ($_POST["username"] == $username and $_POST["password"] == $passwd ){
$_SESSION["username"] = $username;
session_write_close();
header("Location : login.php");
}else{
displayLoginForm ("username/password Tidak cocok");
}
}
}
function logout(){
unset($_SESSION["username"]);
session_write_close();
header("Location: login.php");
}
function displayPage(){
displayPageHeader();
?>
<p>Welcome, <strong><?php echo $SESSION["username"] ?></strong> Anda sudah Berhasil Login.</p>
<p><a href="login.php?action=logout">Logout</a></p>
</body>
</html>
<?php
}
function displayLoginForm($message=""){
displayPageHeader();
?>
<?php if($message)
echo '<p class="error">' . $message . '</p>';
?>
<form action="login.php" method="post">
<div style= "width: 30em;">
<label for = "username">Username</label>
<input type="text" name="username" id="username" value=""/>
<label for="password">Password</label>
<input type="password" name="password" id="password" value=""/>
<div style="clear: both;">
<input type="submit" name="login" value="Login"/>
</div>
</div>
</form>
</body>
</html>
<?php
}
function displayPageHeader(){
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<title> A Login Form</title>
<link rel="stylesheet" type="text/css" href="common2.css" />
<style type="text/css">
.error{ background: #d33; color: white; padding: 0.2em; }
</style>
</head>
<body>
<h1>Silahkan Login</h1>
<?php
}
?>
simpan program berikut dengan nama common.css
/*Page Body */
body {font-family : Arial,helvetia,sans-serif;}
/*definition lists*/
dl {
width:100%;
margin:2em 0;
padding: 0;
clear: both;
overflow:auto;
}
dt {
width:30%;
float : left ;
margin:0;
padding: 5px 9.9% 5px 0; 0
order-top:1px solid #DDDDB7;
font-weight:bold;
overflow:auto;
clear:left;
}
dd {
width : 60%;
float :left;
margin:0;
padding:6px 0 5px 0;
border-top:1px solid #DDDDB7;
overflow:auto;
}
/*headings*/
h1{
font-weight:bold;
margin:35px 0 14px;
color:#666;
font-size:1.5em;
}
h2{
font-weight:bold;
margin:30px 0 12px;
color:#666;
font-size:1.3em;
}
h3{
font-weight:normal;
margin:30px 0 12px;
color:#666;
font-size:1.2em;
}
h4{
font-weight:bold;
margin:25px 0 12px;
color:#666;
font-size:1.0em;
}
h5{
font-weight:bold;
margin:25px 0 12px;
color:#666;
font-size:0.9em;
}
/*form*/
label { display:block;
float:left;
clear:both;
text-align:right;
margin:0.6em 5px 0 0;
width: 40%;
}
input,select,textarea {
float:right;
margin:1em 0 0 0;
width:57%;
}
input {
border:1px solid #666;
}
input[type=radio], iinput[type=checkbox],input[type=submit],input[type=reset],input[type=button],input[type=image]{
width:auto;
}
maka outputnya akan seperti berikut:
Tampilan untuk login awal
Setelah di isi akan tampil seperti berikut:
Apabila login berhasil akan tampil seperti berikut
Apabila login gagal maka akan tampil seperti berikut
Rabu, 06 Juni 2012
MODUL 6 WEB FORM
Praktikum 6.1
simpan program dengan nama form-registrasi.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Membership Form</tittle>
<link rel="stylesheet" type="text/css" href="common.css" />
<!--common.cs merupakan code dari buku Beginning PHP 5.3-->
</head>
<body>
<h1>Formulir Pendaftaran</h1>
<form action="registrasi.php" method ="POST">
<div style ="width:30 cm;">
<label for ="nama">Nama</label>
<input type ="text" name ="nama" id="nama" value = ""/>
<label for = "nim">N I M</label>
<input type="text" name ="nim" id ="nim" value ="" />
<label for = "password1">Password</label>
<input type="password" name ="password1" id ="password1" value ="" />
<label for ="laki-laki">Apakah Anda Laki-Laki...</label>
<input type="radio" name="jk" id="Laki-Laki" value ="Laki-Laki"/>
<label for="perempuan">...atau perempuan?</label>
<input type="radio" name="jk" id="perempuan" value="perempuan"/>
<label for ="paket">paket yang anda pilih?</label>
<select name="paket" id="favoriteWidget" size="1">
<option value="platinum">Paket Platinum</option>
<option value="gold">Paket Gold</option>
<option value="silver">Paket Silver</option>
</select>
<input type="submit" name="daftar" id="daftar" value="Daftar"/>
</div>
</form>
</body>
</html>
simpan program dengan nama common.css
/*Page Body */
body {font-family : Arial,helvetia,sans-serif;}
/*definition lists*/
dl {
width:100%;
margin:2em 0;
padding: 0;
clear: both;
overflow:auto;
}
dt {
width:30%;
float : left ;
margin:0;
padding: 5px 9.9% 5px 0; 0
order-top:1px solid #DDDDB7;
font-weight:bold;
overflow:auto;
clear:left;
}
dd {
width : 60%;
float :left;
margin:0;
padding:6px 0 5px 0;
border-top:1px solid #DDDDB7;
overflow:auto;
}
/*headings*/
h1{
font-weight:bold;
margin:35px 0 14px;
color:#666;
font-size:1.5em;
}
h2{
font-weight:bold;
margin:30px 0 12px;
color:#666;
font-size:1.3em;
}
h3{
font-weight:normal;
margin:30px 0 12px;
color:#666;
font-size:1.2em;
}
h4{
font-weight:bold;
margin:25px 0 12px;
color:#666;
font-size:1.0em;
}
h5{
font-weight:bold;
margin:25px 0 12px;
color:#666;
font-size:0.9em;
}
/*form*/
label { display:block;
float:left;
clear:both;
text-align:right;
margin:0.6em 5px 0 0;
width: 40%;
}
input,select,textarea {
float:right;
margin:1em 0 0 0;
width:57%;
}
input {
border:1px solid #666;
}
input[type=radio], iinput[type=checkbox],input[type=submit],input[type=reset],input[type=button],input[type=image]{
width:auto;
}
simpan program dengan nama registrasi.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<title>Membership Form</title>
<link rel="stylesheet" type="text/css" href="common.css" />
</head>
<body>
<h1>Anda Telah Terdaftar</h1>
<p>Berikut adalah data anda:</p>
<dl>
<dt>Nama Anda </dt><dd><?php echo $_POST["nama"]?></dd>
<dt>NIM</dt><dd><?php echo $_POST["nim"]?></dd>
<dt>Password</dt><dd></dd>
<dt>Jenis Kelamin</dt><dd><?php echo $_POST["jk"]?></dd>
<dt>Paket yang anda Pilih</dt><dd><?php echo $_POST["paket"]?></dd>
</dl>
</body>
</html>
maka outoutnya adalah sebagai berikut:
Tampilan awal formulir
Setelah di isi maka outputnya akan seperti berikut:
apabila telah di lakukan penambahan untuk alamat email maka akan seperti berikut :
Apabila login gagal maka outputnya seperti berikut:
apabila ada field yang tidak di isi maka formulir tidak bisa di daftar
Apabila alamat email sudah di isi maka outputnya seperti berikut:
Setelah di lakukan penambahan field seperti password,konfirmasi_password,dan alamat_email
maka tampilan nya seperti berikut
simpan program dengan nama form-registrasi.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Membership Form</tittle>
<link rel="stylesheet" type="text/css" href="common.css" />
<!--common.cs merupakan code dari buku Beginning PHP 5.3-->
</head>
<body>
<h1>Formulir Pendaftaran</h1>
<form action="registrasi.php" method ="POST">
<div style ="width:30 cm;">
<label for ="nama">Nama</label>
<input type ="text" name ="nama" id="nama" value = ""/>
<label for = "nim">N I M</label>
<input type="text" name ="nim" id ="nim" value ="" />
<label for = "password1">Password</label>
<input type="password" name ="password1" id ="password1" value ="" />
<label for ="laki-laki">Apakah Anda Laki-Laki...</label>
<input type="radio" name="jk" id="Laki-Laki" value ="Laki-Laki"/>
<label for="perempuan">...atau perempuan?</label>
<input type="radio" name="jk" id="perempuan" value="perempuan"/>
<label for ="paket">paket yang anda pilih?</label>
<select name="paket" id="favoriteWidget" size="1">
<option value="platinum">Paket Platinum</option>
<option value="gold">Paket Gold</option>
<option value="silver">Paket Silver</option>
</select>
<input type="submit" name="daftar" id="daftar" value="Daftar"/>
</div>
</form>
</body>
</html>
simpan program dengan nama common.css
/*Page Body */
body {font-family : Arial,helvetia,sans-serif;}
/*definition lists*/
dl {
width:100%;
margin:2em 0;
padding: 0;
clear: both;
overflow:auto;
}
dt {
width:30%;
float : left ;
margin:0;
padding: 5px 9.9% 5px 0; 0
order-top:1px solid #DDDDB7;
font-weight:bold;
overflow:auto;
clear:left;
}
dd {
width : 60%;
float :left;
margin:0;
padding:6px 0 5px 0;
border-top:1px solid #DDDDB7;
overflow:auto;
}
/*headings*/
h1{
font-weight:bold;
margin:35px 0 14px;
color:#666;
font-size:1.5em;
}
h2{
font-weight:bold;
margin:30px 0 12px;
color:#666;
font-size:1.3em;
}
h3{
font-weight:normal;
margin:30px 0 12px;
color:#666;
font-size:1.2em;
}
h4{
font-weight:bold;
margin:25px 0 12px;
color:#666;
font-size:1.0em;
}
h5{
font-weight:bold;
margin:25px 0 12px;
color:#666;
font-size:0.9em;
}
/*form*/
label { display:block;
float:left;
clear:both;
text-align:right;
margin:0.6em 5px 0 0;
width: 40%;
}
input,select,textarea {
float:right;
margin:1em 0 0 0;
width:57%;
}
input {
border:1px solid #666;
}
input[type=radio], iinput[type=checkbox],input[type=submit],input[type=reset],input[type=button],input[type=image]{
width:auto;
}
simpan program dengan nama registrasi.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<title>Membership Form</title>
<link rel="stylesheet" type="text/css" href="common.css" />
</head>
<body>
<h1>Anda Telah Terdaftar</h1>
<p>Berikut adalah data anda:</p>
<dl>
<dt>Nama Anda </dt><dd><?php echo $_POST["nama"]?></dd>
<dt>NIM</dt><dd><?php echo $_POST["nim"]?></dd>
<dt>Password</dt><dd></dd>
<dt>Jenis Kelamin</dt><dd><?php echo $_POST["jk"]?></dd>
<dt>Paket yang anda Pilih</dt><dd><?php echo $_POST["paket"]?></dd>
</dl>
</body>
</html>
maka outoutnya adalah sebagai berikut:
Tampilan awal formulir
Setelah di isi maka outputnya akan seperti berikut:
apabila telah di lakukan penambahan untuk alamat email maka akan seperti berikut :
Apabila login gagal maka outputnya seperti berikut:
apabila ada field yang tidak di isi maka formulir tidak bisa di daftar
Apabila alamat email sudah di isi maka outputnya seperti berikut:
Setelah di lakukan penambahan field seperti password,konfirmasi_password,dan alamat_email
maka tampilan nya seperti berikut
MODUL 5 ARRAY
Praktikum 5.1 Array Satu Dimensi
simpan progrsm berikut dengan nama array-demo1.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Praktikum 5 array</tittle><br>
<meta http-equiv="content-type" content="text/html; charsct=utf-8" />
<meta name="generator" content="Geany 0.20" />
</head>
<body>
<?php
//membuat array
$mahasiswa = array("Toni","Joko","Agam","Tina","Lia","Yana");
$ipk = array(3.23,2.89,4.00,3.12,2.67,2.22);
$i = 0;
//mengakses array
echo "<table border = 1>";
echo "<tr>";
echo "<td>No</td>";
echo "<td>Nama</td>";
echo "<td>ipk</td>";
echo "</tr>";
while ($nama = each ($mahasiswa)){
echo "<tr>";
$no = $nama[0] + 1;
echo "<td>$no</td>";
echo "<td>$nama[1]</td>";
echo "<td>$ipk[$i]</td>";
echo "</tr>";
$i++;
}
echo "</table>";
?>
</body>
</html>
maka outputnya seperti berikut:
Praktikum 5.2 Array Multi-Dimensi
simpan progrsm berikut dengan nama multi-array.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Praktikum 5 Array</tittle><br>
<meta http-equiv="content-type" content="text/html; charsct=utf-8" />
<meta name="generator" content="Geany 0.20" />
</head>
<body>
<?php
//membuat array
$mahasiswa = array (
array(
"nama" =>"Toni",
"nim" => "123456789",
"IPK" => 2.79
),
array (
"nama" => "Joko",
"nim" => "234567890",
"IPK" => 2.67
),
array (
"nama" => "Tina",
"nim" => "4567890145",
"IPK" => 2.34
),
array (
"nama" => "Lia",
"nim" => "6789043256",
"IPK" => 3.12
),
array (
"nama" => "Agam",
"nim" => "67452253436",
"IPK" => 4.00
),
array (
"nama" => "Yanna",
"nim" => "345562327844",
"IPK" => 3.56
),
);
echo "<table border=1>";
echo "<tr>";
echo "<td>Nama</td>";
echo "<td>N I M</td>";
echo "<td>IPK</td>";
foreach ($mahasiswa as $nama){
echo "<tr>";
foreach ($nama as $key =>$value){
echo "<td>$value</td>";
}
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>
maka outputnya seperti berikut:
simpan progrsm berikut dengan nama array-demo1.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Praktikum 5 array</tittle><br>
<meta http-equiv="content-type" content="text/html; charsct=utf-8" />
<meta name="generator" content="Geany 0.20" />
</head>
<body>
<?php
//membuat array
$mahasiswa = array("Toni","Joko","Agam","Tina","Lia","Yana");
$ipk = array(3.23,2.89,4.00,3.12,2.67,2.22);
$i = 0;
//mengakses array
echo "<table border = 1>";
echo "<tr>";
echo "<td>No</td>";
echo "<td>Nama</td>";
echo "<td>ipk</td>";
echo "</tr>";
while ($nama = each ($mahasiswa)){
echo "<tr>";
$no = $nama[0] + 1;
echo "<td>$no</td>";
echo "<td>$nama[1]</td>";
echo "<td>$ipk[$i]</td>";
echo "</tr>";
$i++;
}
echo "</table>";
?>
</body>
</html>
maka outputnya seperti berikut:
Praktikum 5.2 Array Multi-Dimensi
simpan progrsm berikut dengan nama multi-array.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Praktikum 5 Array</tittle><br>
<meta http-equiv="content-type" content="text/html; charsct=utf-8" />
<meta name="generator" content="Geany 0.20" />
</head>
<body>
<?php
//membuat array
$mahasiswa = array (
array(
"nama" =>"Toni",
"nim" => "123456789",
"IPK" => 2.79
),
array (
"nama" => "Joko",
"nim" => "234567890",
"IPK" => 2.67
),
array (
"nama" => "Tina",
"nim" => "4567890145",
"IPK" => 2.34
),
array (
"nama" => "Lia",
"nim" => "6789043256",
"IPK" => 3.12
),
array (
"nama" => "Agam",
"nim" => "67452253436",
"IPK" => 4.00
),
array (
"nama" => "Yanna",
"nim" => "345562327844",
"IPK" => 3.56
),
);
echo "<table border=1>";
echo "<tr>";
echo "<td>Nama</td>";
echo "<td>N I M</td>";
echo "<td>IPK</td>";
foreach ($mahasiswa as $nama){
echo "<tr>";
foreach ($nama as $key =>$value){
echo "<td>$value</td>";
}
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>
maka outputnya seperti berikut:
MODUL 4 PERULANGAN
Praktikum 4.1 Percabangan while
simpan program dengan nama struktur-while.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Praktikum 4.Perulangan</tittle><br>
<meta http-equiv="content-type" content="text/html; charsct=utf-8" />
<meta name="generator" content="Geany 0.20" />
</head>
<body>
<?php
$tinggi = 10 ;
$i = 0;
while ($i < $tinggi){
$j = 0;
while($j<=$i){
echo "*";
$j++;
}
echo "<br>";
$i++;
}
?>
</body>
</html>
maka outputnya sebagai berikut:
Praktikum 4.2 Percabangan do while
simpan program dengan nama struktur-do-while.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Praktikum 4.Perulangan</tittle><br>
<meta http-equiv="content-type" content="text/html; charsct=utf-8" />
<meta name="generator" content="Geany 0.20" />
</head>
<body>
<?php
$i=0;
do {
$j = 0;
while($j < $i){
echo "*";
$j++;
}
echo "<br>";
$i++;
}while($i<=10);
?>
</body>
</html>
maka outputnya sebagai berikut:
simpan program dengan nama cek-bilangan.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Praktikum 4.Perulangan</tittle><br>
<meta http-equiv="content-type" content="text/html; charsct=utf-8" />
<meta name="generator" content="Geany 0.20" />
</head>
<body>
<?php
$x = 100;
while ($x > 0){
if ($x % 2 ==0){
echo "$x adalah bilangan Genap";
}else{
echo "$x adalah bilangan <b>Ganjil</b>";
}
echo "<br>";
$x--;
}
?>
</body
</html>
maka outputnya sebagai berikut:
Praktikum 4.3 Perulangan for
simpan program dengan nama perulangan-for.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Praktikum 4.Perulangan</tittle><br>
<meta http-equiv="content-type" content="text/html; charsct=utf-8" />
<meta name="generator" content="Geany 0.20" />
</head>
<body>
<?php
$tinggi = 10;
$i = 0;
for ($i = 0 ; $i <= $tinggi ; $i++){
for ($j = 0 ; $j < $i ; $j++ ){
echo "*";
}
echo "<br>";
}
?>
</body>
</html>
maka outputnya sebagai berikut:
MODUL 3 PERCABANGAN
Praktikum 3.1 Percabangan if
simpan program dengan nama struktur-if.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Praktikum 3. Struktur Kontrol</tittle>
<meta http-equiv="content-type" content="text/html; charsct=utf-8" />
<meta name="generator" content="Geany 0.20" />
</head>
<body>
<?php
$stok_roti = 100;
if($stok_roti <= 50){
echo '<script language= "javascript"> alert ("Stock Roti sudah menipis")</script>';
}
?>
</body>
</html>
maka output akan seperti ini:
Praktikum 3.2 percabangan if...else
simpan program dengan nama struktur-if-else.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Praktikum 3. Struktur Kontrol</tittle>
<meta http-equiv="content-type" content="text/html; charsct=utf-8" />
<meta name="generator" content="Geany 0.20" />
</head>
<body>
<?php
$umur = 12;
if (($umur < 20) && ($umur > 10)){
echo 'Anda masih remaja';
}
?>
</body>
</html>
maka output akan seperti ini:
Praktikum 3.3 Percabangan if...else if...else
simpan program dengan nama struktur if-else-if.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Praktikum 3. Struktur Kontrol</tittle>
<meta http-equiv="content-type" content="text/html; charsct=utf-8" />
<meta name="generator" content="Geany 0.20" />
</head>
<body>
<?php
$bulan_lahir = 6;
if ($bulan_lahir == 1){
echo 'Anda lahir di bulan januari';
}else if ($bulan_lahir == 2){
echo 'Anda lahir di bulan Februari';
}else if ($bulan_lahir == 3){
echo 'Anda lahir di bulan Maret';
}else if ($bulan_lahir == 4){
echo 'Anda lahir di bulan April';
}else if ($bulan_lahir == 5){
echo 'Anda lahir di bulan Mei';
}else if ($bulan_lahir == 6){
echo 'Anda lahir di bulan Juni';
}else if ($bulan_lahir == 7){
echo 'Anda lahir di bulan Juli';
}else if ($bulan_lahir == 8){
echo 'Anda lahir di bulan Agustus';
}else if ($bulan_lahir == 9){
echo 'Anda lahir di bulan September';
}else if ($bulan_lahir == 10){
echo 'Anda lahir di bulan Oktober';
}else if ($bulan_lahir == 11){
echo 'Anda lahir di bulan November';
}else if ($bulan_lahir == 12){
echo 'Anda lahir di bulan Desember';
}else{
echo 'Bulan yang anda masukkan salah';
}
?>
</body>
</html>
maka output akan seperti ini:
Praktikum 3.4 Percabangan if bersarang
simpan program dengan nama struktur nested-if.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Praktikum 3. Struktur Kontrol</tittle>
<meta http-equiv="content-type" content="text/html; charsct=utf-8" />
<meta name="generator" content="Geany 0.20" />
</head>
<body>
<?php
$tanggal_lahir = 16;
$bulan_lahir = 6;
switch ($bulan_lahir){
case 1:
if($tanggal_lahir <= 20)
echo 'Anda Berzodiak <b>CAPRICON</b>';
else
echo 'Anda Berzodiak <b>AQUARIUS</b>';
break;
case 2:
if($tanggal_lahir <= 19)
echo 'Anda Berzodiak <b>AQUARIUS</b>';
else
echo 'Anda Berzodiak <b>PISCES</b>';
break;
case 3:
if($tanggal_lahir <= 20)
echo 'Anda Berzodiak <b>PISCES</b>';
else
echo 'Anda Berzodiak <b>ARIES</b>';
break;
case 4:
if($tanggal_lahir <= 19)
echo 'Anda Berzodiak <b>ARIES</b>';
else
echo 'Anda Berzodiak <b>TAURUS</b>';
break;
case 5:
if($tanggal_lahir <= 20)
echo 'Anda Berzodiak <b>TAURUS</b>';
else
echo 'Anda Berzodiak <b>GEMINI</b>';
break;
case 6:
if($tanggal_lahir <= 21)
echo 'Anda Berzodiak <b>GEMINI</b>';
else
echo 'Anda Berzodiak <b>CANCER</b>';
break;
case 7:
if($tanggal_lahir <= 22)
echo 'Anda Berzodiak <b>CANCER</b>';
else
echo 'Anda Berzodiak <b>LEO</b>';
break;
case 8:
if($tanggal_lahir <= 23)
echo 'Anda Berzodiak <b>LEO</b>';
else
echo 'Anda Berzodiak <b>VIRGO</b>';
break;
case 9:
if($tanggal_lahir <= 22)
echo 'Anda Berzodiak <b>VIRGO</b>';
else
echo 'Anda Berzodiak <b>LIBRA</b>';
break;
case 10:
if($tanggal_lahir <= 23)
echo 'Anda Berzodiak <b>LIBRA</b>';
else
echo 'Anda Berzodiak <b>SCORPIO</b>';
break;
case 11:
if($tanggal_lahir <= 22)
echo 'Anda Berzodiak <b>SCORPIO</b>';
else
echo 'Anda Berzodiak <b>SAGITARIUS</b>';
break;
case 12:
if($tanggal_lahir <= 21)
echo 'Anda Berzodiak <b>SAGITARIUS</b>';
else
echo 'Anda Berzodiak <b>CAPRICON</b>';
break;
default:
echo 'Zodiak Tidak Terdaftar';
break;
}
?>
</body>
</html>
maka output akan seperti ini:
Praktikum 3.5 Percabangan switch...case
simpan program dengan nama struktur-switch.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Praktikum 3. Struktur Kontrol</tittle>
<meta http-equiv="content-type" content="text/html; charsct=utf-8" />
<meta name="generator" content="Geany 0.20" />
</head>
<body>
<?php
$hari_ini = 'Rabu';
switch ($hari_ini){
case 'Senin':
echo 'Hari Senin';
break;
case 'Selasa':
echo 'Hari Selasa';
break;
case 'Rabu':
echo 'Hari Rabu';
break;
case 'Kamis':
echo 'Hari Kamis';
break;
case 'Jumat':
echo 'Hari jumat';
break;
case 'Sabtu':
echo 'Hari Sabtu';
break;
case 'Minggu':
echo 'Hari Minggu';
break;
default:
echo 'Hari Tidak Terdaftar';
break;
}
?>
</body>
</html>
maka output akan seperti ini:
simpan program dengan nama struktur-if.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Praktikum 3. Struktur Kontrol</tittle>
<meta http-equiv="content-type" content="text/html; charsct=utf-8" />
<meta name="generator" content="Geany 0.20" />
</head>
<body>
<?php
$stok_roti = 100;
if($stok_roti <= 50){
echo '<script language= "javascript"> alert ("Stock Roti sudah menipis")</script>';
}
?>
</body>
</html>
maka output akan seperti ini:
Praktikum 3.2 percabangan if...else
simpan program dengan nama struktur-if-else.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Praktikum 3. Struktur Kontrol</tittle>
<meta http-equiv="content-type" content="text/html; charsct=utf-8" />
<meta name="generator" content="Geany 0.20" />
</head>
<body>
<?php
$umur = 12;
if (($umur < 20) && ($umur > 10)){
echo 'Anda masih remaja';
}
?>
</body>
</html>
maka output akan seperti ini:
Praktikum 3.3 Percabangan if...else if...else
simpan program dengan nama struktur if-else-if.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Praktikum 3. Struktur Kontrol</tittle>
<meta http-equiv="content-type" content="text/html; charsct=utf-8" />
<meta name="generator" content="Geany 0.20" />
</head>
<body>
<?php
$bulan_lahir = 6;
if ($bulan_lahir == 1){
echo 'Anda lahir di bulan januari';
}else if ($bulan_lahir == 2){
echo 'Anda lahir di bulan Februari';
}else if ($bulan_lahir == 3){
echo 'Anda lahir di bulan Maret';
}else if ($bulan_lahir == 4){
echo 'Anda lahir di bulan April';
}else if ($bulan_lahir == 5){
echo 'Anda lahir di bulan Mei';
}else if ($bulan_lahir == 6){
echo 'Anda lahir di bulan Juni';
}else if ($bulan_lahir == 7){
echo 'Anda lahir di bulan Juli';
}else if ($bulan_lahir == 8){
echo 'Anda lahir di bulan Agustus';
}else if ($bulan_lahir == 9){
echo 'Anda lahir di bulan September';
}else if ($bulan_lahir == 10){
echo 'Anda lahir di bulan Oktober';
}else if ($bulan_lahir == 11){
echo 'Anda lahir di bulan November';
}else if ($bulan_lahir == 12){
echo 'Anda lahir di bulan Desember';
}else{
echo 'Bulan yang anda masukkan salah';
}
?>
</body>
</html>
maka output akan seperti ini:
Praktikum 3.4 Percabangan if bersarang
simpan program dengan nama struktur nested-if.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Praktikum 3. Struktur Kontrol</tittle>
<meta http-equiv="content-type" content="text/html; charsct=utf-8" />
<meta name="generator" content="Geany 0.20" />
</head>
<body>
<?php
$tanggal_lahir = 16;
$bulan_lahir = 6;
switch ($bulan_lahir){
case 1:
if($tanggal_lahir <= 20)
echo 'Anda Berzodiak <b>CAPRICON</b>';
else
echo 'Anda Berzodiak <b>AQUARIUS</b>';
break;
case 2:
if($tanggal_lahir <= 19)
echo 'Anda Berzodiak <b>AQUARIUS</b>';
else
echo 'Anda Berzodiak <b>PISCES</b>';
break;
case 3:
if($tanggal_lahir <= 20)
echo 'Anda Berzodiak <b>PISCES</b>';
else
echo 'Anda Berzodiak <b>ARIES</b>';
break;
case 4:
if($tanggal_lahir <= 19)
echo 'Anda Berzodiak <b>ARIES</b>';
else
echo 'Anda Berzodiak <b>TAURUS</b>';
break;
case 5:
if($tanggal_lahir <= 20)
echo 'Anda Berzodiak <b>TAURUS</b>';
else
echo 'Anda Berzodiak <b>GEMINI</b>';
break;
case 6:
if($tanggal_lahir <= 21)
echo 'Anda Berzodiak <b>GEMINI</b>';
else
echo 'Anda Berzodiak <b>CANCER</b>';
break;
case 7:
if($tanggal_lahir <= 22)
echo 'Anda Berzodiak <b>CANCER</b>';
else
echo 'Anda Berzodiak <b>LEO</b>';
break;
case 8:
if($tanggal_lahir <= 23)
echo 'Anda Berzodiak <b>LEO</b>';
else
echo 'Anda Berzodiak <b>VIRGO</b>';
break;
case 9:
if($tanggal_lahir <= 22)
echo 'Anda Berzodiak <b>VIRGO</b>';
else
echo 'Anda Berzodiak <b>LIBRA</b>';
break;
case 10:
if($tanggal_lahir <= 23)
echo 'Anda Berzodiak <b>LIBRA</b>';
else
echo 'Anda Berzodiak <b>SCORPIO</b>';
break;
case 11:
if($tanggal_lahir <= 22)
echo 'Anda Berzodiak <b>SCORPIO</b>';
else
echo 'Anda Berzodiak <b>SAGITARIUS</b>';
break;
case 12:
if($tanggal_lahir <= 21)
echo 'Anda Berzodiak <b>SAGITARIUS</b>';
else
echo 'Anda Berzodiak <b>CAPRICON</b>';
break;
default:
echo 'Zodiak Tidak Terdaftar';
break;
}
?>
</body>
</html>
maka output akan seperti ini:
Praktikum 3.5 Percabangan switch...case
simpan program dengan nama struktur-switch.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="on" lang="on">
<head>
<tittle>Praktikum 3. Struktur Kontrol</tittle>
<meta http-equiv="content-type" content="text/html; charsct=utf-8" />
<meta name="generator" content="Geany 0.20" />
</head>
<body>
<?php
$hari_ini = 'Rabu';
switch ($hari_ini){
case 'Senin':
echo 'Hari Senin';
break;
case 'Selasa':
echo 'Hari Selasa';
break;
case 'Rabu':
echo 'Hari Rabu';
break;
case 'Kamis':
echo 'Hari Kamis';
break;
case 'Jumat':
echo 'Hari jumat';
break;
case 'Sabtu':
echo 'Hari Sabtu';
break;
case 'Minggu':
echo 'Hari Minggu';
break;
default:
echo 'Hari Tidak Terdaftar';
break;
}
?>
</body>
</html>
maka output akan seperti ini:
Langganan:
Postingan (Atom)