Professional Documents
Culture Documents
Hypertext Preprocessor
DHTML
Using Array:ا لمصفوفات
PHP supports two kinds of array:
1. Indexed ف هرس: which use numbers as the key, as follow:
ترتيب في شكل
ارقام
ترتيب في شكل
نصوص
Some of Array methods:
method Description example
count() , sizeof() determine the number of $num=count($arr);
elements in an array
range() used to create an array of $alpha=range(‘a’,’z’);
sequential letters
sort() sorts an array by values sort ($arr);
discarding the original key,
?> • Friday
ex(2): using array- Associative array
<?php
# display.php
//using Associative array
$day[‘sat’] = 'Saturday';
$day[‘mon’] = ‘Monday';
$day[‘wen’] = ‘Wednesday';
?>
ex(3): using array- range & count methods
<?php
# year.php //define values
$year = range (‘2000’,’2020’);
echo (“Array elements are :”);
foreach ( $year as $key)
echo(“<br />”. $key);
?> http://localhost/year.php
Array elements are:
2000
2001
2002
.....
2019
2020
The number of element= 21
Global-request-related automatic variables:
$_GET : is an array of variable names and values sent
by the HTTP GET method.
GET_$ عبارة متغيرات من نوع
$_POST: is an array of variable names and values sent
by the HTTP POST method.
POST_$ عبارة متغيرات من نوع
$_REQUEST: works for both GET and POST method.
) معاGET and POST(عبارة عن دالة يستخدم
$_COOKIE: is an array Stores cookie data.
في شكل مصفوفةcookie يتم تخزين البيانات
$_SESSION: is an array Stores session data.
في شكل مصفوفةsession يتم تخزين البيانات
PHP From processing:
$_GET and $_POST variables are used to retrieve
information from forms.ي ستخدم ال رجاع ا لمعلوماتمنا لنموذج
$_REQUEST variable used to get the form’s data that sent with both the GET and POST methods.
Form.html
Login Form
Username:
Password:
Submit
ex : using Post method
<!-- Form.html -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Using post variables - Login Form </title>
<body>
<h3> Login Form </h3>
<form action = “welcome.php" method= "post“ >
<label> Name : </label>
<input type= "text" name="username"> <br/>
<label> Password: </label>
<input type= “password” name= “password” /> <br/>
<input name=“b” type=“submit” value= “Submit” />
</form>
</body>
</html>
ex : using Post methodاستخدام
In “welcome.php” we can retrieve the form elements
using $_POST variable:
<?php
# welcome.php
$user = $_POST ["username"];
$passwd = $_POST ["password"];
echo (“ Welcome $user “);
echo(“ <br /> your Password is : $passwd “);
?>
http://localhost/Form.html http://localhost/welcome.php
1 Login Form 2
Username: sustech Welcome sustech
Password: **** your Password is :1234
Submit
PHP Cookies: $_COOKIE
A cookie is a small file that the server embeds on the
user's computer.عبارة عنملفص غير ي كونف يجهازا لمستخدم
it is often used to identify a user.غا لبا ما ي ستخدم ل تع ريفا لمستخدم
Creating cookie by setcookie(variable,value) cookie انشاء
<?php setcookie ("user", "Alex Porter"); ?>
http://localhost/check.php
<?php
// check.php Print a cookie
Alex Porter
echo ( $_COOKIE["user"] );
// A way to view all cookies
Array ( [user] => Alex Porter )
print_r ($_COOKIE);
?>
PHP Session: $_SESSION
PHP session variable is used to store information about user, or
change settings for a user sessionعبارة عنت خزينا لمعلوماتعنا لمستخدم
$_SESSION[‘view’] ++;
Login Form
Username:
Password:
Submit