PHP is a widely used open source scripting language that is embedded in HTML and interpreted by servers to produce dynamic web pages. It supports features like variables, functions, arrays, sessions, cookies, and connecting to databases like MySQL. PHP code is written in .php files and contains HTML tags. It allows combining of HTML markup and PHP code to create dynamic content.
2. Introduction
Php is stands for php: hypertext pre-processor
Widely used open source scripting language
Server-side scripting language
Embedded with html
current version of php is 5.5.15 released on 24
july 2014.
3. What is scripting language
Scripting languages abstract their users from variable
types and memory management
no need to compile
A scripting language is usually interpreted from source
code to bytecode
5. Server side scripting
it is a technique used in web design
involves embedding script in html source code
before respond to client , server execute server –side
script and produce equivalent HTML code
server side scripting is different from client side
scripting. For example javascript runs on brower.
6. Importance of php in web development
open source
Cross platform architecture
Intergated with a wider range of database like oracle
mysql ,ms access etc.
It supports various servers like Apache ,IIS etc.
Aache is best suited for executing PHP scripts
7. PHP program structure
<?php
//php code goes here
?>
“.php” is default file extension for PHP
PHP file contains PHP scripting code and HTML tags
8. Variables in PHP
Used for storing value
Can hold any type of value, no data type
Starts with $ sign and preceded by name of
variable
name of variable are case sensitive
9. Built in variable
$_GET-used for retrieving form element ,also used
for fetching value of variable through URL
$_POST:-HTTP post variable used for retrieving form
element
$_SESSION :-used for creating session variable
$_COOKIE :-used for cookie manipulation
10. Combining HTML and PHP
<html>
<head></head>
<body>
<?php
echo “hello”;
?>
</body>
</html>
11. PHP functions
function keyword is used to create a function
Syntax
function fun_name(parameter){
//some code
return some_value;
}
12. PHP ‘include’ and ‘requir’
used to include content of one file into another
Syntax
<?php include “header.php”;
//some code
include “footer.php”
?>
13. PHP array
special variable that can hold multiple values at a time
Indexed array: array with numeric index
Associative array: element are accessed by keys instead of
numeric index
multidimensional array: An array that can contain
another array as value
array() function is used to create an array cont…
15. PHP arrays
foreach loop:-special loop used for arrays
syntax to access array element
foreach($arr as $value){
echo $value; //for indexed array
}
to access element of associative array
16. PHP array
foreach($arr as $key=>$value)
{
echo “value at”.$key.”is”.$value;
}
array_pop() function is used to delete the last
element of an array
17. MYSQL
Mysql is a database and defines structure for storing
information.
MYSQL is used to perform database related
operation.
Can be integrated with php.
open source database server.
18. Connecting to mysql
In PHP connection is established using mysql_connect()
function
syntax:
mysql_connect(servername,username,database
password);
example:-
<?php
$ conn=mysql_connect(“localhost”,”root”,””)
// some code
?>
19. Closing MYSQL connection
connection use the mysql_closeTo close the () function
example
<php $db=mysql_connect(“localhost”,”root”,””);
if(!$db) die(“cannot connet to mysal”);
else
//some code
mysql_close($db);
?>
20. session
contains information about same user between different
web pages for a particular application
session_start() function is used to start session
$_SESSION variable is used to create session variable
<?php session_start()
$_SESSION[‘uname’]=“shyam”;
?>
21. session
session_destroy() function is use to destroy session variable
<?php
session_start();
$_SESSION[‘uname’]=$_POST[‘name’];
// some code
session_destroy() //destroy the session
?>
22. cookie
often used to identify user
cookie is a small file which server embeds on user’s system
whenever same system request a webpage it sends cookie
too
creating a cookie
setcookie(‘name’,value’,expire,path,domain,security)
23. cookie
$_COOKIE variable is used to retrieve cookie
<?php setcookie(“name”, ”shyam” date()+12*60*60);
echo $_COOKIE[‘name’];
?>
session is better option of cookie