Sei sulla pagina 1di 7

‫لغة ‪PHP‬‬

‫م‪.‬ماجد الجمية ‪00963955335369 /‬‬


‫المحاضرة ( ‪) 12‬‬
‫م‪ .‬ماجد الجمية‬

‫‪1‬‬
Variable Scope
The scope of a variable is the context within which it is defined.
<?php
$a = 1; /* limited variable scope */
function Test()
{
echo $a; The scope is local within functions,
/* reference to local scope variable */
}
and hence the value of $a is
Test(); undefined in the “echo” statement.
?>

<?php <?php
$a = 1; function Test()
$b = 2; global {
function Sum() static
static $a = 0;
{
global $a, $b; refers to its echo $a;
does not lose
$a++;
$b = $a + $b; global } its value.
}
Sum();
version. Test1();
Test1();
echo $b; Test1();
?> ?>
Cookie Workings
setcookie(name,value,expire,path,domain) creates cookies.
<?php
setcookie("uname", $_POST["name"], time()+36000);
?>
<html>
<body>
<p>
NOTE:
Dear <?php echo $_POST["name"] ?>, a cookie was set on this setcookie() must appear
page! The cookie will be active when the client has sent the
cookie back to the server. BEFORE <html> (or
</p>
</body>
any output) as it’s part
</html> of the header
information sent with
the page.
<html>
<body> $_COOKIE
<?php
if ( isset($_COOKIE["uname"]) )
contains all COOKIE data.
echo "Welcome " . $_COOKIE["uname"] . "!<br />";
else isset()
echo "You are not logged in!<br />"; finds out if a cookie is set
?>
</body>
</html>
use the cookie name as a
variable
‫وظيفة‬
‫• قم بإنشاء موقع دليل هاتف باستخدام من تقنيات ما تعلمتها من قبل‬
‫• ذو االمكانيات التالية‬
‫الدخول باسم مستخدم وكلمة مسر والتحقق من كونه مسجل من قبل الموقع‬ ‫•‬
‫تخزين االسم ‪ +‬رقم الهاتف ‪ +‬رقم الجوال ‪ +‬العنوان ‪ +‬االيميل‬ ‫•‬

‫م‪.‬ماجد الجمية ‪00963955335369 /‬‬


‫استعراض كل االسماء‬ ‫•‬
‫البحث عن اسم معين وعرضه جميع ارقامه والعنوان وااليميل في حال وجوده‬ ‫•‬
‫البحث عن طريق الرقم‬ ‫•‬
‫تعديل رقم الجوال عن طريق االسم‬ ‫•‬
‫حذف سجل كامل السم معين‬ ‫•‬
‫ظهور عدد السجالت‬ ‫•‬

‫‪4‬‬
Function SearchByName($lines,$Name)
{
foreach ($lines as $line){
$liste = explode("|",$line);

00963955335369 / ‫ماجد الجمية‬.‫م‬


if (trim($liste[1]) == $oldName)
printarray($line);
}
}

5
• Function updateFileByName($lines,$oldName,$NewName)
• {
• $NewLines = array();
• $newline="";
• foreach ($lines as $line){

00963955335369 / ‫ماجد الجمية‬.‫م‬


• $liste = explode("|",$line);
• if (trim($liste[1]) == $oldName)
• $liste[1]=$NewName;
• $newline=implode("|",$liste);
• $NewLines[]=$newline;
• }
• } 6
‫انتهت المحاضرة‬

‫م‪.‬ماجد الجمية ‪00963955335369 /‬‬


‫‪7‬‬

Potrebbero piacerti anche