0% found this document useful (0 votes)
1 views

php (1)

PHP is a powerful server-side scripting language used to create dynamic web pages and perform various server-side tasks. It supports functionalities such as file manipulation, data collection, user access control, and database interactions. PHP syntax includes variables, constants, data types, operators, conditional statements, loops, functions, and superglobals, making it versatile for web development.

Uploaded by

ibromuktar863
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)
1 views

php (1)

PHP is a powerful server-side scripting language used to create dynamic web pages and perform various server-side tasks. It supports functionalities such as file manipulation, data collection, user access control, and database interactions. PHP syntax includes variables, constants, data types, operators, conditional statements, loops, functions, and superglobals, making it versatile for web development.

Uploaded by

ibromuktar863
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/ 16

SERVER SIDE SCRIPTING

PHP
Php
Php is powerful server side programming language.
Php originally stands for personal home page but know its stands for hypertext pre processor
Php files are executed on servers like apache
http(hyper text transfer protocol ):is a protocol used over a website between client and server
The web browser is a client and the web server is the server .the client request a page and the server the
request.
Major examples webserver
1 apache: the second most popular web server software (31% of known websites use it )
2 NGINX:is the most popular web server(33% of known websites use it )
http uses port 80 by default, while https uses port 443.
Cont’d

Php is scripting language used to create dynamic wage pages.


Php can :
 generate dynamic page contents based on conditions.
 Create read write delete and close files on the server
 Collect data
 Control user access .
 Encrypt data and much more
 Read ,add ,modify or delete in your database
Cont’d

Php syntax::
Php scripts can be placed anywhere in the document but the must start and end
with <? Php and ?> respectively.
Php files can contain HTML,CSS AND JAVASCRIPT codes , php files can also
contain only php code.
echo: is a php keyword used to display a text.
Php variables: used to store a value that can be used throughout a script.]
variables are declared using the $ sign followed by identifier
Variable name (identifiers): variables are declared using the $ sign followed by
identifier. Identifier can contain letter number and underscore but must start with a
letter or underscore
Rules of a variable name:
1 must start with $ sign
2 variable names are case sensitive
3 the first letter after $ must be a letter or underscore(_)
4 there are no restriction on the length of a name.
Php constants : constants are values that cannot be changed once they are
defined.they are used to store values that should remain the same throught the
execution of the code.
There are 2 ways to declare constants
1 by using the const key word
2 by using define() function
BASICS OF PHP
Comments: comments has no impact on the code or program none what so ever.
Single line comment:
// comments a nd #comments
Multiple line comment:
/*comments */
Variable names(identifiers): can be letters numbers and underscore but must start with
letter or underscore(_)
 are unique name given to a variable
Rules of identifiers:
1 must start with the dollar sign ($)
2 php variables are case sensetives (capital and small letter are different )
3 variable name cant start with number .it can start with letter or underscore
4 the length of variable name is not restricted.
Php datatypes

Srting: collection of letters


Integer: non decimal numbers
Float: for decimal numbers but it can also hold non decimal numbers
Boolean:either true or false
Array: multiple values in single variable
Null: a variable that has no value assigned to it
operators
Arithmetic operators : +,-,/,*,--,++,%
Assignment operators:=,+=,-=,*=,
Comparison operators:==,!=(not equal to),<,>
Php conditional
statments
The following are examples of conditional statements in php:
 If statements
 If …else statements
 Switch statement
Php loop statments
Loop is sequence of statements that is continually repeated until certain condition is reached;
The following are examples loop statements in php:
1 while loop
2 do while
3 for loop
4 for each loop
For loop:
Q write php code that display list of numbers less than 100
<?php
For($i=0;$i<5;$i++){
Echo$i.”<br>”
}
?>
Break and continue
statments
Break and continue are control stracture in php.
Break used to terminate the execution .
Continue used to skip a certain condition
Php functions and array
Function is a reusable pieces of code that used to perform specific task. They allow you to break down
the code in to smaller parts which make it easier to manage.
Syntax for function declaration
Function function name ()
{
//code
}
Functions must be called in order to used them after they are declared
Array: is special type of variable used to store multiple values in single variable.
There are many types of array like:
Associative array
Multidimensional array
http methods
http stands for hypertext transfer protocol. The most commonly used http methods are
1 get :to retrieve data from the server
2 post : to submit data to the server
3 put :to update data on a sever
4 delete : to remove data from the server
5 patch :partially update data on the server.
Each http method serve a specific purpose.
Get vs post method: compare them(refer your text book)
Here is the main deference between the 2 methods
1 in terms of parameter
2 in terms of data amount
3 in terms of security
Refer your text book
php Super global
Super global is special type of array that are automatically available in all scopes of php scripts.
There are 9 super globals in php:
1$GLOBALE
2$_SERVER
3$_GET
4$_POST
5$_FILES
6$_COOKIE
7$_SESSION
8$_REQUEST
9$_ENV
do the following questions

1 write a php code that display your full name, age and section. NB: each of them
has to be displayed in separate line
2 write a php code that display the sum, subtraction ,division and multiplication of
10 and 5
3 write a php code that display 5 of your favorite colors by using array.
4 Write php code that display list of numbers from 100 to 10 downwards

You might also like