0% found this document useful (0 votes)
6 views43 pages

PHP.... Part 6

The document explains the use of the header() function in PHP for sending raw HTTP headers to clients, including examples of redirection. It also discusses the include() and require() functions, which allow for code reusability across multiple pages, highlighting their differences in error handling. The document provides syntax examples and emphasizes the advantages of using these functions for efficient web development.

Uploaded by

altihamimohmmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views43 pages

PHP.... Part 6

The document explains the use of the header() function in PHP for sending raw HTTP headers to clients, including examples of redirection. It also discusses the include() and require() functions, which allow for code reusability across multiple pages, highlighting their differences in error handling. The document provides syntax examples and emphasizes the advantages of using these functions for efficient web development.

Uploaded by

altihamimohmmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

Web Development

ADEL AHMED ALHAJJ


header() function 2

 header() function is an inbuilt function that is used to send a raw HTTP header to the

client and it is mandatory that they actually manipulate the information which is sent to

the client or browser before any original output can be sent. A raw request (like an

HTTP request) is sent to the browser or the client.

‫ خام إلى العميل ومن الضروري أن يتعاملوا بالفعل مع‬HTTP ‫ عبارة عن دالة مضمنة تُستخدم إلرسال رأس‬

‫ يتم إرسال طلب خام (مثل‬.‫المعلومات التي يتم إرسالها إلى العميل أو المتصفح قبل إرسال أي إخراج أصلي‬

.‫) إلى المتصفح أو استجابة العميل‬HTTP ‫طلب‬


header() function 3

<?php
// This will redirect the user to the new location
header ('Location: http://www.javatpoint.com/');
exit; ?>

<?php
// This will redirect after 10 seconds
header('Refresh: 10; url = http://www.javatpoint.com/');
exit; ?>
header() function 4

File :headercheck.php
?php
$newpage = 'welcome.php';

header("Location: $newpage");

exit; ?>

File :welcome.php
<!-- welcome.php file redirect to new page -->
<html> <body>
<h1> <center> Welcome to javaTpoint </center> </h1>
</body> </html>
include () and require () 5

 PHP allows us to create various elements and functions, which are used several times in

many pages. It takes much time to script these functions in multiple pages.

‫ يستغرق األمر‬.‫ تُستخدم عدة مرات في العديد من الصفحات‬، ‫ إنشاء عناصر و دوال متنوعة‬PHP ‫تسمح لنا‬ 

.‫وق ًتا طويال ً لكتابة هذه الدوال في صفحات متعددة‬

 Therefore, use the concept of file inclusion that helps to include files in various

programs and saves the effort of writing code multiple times.

‫ استخدم مفهوم تضمين الملف الذي يساعد على تضمين الملفات في البرامج المختلفة ويوفر جهد‬، ‫لذلك‬ 

.‫كتابة الكود عدة مرات‬


include () and require () 6

 PHP allows you to include file so that a page content can be reused many times.

.‫ بتضمين ملف بحيث يمكن إعادة استخدام محتوى الصفحة عدة مرات‬PHP ‫تسمح لنا‬ 

 It is very helpful to include files when you want to apply the same HTML or PHP code

to multiple pages of a website." There are two ways to include file in PHP

‫على صفحات متعددة من موقع‬PHP ‫ أو‬HTML ‫من المفيد ج ًدا تضمين الملفات عندما تريد تطبيق نفس كود‬ 

.‫ويب‬

‫يؤدي تضمين ملف إلى الحصول على نفس نتيجة نسخ البرنامج من الملف المحدد ولصقه في المكان الذي‬ 

.‫تم استدعاؤه فيه‬

PHP ‫هناك طريقتان لتضمين الملف في‬ 

1- Include 2-Require
include () and require () 7

 Both include and require are identical to each other, except failure.

 include only generates a warning, i.e., E_WARNING, and continue the execution of the

script.

 require generates a fatal error, i.e., E_COMPILE_ERROR, and stop the execution of

the script.

 Advantage

 Code Reusability: By the help of include and require construct, we can reuse HTML code

or PHP script in many PHP scripts.

 Easy editable: If we want to change anything in webpages, edit the source file included

in all webpage rather than editing in all the files separately.


include () and require () 8

 PHP include

 Syntax >>>> include 'filename '; Or include ('filename');

File: menu.html
<a href="http://www.all-learn.com">Home</a> |
<a href="http://www. all-learn.com/php-tutorial">PHP</a> |
<a href="http://www. all-learn.com/java-tutorial">Java</a> |
<a href="http://www. all-learn.com/html-tutorial">HTML</a>

File: Main Page.php


<?php include ("menu.html"); ?>
<h1>This is Main Page</h1>
include () and require () 9

 PHP require

 Syntax >>>> require 'filename '; Or require ('filename');

File: menu.html
<a href="http://www.all-learn.com">Home</a> |
<a href="http://www. all-learn.com/php-tutorial">PHP</a> |
<a href="http://www. all-learn.com/java-tutorial">Java</a> |
<a href="http://www. all-learn.com/html-tutorial">HTML</a>

File: Main Page.php


<?php require ("menu.html"); ?>
<h1>This is Main Page</h1>
include () and require () 10

<?php
include ("welcome.php");
echo "The welcome file is included."; ?>

<?php
require ("welcome.php");
echo "The welcome file is included."; ?>
include () and require () 11
include () and require () 12
Example >> 13
Example >> 14
Example >> 15

Index.php
Example >> 16

merge.php
Example >> 17

merge.php
Example >> 18
Example >> 19

add.php
Example >> 20

add.php
Example >> 21

Sum2Num.php
Example >> 22
Example >> 23
Example >> 24

check number is even or odd.php


Example >> 25

check number is even or odd.php


Example >> 26

EvenOrOdd.php
Example >> 27
Example >> 28

print the factorial of a given number.php


Example >> 29

print the factorial of a given number.php


Example >> 30

FindFactorial.php
Example >> 31
Example >> 32

Reverse Words of a string.php


Example >> 33

Reverse Words of a string.php


Example >> 34

ReverseWords.php
Example >>> 35
Example >>> 36

Character.php
Example >>> 37

CheckCh.php
Example >> 38
Example >> 39
Example >> 40
Example >> 41
Example >> 42

You might also like