By dharmendra kumar dhakar
Roll no:12115029
NIT RAIPUR
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.
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
Client server model of php
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.
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
PHP program structure
<?php
//php code goes here
?>
 “.php” is default file extension for PHP
 PHP file contains PHP scripting code and HTML tags
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
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
Combining HTML and PHP
<html>
<head></head>
<body>
<?php
echo “hello”;
?>
</body>
</html>
PHP functions
 function keyword is used to create a function
 Syntax
function fun_name(parameter){
//some code
return some_value;
}
PHP ‘include’ and ‘requir’
 used to include content of one file into another
Syntax
<?php include “header.php”;
//some code
include “footer.php”
?>
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…
PHP array
 syntax
$arr=array(1,2,3,4,5); //indexed array
$arr=array(1=>2,4=>6,5=>7)//associative array
$a=array(1=>array(1,2,3,4,5))//multidimentiona
l
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
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
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.
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
?>
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);
?>
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”;
?>
session
 session_destroy() function is use to destroy session variable
<?php
session_start();
$_SESSION[‘uname’]=$_POST[‘name’];
// some code
session_destroy() //destroy the session
?>
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)
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
Php technical presentation

Php technical presentation

  • 1.
    By dharmendra kumardhakar Roll no:12115029 NIT RAIPUR
  • 2.
    Introduction Php is standsfor 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 scriptinglanguage  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
  • 4.
  • 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 phpin 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 //phpcode 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-usedfor 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 andPHP <html> <head></head> <body> <?php echo “hello”; ?> </body> </html>
  • 11.
    PHP functions  functionkeyword 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  specialvariable 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…
  • 14.
    PHP array  syntax $arr=array(1,2,3,4,5);//indexed array $arr=array(1=>2,4=>6,5=>7)//associative array $a=array(1=>array(1,2,3,4,5))//multidimentiona l
  • 15.
    PHP arrays  foreachloop:-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 isa 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 connectionuse 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 informationabout 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() functionis use to destroy session variable <?php session_start(); $_SESSION[‘uname’]=$_POST[‘name’]; // some code session_destroy() //destroy the session ?>
  • 22.
    cookie  often usedto 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 variableis used to retrieve cookie <?php setcookie(“name”, ”shyam” date()+12*60*60); echo $_COOKIE[‘name’]; ?>  session is better option of cookie