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

Introduction To PHP

Uploaded by

jyotsnas99
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Introduction To PHP

Uploaded by

jyotsnas99
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Intro.

to LAMP Stack and PHP

Dr. Nagender Kumar S


Intro.to LAMP (Linux+Apache+MySQL+PHP)
To develop a Website (Web application), what do we require?
**Website: Collection of Web Pages(sources)

Website (Application) Available Stack


Linux-AMP:
Frontend Backend
(User Interface) (Servers)
Windows-AMP:
Mac-AMP:
Database Web
Web Page
Programming
Language
X(Cross Platform)-AMPP
Server Server

JavaScript MySQL Apache PHP

Request

Response

Client Server
Steps to Install LAMP stack on Ubuntu 18.04 LTS
Intro to PHP
• PHP Hypertext Preprocessor (PHP) is a programming language that
allows web developers to create dynamic content that interacts with
databases.
• PHP is a server side scripting language that is embedded in HTML. It is
used to manage dynamic content, databases, session tracking, even build
entire e-commerce sites.
• PHP Syntax is like “C” Programming Language.
<html>
<head> <title>Example1-PHP</title> </head>
<body>
<h2> Welcome to Server Side programming using PHP </h2>
<?php echo "Hello, World!";?> </body>
</html>
PHP: Variables and Operators
<?php
$first = 100;
$second = 200;
<?php
$third = $first + $second; $uname=“abcd";
echo "Sum = ".$third; $upass=“abcd123";
if($uname=="abcd" || $upass=="abcd123")
?> {
header('location:http://localhost/relogin.php');
<?php }
$x=10; else
{
$y=3; echo "Invalid name or password";
//remainder }
?>
$rem=$x%$y;
echo "remainder=".$rem."<br/>";
?>
PHP-Arrays <html>
<body>
<html> <?php
$marks = array(
<body>
“student1" => array (
<?php "physics" => 35,
$numbers = array( 1, 2, 3, 4, 5); "maths" => 30,
"chemistry" => 39
foreach( $numbers as $value ) { ),
echo "Value is $value <br />"; “student2" => array (
"physics" => 30,
} "maths" => 32,
$numbers[0] = "one"; $numbers[1] = "two"; "chemistry" => 29
) );
$numbers[2] = "three"; $numbers[3] = "four";
$numbers[4] = "five"; /* Accessing multi-dimensional array values */
echo "Marks for student1 in physics : " ;
foreach( $numbers as $value ) { echo $marks[‘student1']['physics'] . "<br />";
echo "Value is $value <br />";
echo "Marks for student2 in maths : ";
}
echo $marks[‘student2']['maths'] . "<br />";
?>
?>
</body> </html>
</body> </html>
PHP: Functions
<html> <html>
<head>
<head>
<title>Writing PHP Function with Parameters</title> <title>Writing PHP Function which returns value</title>
</head> </head>

<body> <body>
<?php
<?php
function addFunction($num1, $num2) { function addFunction($num1, $num2) {
$sum = $num1 + $num2; $sum = $num1 + $num2;
return $sum;
echo "Sum of the two numbers is : $sum"; }
} $return_value = addFunction(10, 20);
addFunction(10, 20); echo "Returned value from the function : $return_value";
?> ?>
</body>
</body>
</html> </html>
PHP Super global variables
• PHP Super global variables is accessible inside the same page that defines it, as
well as outside the page

1) $_GET["FormElementName"]
It is used to collect value from a form(HTML script) sent with method='get'. information sent from a form with the
method='get' is visible to everyone(it display on the browser URL bar).

2) $_POST["FormElementName"]
It is used to collect value in a form with method="post". Information sent from a form is invisible to others.(can
check on address bar)
Usage of $_POST
<form method="post">
<?php
<table align="center">
extract($_POST);
<tr> if(isset($swap))
<td>Enter First number</td> {
$x=$fn;
<td><input type="text" name="fn"/></td> $y=$sn;
</tr> $z=0;
$z=$x;
<tr> $x=$y;
<td>Enter Second number</td> $y=$z;
echo "<p align='center'>Now First numebr is : ". $x ."<br/>";
<td><input type="text" name="sn"/></td> echo "and Second number is : ". $y."</p>";
</tr> }
?>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Swap Numbers" name="swap"/>
</td>
</tr> </table> </form>
Next Video

Demo
PHP MySQL User Login System
Reference

You might also like