Unit-1
Introduction to Webpage and Website
In PHP, a "website" refers to a collection of interconnected webpages, all built using PHP
code to generate dynamic content, while a "webpage" is a single HTML file that can contain
PHP code to dynamically display information, essentially acting as one page within a larger
website.
Website
Website is a collection of related web pages that may contain text, images, audio and
video. The first page of a website is called home page. Each website has specific
internet address (URL) that you need to enter in your browser to access a website.
Website is hosted on one or more servers and can be accessed by visiting its
homepage using a computer network. A website is managed by its owner that can be
an individual, company or an organization.
A website can be of two types:
Static Website
Dynamic Website
Static website
Static website is the basic type of website that is easy to
create. You don't need web programming and database
design to create a static website. Its web pages are coded
in HTML.
The codes are fixed for each page so the information
contained in the page does not change and it looks like a
printed page.
Dynamic website
Dynamic website is a collection of dynamic web pages
whose content changes dynamically. It accesses content
from a database or Content Management System (CMS).
Therefore, when you alter or update the content of the
database, the content of the website is also altered or
updated.
Dynamic website uses client-side scripting or server-side
scripting, or both to generate dynamic content.
Client side scripting generates content at the client
computer on the basis of user input. The web browser
downloads the web page from the server and processes the code within the page to
render information to the user.
In server side scripting, the software runs on the server and processing is completed
in the server then plain pages are sent to the user.
Static vs Dynamic website
Static Website Dynamic Website
Prebuilt content is same every time Content is generated quickly and changes regularly.
the page is loaded.
It uses the HTML code for developing It uses the server side languages such
a website. as PHP,SERVLET, JSP, and ASP.NET etc. for
developing a website.
It sends exactly the same response for It may generate different HTML for each of the
PARUL BHEDA Page 1
Unit-1
every request. request.
The content is only changes when The page contains "server-side" code it allows the
someone publishes and updates the server to generate the unique content when the
file (sends it to the web server). page is loaded.
Flexibility is the main advantage of Content Management System (CMS) is the main
static website. advantage of dynamic website.
Client and Server side scripting
What is the Difference between Client Side Scripting and Server Side Scripting
Language?
Client-side Scripting Server-side Scripting
1. Client-side scripting is executed on user‟s It is executed on the server.
computer (browser).
2. It does not require any web server. It required web server.
3. It executes speedier fastly. It is executed slowly compared to client-side scripting.
4. It reduces the network traffic. It mostly generates the network traffic.
5. It is not safe and secure. It is secure and visible for users.
6. JavaScript, HTML and CSS are example of PHP, C#, VB.NET is an example of server scripting.
client-side scripting.
7. It is the check the validation for use It is the check the validation for use regular
JavaScript condition. expression function.
8. Users may be able to see its source code. The user cannot see the script‟s source code.
Introduction to other server side languages
There are several languages that can be used for server-side programming:
PHP
ASP.NET (C# OR Visual Basic)
C++
Java and JSP
Python
Ruby on Rails and so on.
open source vs. closed source software
In the context of PHP, "open source" software means the source code is publicly accessible,
allowing anyone to view, modify, and distribute it freely, while "closed source" software keeps the
source code hidden, only accessible to the developers, limiting customization and requiring users to
rely solely on the vendor for updates and support;
Introduction to PHP:
• PHP is an open-source, interpreted, and object-oriented scripting language that can be
executed at the server-side. PHP is well suited for web development. Therefore, it is used to
develop web applications (an application that executes on the server and generates the
dynamic page.).
• PHP was created by Rasmus Lerdorf in 1994 but appeared in the market in 1995. PHP
7.4.0 is the latest version of PHP, which was released on 28 November.
PARUL BHEDA Page 2
Unit-1
• PHP stands for Hypertext Preprocessor. Its original name was “personal homepage”.
• PHP is an interpreted language, i.e., there is no need for compilation.
• PHP is faster than other scripting languages, for example, ASP and JSP.
• PHP is a server-side scripting language, which is used to manage the dynamic content of the
website.
• PHP can be embedded into HTML.
• PHP is an object-oriented language.
• PHP is an open-source scripting language.
• PHP is simple and easy to learn language.
Installation and configuration of Apache,MySQL and PHP
Apache server has been the most popular Web server on the internet since April
1996.
Apache server is developed and maintained s an open-source software by the apache
HTTP server project.
Apache server supports several operating system including Unix and windows.
PHP Data Types(on w3school)
Variables can store data of different types, and different data types can do
different things.
PHP supports the following data types:
String
Integer
Float (floating point numbers - also called double)
Boolean
Array
Object
NULL
APACHE Installation:
1. Go to www.apache.org and download “win32 Binary:apache_2.2.4-win32-x86-
no_ssl.msi” to your desktop.
2. Double click “apache_2.2.4-win32-x86-no_ssl.msi”, and if prompted, click “run”.
3. An installation wizard will appear click Next.
4. The next page contains the terms of agreement. Select “I Accept”, and click “Next”.
5. Read about the Apache Server, and click “Next”.
6. The next screen will ask you for specific server information. Enter the values in
Network Domain: localhost
Server Name : localhost
Administrator‟s email address : admin@localhost.com
7. Then select the option: for all users, on port 80, as a service – recommended.
PARUL BHEDA Page 3
Unit-1
8. Click “Next”.
9. On the next screen, select “Typical Installation” and click “Next”.
10. Click “Next”.
11. Click “Install”.
12. Open up Internet Explorer and type in “http://localhost “. if you see a page that
says “It works!” then the Apache Sever has been installed successfully.
Understanding of PHP.INI file
php.ini is the configuration file of a PHP installation. Its location can depend on your
web server‟s operating system and the method you used to install PHP.
It basically consists of key-value pairs. Any line starts with a ; (semicolon) is a
comment. Except comment and blank lines, all the others are active settings. You
can open this file in a text editor.
Before changing any setting, it‟s a good practice to backup your original php.ini file.
Otherwise if you made an error in the file (mistyped) then your whole PHP
installation won‟t work. After making a change, to take effect that change, you will
have to restart your web server.
Let‟s take a look at some basic settings.
short_open_tag
You know that any PHP code should reside between <?php and ?> tags. Making this
setting „On‟ allows you to put PHP code between <? and ?> omitting the „php‟ part in
the opening tag.
register_globals
Usually default value of this setting is „Off‟. Turning this „On‟ allows to use form
submitted data ($_GET and $_POST), cookies ($_COOKIE) and server variables
($_SERVER) to use in global scope.
For an example, if there is a form field called firstName and if the form
uses post method to submit the form to the server then at the server you have to
access that value as $_POST['firstName'] (that is using $_POST array). But if you
turn this option „On‟ then you can access the value by just $firstName.
. Explain Operators in PHP.
An operator is a symbol that tells the compiler to perform certain mathematical or
logical manipulations.
Arithmetic Operators Assignment Operators
Operat Exampl Operator Example Is The Same As
Syntax Result
or e
= x=y x=y
+ Addition x=2 4
x+2 += x+=y x=x+y
- Subtraction x=2 3 -= x-=y x=x-y
5-x
*= x*=y x=x*y
* Multiplication x=4 20
/= x/=y x=x/y
x*5
%= x%=y x=x%y
/ Division 15/5 3
5/2 2.5
% Modulus 5%2 1
10%8 2
(division 10%2 0
remainder)
PARUL BHEDA Page 4
Unit-1
Comparison Operators Logical Operators
Operat Operat Synta
Syntax Example Example
or or x
== is equal to 5==8 returns false && and x=6
y=3(x < 10 && y > 1) returns
!= is not equal 5!=8 returns true true
|| or x=6
> is greater than 5>8 returns false y=3(x==5 || y==5) returns
false
< is less than 5<8 returns true
! not x=6
y=3!(x==y) returns true
>= is greater than or 5>=8 returns false
equal to
<= is less than or equal to 5<=8 returns true
String Operators
Concatenation Returns the second value appended to the first
. $a.$b
.=
Shorthand Appends the second value to the first $a.=$b.
concatenation
These operators are used to join strings together, like this:
<?php
$first = "PHP";
$second = "/MySQL";
$third = $first.$second;
//$third is now "PHP/MySQL"
$first .= "-Hypertext PreProcessor";
//$first is now "PHP-Hypertext PreProcessor";
?>
Ternary Operator
The ternary operators is so Named because it is the only operator that takes three
operands: a condition, a result for true, and a result for false.
If that sounds like an if statement to you, you are right on the ternary operator is a
shorthand(very hard to read)way of doing if statements.
$agestr = ($age < 16) ? „child‟ : „adult‟;
First there is a condition ($age < 16),then there is a question mark, and then a true
result, a colon, and a false result.
If $age is less than 16, $agestr will be set to „child‟; otherwise, it will be set to
„adult‟.
That one-linear ternary statement can be expressed in a normal if statement like
this:
If($age < 16)
{
$agestr = „child‟;
}else{
$agestr = „adult‟;}
So, in essence, using the ternary operator allows you to compact five lines of
code. Into one, at the expense of some reliability.
Increment/decrement Operators
Example Name Effect
++$a Pre-increment Increments $a by one, then returns $a.
PARUL BHEDA Page 5
Unit-1
$a++ Post-increment Returns $a, then increments $a by one.
--$a Pre-decrement Decrements $a by one, then returns $a.
$a-- Post-decrement Returns $a, then decrements $a by one.
Explain Static & Global Variable In PHP.
Static Variable:
This function is quite useless since every time it is called it sets $a to 0 prints “0”.
The $a++ which increments the variable since no purpose since as soon as the
function exists the $a variable disappears.
To make a useful counting function which will not lose track of the current count,
the $a variable is declared static:
Example
<?php
function Test(){
static $a=0;
echo $a,'<br>';
$a++;}
Test();
Test();
?>
Global Variable:
This script will not produce any output because the echo statement refers to a local
version of the $a variable, and it has not been assigned a value within this scope.
You may notice that this is a little bit different from the C language in that global
variables in C are automatically available to functions unless specifically overridden
by a local definition,
This can cause some problems in that people may inadvertently change a global
variable.
In PHP global variables must be declared global inside a function if they are going to
be used in that function.
Example:
<?php
$a=1;
$b=2;
function Sum(){
global $a,$b;
$b=$a+$b; }
Sum();
echo $b;
?>
PARUL BHEDA Page 6