PHP.... Part 6
PHP.... Part 6
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 عبارة عن دالة مضمنة تُستخدم إلرسال رأس
يتم إرسال طلب خام (مثل.المعلومات التي يتم إرسالها إلى العميل أو المتصفح قبل إرسال أي إخراج أصلي
<?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
استخدم مفهوم تضمين الملف الذي يساعد على تضمين الملفات في البرامج المختلفة ويوفر جهد، لذلك
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 من المفيد ج ًدا تضمين الملفات عندما تريد تطبيق نفس كود
.ويب
يؤدي تضمين ملف إلى الحصول على نفس نتيجة نسخ البرنامج من الملف المحدد ولصقه في المكان الذي
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
Easy editable: If we want to change anything in webpages, edit the source file included
PHP include
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>
PHP require
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>
<?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
EvenOrOdd.php
Example >> 27
Example >> 28
FindFactorial.php
Example >> 31
Example >> 32
ReverseWords.php
Example >>> 35
Example >>> 36
Character.php
Example >>> 37
CheckCh.php
Example >> 38
Example >> 39
Example >> 40
Example >> 41
Example >> 42