Professional Documents
Culture Documents
What is an Variable?
A variable is a storage area holding a number or text.
The problem is, a variable will hold only one value.
What is an Array?
An array is a special variable, which can store multiple
values in one single variable.
$datakuliah
$datakuliah
$datakuliah
$datakuliah
datakuliah
datakuliah
Anto
Anto
sort
rsort
asort -- elemen
arsort
ksort -- key
krsort
natsort -- man
array_reverse
array_pop
array_push
array_shift
array_unshift
array_rand
array_unique
in_array
shuffle
range
explode
implode
Example:
Form:
<form action="welcome.php" method="get">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
Address Bar:
welcome.php?fname=Peter&age=37
Welcome.php:
Welcome <?php echo $_GET["fname"]; ?>.<br />
You are <?php echo $_GET["age"]; ?> years old!
Example:
Form:
<form action="welcome.php" method="post">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
Address Bar:
welcome.php
Welcome.php:
Welcome <?php echo $_POST["fname"]; ?>.<br />
You are <?php echo $_POST["age"]; ?> years old!
<form method="POST"
name="myform"
action="form.php">
Nama = <input
type="text" name="txtnama"
size="20"><br>
<input type="button"
value="Simpan" name="simpan"
onClick="huruf(this.form)"><inp
ut type="reset" value="Reset"
name="B2">
</form>
<script>
function check(form) {
if(form.txtnama.value=="") {
alert("Nama belum diisi!");
form.txtnama.focus();
return false;
} else
return true;
}
function huruf(form) {
if (check(form)) {
if(!isNaN(form.txtnama.value)) {
alert("Nama harus
huruf!");
form.txtnama.focus();
return false;
} else
form.submit();
return true;
}
}
document.myform.txtnama.focus();
</script>
<body>
<?php
echo "Nama Anda ".$_POST['txtnama'];
?>
</body>
Legal access
Direct access
<body>
<?php
if(isset($_POST['txtnama'])) {
echo "Nama Anda : ".$_POST['txtnama'];
}
?>
</body>
Legal access
Direct access
<body>
<?php
if(isset($_POST['txtnama'])) {
echo "Nama Anda : ".$_POST['txtnama'];
} else {
echo "Illegal Access is not allowed!";
}
?>
</body>
Legal access
Direct access
<body>
<?php
if(isset($_POST['txtnama'])) {
echo "Nama Anda : ".$_POST['txtnama'];
} elseif(isset($_GET['txtnama'])) {
echo $_GET['txtnama'].", this method is not allowed!";
} else {
echo "Illegal Access is not allowed!";}
?>
</body>
<html>
<body>
<?php include("header3.php"); ?>
<h1>Selamat Datang!</h1>
<p>hehehe....</p>
</body>
</html>
<html>
<body>
<?php require("header3.php"); ?>
<h1>Selamat Datang!</h1>
<p>hehehe....</p>
</body>
</html>
Example:
<?php
?>
<?php
?>
var.php
$var = "nilai var ke-1<br/>";
include_once.php
include("var.php");
echo $var;
$var = "nilai var ke-2<br/>";
echo $var;
include_once("var.php");
echo $var;
Example:
<?php
?>
<?php
?>
var.php
require("var.php");
echo $var;
$var = "nilai var ke-2<br/>";
echo $var;
require_once("var.php");
echo $var;
What is a Cookie?
A cookie is a small file that the server embeds on the user's
computer.
Example:
<?php
setcookie(nama, Alex Porter);
?>
<html>
<body>
</body>
</html>
nama
nama
Expiration
setcookie(cookie_name, cookie_value, expired_date);
setcookie nama
()+3600);
$_SESSION[session_name]=session_value;
Example
$_
$
nama
nama
nama
nama
nama
nama