SlideShare a Scribd company logo
PHP -  Introduction to PHP Fundamentals
Introduction toIntroduction to
PHP FundamentalsPHP Fundamentals
GoalGoal
• Not to teach everything about PHP, but provide the
basic knowledge
• Explain code of examples
• Provide some useful references
PHP Basics:PHP Basics:
Introduction to PHP
• a PHP file, PHP workings, running PHP.
 Basic PHP syntax
• variables, operators, if...else...and switch, while, do while, and for.
 Some useful PHP functions
 How to work with
• HTML forms, cookies, files, time and date.
 How to create a basic checker for user-entered data
Server-Side Dynamic Web ProgrammingServer-Side Dynamic Web Programming
• CGI is one of the most common approaches to server-side programming
 Universal support: (almost) Every server supports CGI programming. A great deal of
ready-to-use CGI code. Most APIs (Application Programming Interfaces) also allow CGI
programming.
 Choice of languages: CGI is extremely general, so that programs may be written in
nearly any language. Perl is by far the most popular, with the result that many people
think that CGI means Perl. But C, C++, Ruby, and Python are also used for CGI
programming.
 Drawbacks: A separate process is run every time the script is requested. A distinction is
made between HTML pages and code.
• Other server-side alternatives try to avoid the drawbacks
 Server-Side Includes (SSI): Code is embedded in HTML pages, and evaluated on the
server while the pages are being served. Add dynamically generated content to an
existing HTML page, without having to serve the entire page via a CGI program.
 Active Server Pages (ASP, Microsoft) : The ASP engine is integrated into the web server
so it does not require an additional process. It allows programmers to mix code within
HTML pages instead of writing separate programs. (Drawback(?) Must be run on a
server using Microsoft server software.)
 Java Servlets (Sun): As CGI scripts, they are code that creates documents. These must
be compiled as classes which are dynamically loaded by the web server when they are
run.
 Java Server Pages (JSP): Like ASP, another technology that allows developers to
embed Java in web pages.
PHPPHP
• developed in 1995 by Rasmus Lerdorf (member of the Apache Group)
 originally designed as a tool for tracking visitors at Lerdorf's Web site
 within 2 years, widely used in conjunction with the Apache server
 developed into full-featured, scripting language for server-side programming
 free, open-source
 server plug-ins exist for various servers
 now fully integrated to work with mySQL databases
• PHP is similar to JavaScript, only it’s a server-side language
 PHP code is embedded in HTML using tags
 when a page request arrives, the server recognizes PHP content via the file extension (.php or
.phtml)
 the server executes the PHP code, substitutes output into the HTML page
 the resulting page is then downloaded to the client
 user never sees the PHP code, only the output in the page
What do You Need?What do You Need?
• Our server supports PHP
o You don't need to do anything special! *
o You don't need to compile anything or install any
extra tools!
o Create some .php files in your web directory -
and the server will parse them for you.
* Slightly different rules apply when dealing
with an SQL database (as will be explained when
we get to that point).
What is PHP?What is PHP?
• PHP == ‘Hypertext Preprocessor’
• Open-source, server-side scripting language
• Used to generate dynamic web-pages
• PHP scripts reside between reserved PHP tags
o This allows the programmer to embed PHP scripts within HTML pages
• The acronym PHP means (in a slightly recursive definition)
 PHP: Hypertext Preprocessor
What is PHP (cont’d)What is PHP (cont’d)
• Interpreted language, scripts are parsed at run-time
rather than compiled beforehand
• Executed on the server-side
• Source-code not visible by client
o ‘View Source’ in browsers does not display the PHP code
• Various built-in functions allow for fast development
• Compatible with many popular databases
What does PHP codeWhat does PHP code
look like?look like?
• Structurally similar to C/C++
• Supports procedural and object-oriented paradigm
(to some degree)
• All PHP statements end with a semi-colon
• Each PHP script must be enclosed in the reserved
PHP tag
<?php
…
?>
Comments in PHPComments in PHP
• Standard C, C++, and shell comment symbols
// C++ and Java-style comment
# Shell-style comments
/* C-style comments
These can span multiple lines */
Variables in PHPVariables in PHP
• PHP variables must begin with a “$” sign
• Case-sensitive ($Foo != $foo != $fOo)
• Global and locally-scoped variables
o Global variables can be used anywhere
o Local variables restricted to a function or class
• Certain variable names reserved by PHP
o Form variables ($_POST, $_GET)
o Server variables ($_SERVER)
o Etc.
ConstantsConstants
A constant is an identifier (name) for a simple value. A constant is case-sensitive by
default. By convention, constant identifiers are always uppercase.
<?php
/ Valid constant names
define("FOO", "something");
define("FOO2", "something else");
define("FOO_BAR", "something more");
// Invalid constant names (they shouldn’t start
// with a number!)
define("2FOO", "something");
// This is valid, but should be avoided:
// PHP may one day provide a “magical” constant
// that will break your script
define("__FOO__", "something");
?>
You can access
constants anywhere
in your script
without regard to
scope.
OperatorsOperators
• Arithmetic Operators: +, -, *,/ , %, ++, --
• Assignment Operators: =, +=, -=, *=, /=, %=
• Comparison Operators: ==, !=, >, <, >=, <=
• Logical Operators: &&, ||, !
• String Operators: . and .= (for string concatenation)
Example Is the same as
x+=y x=x+y
x-=y x=x-y
x*=y x=x*y
x/=y x=x/y
x%=y x=x%y
$a = "Hello ";
$b = $a . "World!"; // now $b contains "Hello World!"
$a = "Hello ";
$a .= "World!";
Variable usageVariable usage
<?php
$foo = 25; // Numerical variable
$bar = “Hello”; // String variable
$foo = ($foo * 7); // Multiplies foo by 7
$bar = ($bar * 7); // Invalid expression
?>
Basic PHP syntaxA PHP scripting block always starts with <?php and ends with ?>. A PHP scripting block can be placed (almost) anywhere in an HTML document.
<html>
<!-- hello.php -->
<head><title>Hello World</title></head>
<body>
<p>This is going to be ignored by the PHP interpreter.</p>
<?php echo ‘<p>While this is going to be parsed.</p>‘; ?>
<p>This will also be ignored by the PHP preprocessor.</p>
<?php print(‘<p>Hello and welcome to <i>my</i> page!</p>');
?>
<?php
//This is a comment
/*
This is
a comment
block
*/
?>
</body>
</html>
print and echo
for output
a semicolon (;)
at the end of each
statement
// for a single-line comment
/* and */ for a large
comment block.
EchoEcho
• The PHP command ‘echo’ is used to output the
parameters passed to it
• The typical usage for this is to send data to the client’s
web-browser
• Syntax
• void echo (string arg1 [, string argn...])
• In practice, arguments are not passed in parentheses
since echo is a language construct rather than an
actual function
Echo exampleEcho example
• Notice how echo ‘5x5=$foo’ outputs $foo rather than replacing it with 25
• Strings in single quotes (‘ ’) are not interpreted or evaluated by PHP
• This is true for both variables and character escape-sequences (such as “n” or “”)
<?php
$foo = 25; // Numerical variable
$bar = “Hello”; // String variable
echo $bar; // Outputs Hello
echo $foo,$bar; // Outputs 25Hello
echo “5x5=”,$foo; // Outputs 5x5=25
echo “5x5=$foo”; // Outputs 5x5=25
echo ‘5x5=$foo’; // Outputs 5x5=$foo
?>
Arithmetic OperationsArithmetic Operations
• $a - $b // subtraction
• $a * $b // multiplication
• $a / $b // division
• $a += 5 // $a = $a+5 Also works for *= and /=
<?php
$a=15;
$b=30;
$total=$a+$b;
Print $total;
Print “<p><h1>$total</h1>”;
// total is 45
?>
ConcatenationConcatenation
• Use a period to join strings into one.
<?php
$string1=“Hello”;
$string2=“PHP”;
$string3=$string1 . “ ” .
$string2;
Print $string3;
?>
Hello PHP
Escaping the CharacterEscaping the Character
• If the string has a set of double quotation marks that
must remain visible, use the  [backslash] before the
quotation marks to ignore and display them.
<?php
$heading=“”Computer Science””;
Print $heading;
?>
“Computer Science”
PHP Control StructuresPHP Control Structures Control Structures: Are the structures within a language that allow us to control the flow of
execution through a program or script.
 Grouped into conditional (branching) structures (e.g. if/else) and repetition structures (e.g.
while loops).
 Example if/else if/else statement:
if ($foo == 0) {
echo ‘The variable foo is equal to 0’;
}
else if (($foo > 0) && ($foo <= 5)) {
echo ‘The variable foo is between 1 and 5’;
}
else { echo ‘The variable foo is equal to ‘.$foo;
}
If ... Else...If ... Else...
• If (condition)
{
Statements;
}
Else
{
Statement;
}
<?php
If($user==“John”)
{
Print “Hello John.”;
}
Else
{
Print “You are not John.”;
}
?>
No THEN in PHP
Conditionals: if elseConditionals: if else<html><head></head>
<!-- if-cond.php -->
<body>
<?php
$d=date("D");
echo $d, “<br/>”;
if ($d=="Fri")
echo "Have a nice weekend! <br/>";
else
echo "Have a nice day! <br/>";
$x=10;
if ($x==10)
{ echo "Hello<br />";
echo "Good morning<br />";
}
?>
</body>
</html>
if (condition)
code to be executed if condition
is true;
else
code to be executed if condition
is false;
date() is a built-in PHP function that
can be called with many different
parameters to return the date
(and/or local time) in various formats
In this case we get a three letter
string for the day of the week.
While LoopsWhile Loops
• While (condition)
{
Statements;
}
<?php
$count=0;
While($count<3)
{
Print “hello PHP. ”;
$count += 1;
// $count = $count + 1;
// or
// $count++;
?>
hello PHP. hello PHP. hello PHP.
Can loop depending on a "counter"Can loop depending on a "counter"
<?php
for ($i=1; $i<=5; $i++)
{
echo "Hello World!<br />";
}
?>
loops through a block of code a
specified number of times
<?php
$a_array = array(1, 2, 3, 4);
foreach ($a_array as $value)
{
$value = $value * 2;
echo “$value <br/> n”;
}
?>
loops through a block of code for each
element in an array
<?php
$a_array=array("a","b","c");
foreach ($a_array as $key => $value)
{
echo $key." = ".$value."n";
}
?>
Date DisplayDate Display
$datedisplay=date(“yyyy/m/d”);
Print $datedisplay;
# If the date is June 25th, 2012
# It would display as 2012/25/6
2012/25/6
$datedisplay=date(“l, F m, Y”);
Print $datedisplay;
# If the date is June 25th
,2012
# Monday, June 25th
,2012
Monday, June 25, 2012
Month, Day & Date Format SymbolsMonth, Day & Date Format Symbols
M Jan
F January
m 01
n 1
Day of Month d 01
Day of Month J 1
Day of Week l Monday
Day of Week D Mon
FunctionsFunctions
• Functions MUST be defined before then can be
called
• Function headers are of the format
o Note that no return type is specified
• Unlike variables, function names are not case
sensitive (foo(…) == Foo(…) == FoO(…))
function functionName($arg_1, $arg_2, …, $arg_n)
Functions exampleFunctions example
<?php
// This is a function
function foo($arg_1, $arg_2)
{
$arg_2 = $arg_1 * $arg_2;
return $arg_2;
}
$result_1 = foo(12, 3); // Store the function
echo $result_1; // Outputs 36
echo foo(12, 3); // Outputs 36
?>
Include FilesInclude Files
Include “opendb.php”;
Include “closedb.php”;
This inserts files; the code in files will be inserted into current code. This will provide
useful and protective means once you connect to a database, as well as for
other repeated functions.
Include (“footer.php”);
The file footer.php might look like:
<hr SIZE=11 NOSHADE WIDTH=“100%”>
<i>Copyright © 2001-2012 gsu</i></font><br>
<i>ALL RIGHTS RESERVED</i></font><br>
<i>URL: http://www.gsu.edu.edu</i></font><br>
PHP - FormsPHP - Forms
•Access to the HTTP POST and GET data is simple in PHPAccess to the HTTP POST and GET data is simple in PHP
•The global variables $_POST[] and $_GET[] contain the request dataThe global variables $_POST[] and $_GET[] contain the request data
<?php
if ($_POST["submit"])
echo "<h2>You clicked Submit!</h2>";
else if ($_POST["cancel"])
echo "<h2>You clicked Cancel!</h2>";
?>
<form action="form.php" method="post">
<input type="submit" name="submit" value="Submit">
<input type="submit" name="cancel" value="Cancel">
</form>
WHY PHP – Sessions ?WHY PHP – Sessions ?
Whenever you want to create aWhenever you want to create a websitewebsite that allows you to store and displaythat allows you to store and display
information about a user, determine which user groups a person belongs to, utilizeinformation about a user, determine which user groups a person belongs to, utilize
permissions on yourpermissions on your websitewebsite or you just want to do something cool on your site,or you just want to do something cool on your site,
PHP's SessionsPHP's Sessions are vital toare vital to eacheach of these features.of these features.
Cookies are about 30% unreliable right now and it's getting worse every day. More andCookies are about 30% unreliable right now and it's getting worse every day. More and
more web browsers are starting to come with security and privacy settings and peoplemore web browsers are starting to come with security and privacy settings and people
browsing the net these days are starting to frown upon Cookies because they storebrowsing the net these days are starting to frown upon Cookies because they store
information on their local computer that they do not want stored there.information on their local computer that they do not want stored there.
PHP has a great set of functions that can achieve the same results of Cookies andPHP has a great set of functions that can achieve the same results of Cookies and
more without storing information on the user's computer. PHP Sessions store themore without storing information on the user's computer. PHP Sessions store the
information on the web server in a location that you chose in special files. These filesinformation on the web server in a location that you chose in special files. These files
are connected to the user's web browser via the server and a special ID called aare connected to the user's web browser via the server and a special ID called a
"Session ID". This is nearly 99% flawless in operation and it is virtually invisible to the"Session ID". This is nearly 99% flawless in operation and it is virtually invisible to the
user.user.
PHP - SessionsPHP - Sessions
•Sessions store their identifier in a cookie in the client’s browserSessions store their identifier in a cookie in the client’s browser
•Every page that uses session data must be proceeded by theEvery page that uses session data must be proceeded by the session_start()session_start() functionfunction
•Session variables are then set and retrieved by accessing the globalSession variables are then set and retrieved by accessing the global $_SESSION[]$_SESSION[]
•Save it asSave it as session.phpsession.php
<?php<?php
session_start();session_start();
if (!$_SESSION["count"])if (!$_SESSION["count"])
$_SESSION["count"] = 0;$_SESSION["count"] = 0;
if ($_GET["count"] == "yes")if ($_GET["count"] == "yes")
$_SESSION["count"] = $_SESSION["count"] + 1;$_SESSION["count"] = $_SESSION["count"] + 1;
echo "<h1>".$_SESSION["count"]."</h1>";echo "<h1>".$_SESSION["count"]."</h1>";
?>?>
<a href="session.php?count=yes">Click here to count</a><a href="session.php?count=yes">Click here to count</a>
Avoid Error PHP - SessionsAvoid Error PHP - Sessions
PHP Example: <?php
echo "Look at this nasty error below:<br />";
session_start();
?>
Error!
PHP Example: <?php
session_start();
echo "Look at this nasty error below:";
?>
Correct
Warning: Cannot send session cookie - headers already sent
by (output started at
session_header_error/session_error.php:2) in
session_header_error/session_error.php on line 3
Warning: Cannot send session cache limiter - headers
already sent (output started at
session_header_error/session_error.php:2) in
session_header_error/session_error.php on line 3
Destroy PHP - SessionsDestroy PHP - Sessions
Destroying a Session
why it is necessary to destroy a session when the session will get
destroyed when the user closes their browser. Well, imagine that you
had a session registered called "access_granted" and you were using
that to determine if the user was logged into your site based upon a
username and password. Anytime you have a login feature, to make
the users feel better, you should have a logout feature as well. That's
where this cool function called session_destroy() comes in handy.
session_destroy() will completely demolish your session (no, the
computer won't blow up or self destruct) but it just deletes the session
files and clears any trace of that session.
NOTE: If you are using the $_SESSION superglobal array, you must
clear the array values first, then run session_destroy.
Here's how we use session_destroy():
Destroy PHP - SessionsDestroy PHP - Sessions
<?php
// start the session
session_start();
header("Cache-control: private"); //IE 6 Fix
$_SESSION = array();
session_destroy();
echo "<strong>Step 5 - Destroy This Session </strong><br />";
if($_SESSION['name']){
    echo "The session is still active";
} else {
    echo "Ok, the session is no longer active! <br />";
    echo "<a href="page1.php"><< Go Back Step 1</a>";
}
?>
PHP OverviewPHP Overview
• Easy learning
• Syntax Perl- and C-like syntax. Relatively easy to
learn.
• Large function library
• Embedded directly into HTML
• Interpreted, no need to compile
• Open Source server-side scripting language
designed specifically for the web.
PHP Overview (cont.)PHP Overview (cont.)
• Conceived in 1994, now used on +10 million web sites.
• Outputs not only HTML but can output XML, images (JPG
& PNG), PDF files and even Flash movies all generated
on the fly. Can write these files to the file system.
• Supports a wide-range of databases (20+ODBC).
• PHP also has support for talking to other services using
protocols such as LDAP, IMAP, SNMP, NNTP, POP3, HTTP.
• Save as sample.php:
<!– sample.php -->
<html><body>
<strong>Hello World!</strong><br />
<?php
echo “<h2>Hello, World</h2>”; ?>
<?php
$myvar = "Hello World";
echo $myvar;
?>
</body></html>
First PHP scriptFirst PHP script
Example of parameter readingExample of parameter reading
• Consider:
• contents of php_exec/form.php...
• <html><body>
• <h1>Hi there</h1>
• <? if (!isset($_POST['foo'])): ?>
• <h1>'foo' is not set</h1>
• <? elseif (!is_array($_POST['foo'])) : ?>
• <h1>'foo' has one value <?=
$_POST['foo'] ?> </h1>
• <? else: ?>
• <h1>'foo' has multiple values <?=
join(',',$_POST['foo']) ?> </h1>
• <? endif ?>
• </body></html>
• ...end of php_exec/form.php
• Call with form:
• contents of php_exec/form01.txt...
<form action='php_exec/form.php'
method='post'> <ul> <li> <input
type='checkbox' name='foo[]'
value='raisins'> raisins. <li> <input
type='checkbox' name='foo[]'
value='cranberries'> cranberries.
<li> <input type='checkbox'
name='foo[]' value='plums'> plums.
</ul> <input type='submit'> </form>
...end of php_exec/form01.txt
• Here is what it looks like:
o  raisins.
o  cranberries.
o  plums.
Example – show data inExample – show data in
the tablesthe tables
• Function: list all tables in your database. Users can
select one of tables, and show all contents in this
table.
• second.php
• showtable.php
second.phpsecond.php
<html><head><title>MySQL Table Viewer</title></head><body>
<?php
// change the value of $dbuser and $dbpass to your username and password
$dbhost = ‘ codd.cs…….. ';
$dbuser = 'nruan';
$dbpass = ‘*****************’;
$dbname = $dbuser;
$table = 'account';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if (!$conn) {
die('Could not connect: ' . mysql_error());
}
if (!mysql_select_db($dbname))
die("Can't select database");
second.php (cont.)second.php (cont.)
$result = mysql_query("SHOW TABLES");
if (!$result) {
die("Query to show fields from table failed");
}
$num_row = mysql_num_rows($result);
echo "<h1>Choose one table:<h1>";
echo "<form action="showtable.php" method="POST">";
echo "<select name="table" size="1" Font size="+2">";
for($i=0; $i<$num_row; $i++) {
$tablename=mysql_fetch_row($result);
echo "<option value="{$tablename[0]}" >{$tablename[0]}</option>";
}
echo "</select>";
echo "<div><input type="submit" value="submit"></div>";
echo "</form>";
mysql_free_result($result);
mysql_close($conn);
?>
</body></html>
showtable.phpshowtable.php<html><head>
<title>MySQL Table Viewer</title>
</head>
<body>
<?php
$dbhost = 'hercules.cs.kent.edu:3306';
$dbuser = 'nruan';
$dbpass = ‘**********’;
$dbname = 'nruan';
$table = $_POST[“table”];
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if (!$conn)
die('Could not connect: ' . mysql_error());
if (!mysql_select_db($dbname))
die("Can't select database");
$result = mysql_query("SELECT * FROM {$table}");
if (!$result) die("Query to show fields from table failed!" . mysql_error());
showtable.php (cont.)showtable.php (cont.)
$fields_num = mysql_num_fields($result);
echo "<h1>Table: {$table}</h1>";
echo "<table border='1'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++) {
$field = mysql_fetch_field($result);
echo "<td><b>{$field->name}</b></td>";
}
echo "</tr>n";
while($row = mysql_fetch_row($result)) {
echo "<tr>";
// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo "<td>$cell</td>";
echo "</tr>n";
}
mysql_free_result($result);
mysql_close($conn);
?>
</body></html>
Functions CoveredFunctions Covered
• mysql_connect() mysql_select_db()
• include()
• mysql_query() mysql_num_rows()
• mysql_fetch_array() mysql_close()
PHP InformationPHP Information
The phpinfo() function is used to output PHP information about the version installed
on the server, parameters selected when installed, etc.
<html><head></head>
<!– info.php
<body>
<?php
// Show all PHP information
phpinfo();
?>
<?php
// Show only the general information
phpinfo(INFO_GENERAL);
?>
</body>
</html>
INFO_GENERAL The configuration line,
php.ini location,
build date,
Web Server,
System and more
INFO_CREDITS PHP 4 credits
INFO_CONFIGURATION Local and master values
for php directives
INFO_MODULESLoaded modules
INFO_ENVIRONMENT Environment variable
information
INFO_VARIABLES All predefined variables
from EGPCS
INFO_LICENSE PHP license information
INFO_ALL Shows all of the above (default)
Server VariablesServer VariablesThe $_SERVER array variable is a reserved variable that contains all server information.
<html><head></head>
<body>
<?php
echo "Referer: " . $_SERVER["HTTP_REFERER"] . "<br />";
echo "Browser: " . $_SERVER["HTTP_USER_AGENT"] . "<br />";
echo "User's IP address: " . $_SERVER["REMOTE_ADDR"];
?>
<?php
echo "<br/><br/><br/>";
echo "<h2>All information</h2>";
foreach ($_SERVER as $key => $value)
{
echo $key . " = " . $value . "<br/>";
}
?>
</body>
</html>
The $_SERVER is a super global variable, i.e. it's available in all scopes of a PHP script.
$_SERVER info
on php.net
File OpenFile Open
The fopen("file_name","mode") function is used to open files in PHP.
<?php
$fh=fopen("welcome.txt","r");
?>
r Read only. r+ Read/Write.
w Write only. w+ Read/Write.
a Append. a+ Read/Append.
x Create and open for write only. x+ Create and open for read/write.
If the fopen() function is unable to open
the specified file, it returns 0 (false).
<?php
if
( !($fh=fopen("welcome.txt","r")) )
exit("Unable to open file!");
?>
For w, and a, if no file exists, it tries to create it
(use with caution, i.e. check that this is the case,
otherwise you’ll overwrite an existing file).
For x if a file exists, this function fails (and
returns 0).
Form HandlingForm Handling
Any form element is automatically available via one of the built-in PHP variables (provided that
element has a “name” defined with it).
<html>
<-- form.html -->
<body>
<form action="welcome.php" method="POST">
Enter your name: <input type="text" name="name" /> <br/>
Enter your age: <input type="text" name="age" /> <br/>
<input type="submit" /> <input type="reset" />
</form>
</body>
</html>
<html>
<!–- welcome.php -->
<body>
Welcome <?php echo $_POST["name"].”.”; ?><br />
You are <?php echo $_POST["age"]; ?> years old!
</body>
</html>
$_POST
contains all POST data.
$_GET
contains all GET data.
Getting Time and DateGetting Time and Date
date() and time () formats a time or a date.
<?php
//Prints something like: Monday
echo date("l");
//Like: Monday 15th of January 2003 05:51:38 AM
echo date("l jS of F Y h:i:s A");
//Like: Monday the 15th
echo date("l the jS");
?>
date() returns a string
formatted according to the
specified format.
<?php
$nextWeek = time() + (7 * 24 * 60 * 60);
// 7 days; 24 hours; 60 mins; 60secs
echo 'Now: '. date('Y-m-d') ."n";
echo 'Next Week: '. date('Y-m-d', $nextWeek) ."n";
?>
time() returns
current Unix
timestamp
Main ProgramMain Program
/*Main Program*/
if (!$_POST["submit"])
{
?>
<h3>Please enter your information</h3>
<p>Fields with a "<b>*</b>" are required.</p>
<?php
print_form("","","","");
}
else{
check_form($_POST["f_name"],$_POST["l_name"],$_POST["email"],$_POST["os"]);
}
?>
</body>
</html>
Recommended Texts for LearningRecommended Texts for Learning
PHPPHP
• Larry Ullman’s books from the Visual Quickpro series
• PHP & MySQL for Dummies
• Beginning PHP 5 and MySQL: From Novice to
Professional by W. Jason Gilmore
o (This is more advanced and dense than the others, but great to read once
you’ve finished the easier books. One of the best definition/description of
object oriented programming I’ve read)
ThankThank You !!!You !!!
For More Information click below link:
Follow Us on:
http://vibranttechnologies.co.in/php-classes-in-mumbai.html

More Related Content

What's hot (20)

Introduction to php
Introduction to phpIntroduction to php
Introduction to php
Anjan Banda
 
Php
PhpPhp
Php
Ajaigururaj R
 
Php
PhpPhp
Php
Shyam Khant
 
HTTP request and response
HTTP request and responseHTTP request and response
HTTP request and response
Sahil Agarwal
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
Computer Hardware & Trouble shooting
 
Php introduction
Php introductionPhp introduction
Php introduction
krishnapriya Tadepalli
 
Uploading a file with php
Uploading a file with phpUploading a file with php
Uploading a file with php
Muhamad Al Imran
 
javascript objects
javascript objectsjavascript objects
javascript objects
Vijay Kalyan
 
PHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginnersPHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginners
Mohammed Mushtaq Ahmed
 
PHP Basic & Variables
PHP Basic & VariablesPHP Basic & Variables
PHP Basic & Variables
M.Zalmai Rahmani
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
Vibrant Technologies & Computers
 
An Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptAn Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java Script
Fahim Abdullah
 
Javascript
JavascriptJavascript
Javascript
mussawir20
 
PHP - Introduction to File Handling with PHP
PHP -  Introduction to  File Handling with PHPPHP -  Introduction to  File Handling with PHP
PHP - Introduction to File Handling with PHP
Vibrant Technologies & Computers
 
Php array
Php arrayPhp array
Php array
Nikul Shah
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Kengatharaiyer Sarveswaran
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in php
CPD INDIA
 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
Priya Goyal
 
Looping statement
Looping statementLooping statement
Looping statement
ilakkiya
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
Zeeshan Ahmed
 

Viewers also liked (12)

Introduction to FPDF
Introduction to FPDFIntroduction to FPDF
Introduction to FPDF
Jeremy Curcio
 
Pdf's in PHP
Pdf's in PHPPdf's in PHP
Pdf's in PHP
Gert Poppe
 
Reporting using FPDF
Reporting using FPDFReporting using FPDF
Reporting using FPDF
Mudasir Syed
 
File Uploading in PHP
File Uploading in PHPFile Uploading in PHP
File Uploading in PHP
Idrees Hussain
 
php file uploading
php file uploadingphp file uploading
php file uploading
Purushottam Kumar
 
Music Downloading Website (HTML,CSS,PHP Presentation)
Music Downloading Website (HTML,CSS,PHP Presentation)Music Downloading Website (HTML,CSS,PHP Presentation)
Music Downloading Website (HTML,CSS,PHP Presentation)
Anil Kumar
 
The FPDF Library
The FPDF LibraryThe FPDF Library
The FPDF Library
Dave Ross
 
MySQL Database with phpMyAdmin
MySQL Database with  phpMyAdminMySQL Database with  phpMyAdmin
MySQL Database with phpMyAdmin
Karwan Mustafa Kareem
 
Php File Upload
Php File UploadPhp File Upload
Php File Upload
Hiroaki Kawai
 
MySql:Exporting And Importing Data In Mysql
MySql:Exporting And Importing Data In MysqlMySql:Exporting And Importing Data In Mysql
MySql:Exporting And Importing Data In Mysql
DataminingTools Inc
 
PHP Project PPT
PHP Project PPTPHP Project PPT
PHP Project PPT
Pankil Agrawal
 
Introduction to microprocessor
Introduction to microprocessorIntroduction to microprocessor
Introduction to microprocessor
Kashyap Shah
 
Introduction to FPDF
Introduction to FPDFIntroduction to FPDF
Introduction to FPDF
Jeremy Curcio
 
Reporting using FPDF
Reporting using FPDFReporting using FPDF
Reporting using FPDF
Mudasir Syed
 
Music Downloading Website (HTML,CSS,PHP Presentation)
Music Downloading Website (HTML,CSS,PHP Presentation)Music Downloading Website (HTML,CSS,PHP Presentation)
Music Downloading Website (HTML,CSS,PHP Presentation)
Anil Kumar
 
The FPDF Library
The FPDF LibraryThe FPDF Library
The FPDF Library
Dave Ross
 
MySql:Exporting And Importing Data In Mysql
MySql:Exporting And Importing Data In MysqlMySql:Exporting And Importing Data In Mysql
MySql:Exporting And Importing Data In Mysql
DataminingTools Inc
 
Introduction to microprocessor
Introduction to microprocessorIntroduction to microprocessor
Introduction to microprocessor
Kashyap Shah
 
Ad

Similar to PHP - Introduction to PHP Fundamentals (20)

Prersentation
PrersentationPrersentation
Prersentation
Ashwin Deora
 
PHP
PHPPHP
PHP
sometech
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
Alokin Software Pvt Ltd
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
SHARANBAJWA
 
PHP
PHPPHP
PHP
Jawhar Ali
 
PHP ITCS 323
PHP ITCS 323PHP ITCS 323
PHP ITCS 323
Sleepy Head
 
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
Unit 5-PHP  Declaring variables, data types, array, string, operators, Expres...Unit 5-PHP  Declaring variables, data types, array, string, operators, Expres...
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
DRambabu3
 
Php
PhpPhp
Php
Vineet Vats
 
Materi Dasar PHP
Materi Dasar PHPMateri Dasar PHP
Materi Dasar PHP
Robby Firmansyah
 
introduction to php and its uses in daily
introduction to php and its uses in dailyintroduction to php and its uses in daily
introduction to php and its uses in daily
vishal choudhary
 
php basics
php basicsphp basics
php basics
NIRMAL FELIX
 
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Muhamad Al Imran
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdfWT_PHP_PART1.pdf
WT_PHP_PART1.pdf
HambardeAtharva
 
Php unit i
Php unit iPhp unit i
Php unit i
BagavathiLakshmi
 
Lecture8
Lecture8Lecture8
Lecture8
Majid Taghiloo
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
wahidullah mudaser
 
Introduction to-php
Introduction to-phpIntroduction to-php
Introduction to-php
AhmedAElHalimAhmed
 
PHP.pptx is the Best Explanation of ppts
PHP.pptx is the Best Explanation of pptsPHP.pptx is the Best Explanation of ppts
PHP.pptx is the Best Explanation of ppts
AkhileshPansare
 
Php tutorialw3schools
Php tutorialw3schoolsPhp tutorialw3schools
Php tutorialw3schools
rasool noorpour
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
Arjun Shanka
 
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
Unit 5-PHP  Declaring variables, data types, array, string, operators, Expres...Unit 5-PHP  Declaring variables, data types, array, string, operators, Expres...
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
DRambabu3
 
introduction to php and its uses in daily
introduction to php and its uses in dailyintroduction to php and its uses in daily
introduction to php and its uses in daily
vishal choudhary
 
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Muhamad Al Imran
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
wahidullah mudaser
 
PHP.pptx is the Best Explanation of ppts
PHP.pptx is the Best Explanation of pptsPHP.pptx is the Best Explanation of ppts
PHP.pptx is the Best Explanation of ppts
AkhileshPansare
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
Arjun Shanka
 
Ad

More from Vibrant Technologies & Computers (20)

Buisness analyst business analysis overview ppt 5
Buisness analyst business analysis overview ppt 5Buisness analyst business analysis overview ppt 5
Buisness analyst business analysis overview ppt 5
Vibrant Technologies & Computers
 
SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables  SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables
Vibrant Technologies & Computers
 
SQL- Introduction to MySQL
SQL- Introduction to MySQLSQL- Introduction to MySQL
SQL- Introduction to MySQL
Vibrant Technologies & Computers
 
SQL- Introduction to SQL database
SQL- Introduction to SQL database SQL- Introduction to SQL database
SQL- Introduction to SQL database
Vibrant Technologies & Computers
 
ITIL - introduction to ITIL
ITIL - introduction to ITILITIL - introduction to ITIL
ITIL - introduction to ITIL
Vibrant Technologies & Computers
 
Salesforce - Introduction to Security & Access
Salesforce -  Introduction to Security & Access Salesforce -  Introduction to Security & Access
Salesforce - Introduction to Security & Access
Vibrant Technologies & Computers
 
Data ware housing- Introduction to olap .
Data ware housing- Introduction to  olap .Data ware housing- Introduction to  olap .
Data ware housing- Introduction to olap .
Vibrant Technologies & Computers
 
Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.
Vibrant Technologies & Computers
 
Data ware housing- Introduction to data ware housing
Data ware housing- Introduction to data ware housingData ware housing- Introduction to data ware housing
Data ware housing- Introduction to data ware housing
Vibrant Technologies & Computers
 
Salesforce - classification of cloud computing
Salesforce - classification of cloud computingSalesforce - classification of cloud computing
Salesforce - classification of cloud computing
Vibrant Technologies & Computers
 
Salesforce - cloud computing fundamental
Salesforce - cloud computing fundamentalSalesforce - cloud computing fundamental
Salesforce - cloud computing fundamental
Vibrant Technologies & Computers
 
SQL- Introduction to PL/SQL
SQL- Introduction to  PL/SQLSQL- Introduction to  PL/SQL
SQL- Introduction to PL/SQL
Vibrant Technologies & Computers
 
SQL- Introduction to advanced sql concepts
SQL- Introduction to  advanced sql conceptsSQL- Introduction to  advanced sql concepts
SQL- Introduction to advanced sql concepts
Vibrant Technologies & Computers
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
Vibrant Technologies & Computers
 
SQL- Introduction to SQL Set Operations
SQL- Introduction to SQL Set OperationsSQL- Introduction to SQL Set Operations
SQL- Introduction to SQL Set Operations
Vibrant Technologies & Computers
 
Sas - Introduction to designing the data mart
Sas - Introduction to designing the data martSas - Introduction to designing the data mart
Sas - Introduction to designing the data mart
Vibrant Technologies & Computers
 
Sas - Introduction to working under change management
Sas - Introduction to working under change managementSas - Introduction to working under change management
Sas - Introduction to working under change management
Vibrant Technologies & Computers
 
SAS - overview of SAS
SAS - overview of SASSAS - overview of SAS
SAS - overview of SAS
Vibrant Technologies & Computers
 
Teradata - Architecture of Teradata
Teradata - Architecture of TeradataTeradata - Architecture of Teradata
Teradata - Architecture of Teradata
Vibrant Technologies & Computers
 
Teradata - Restoring Data
Teradata - Restoring Data Teradata - Restoring Data
Teradata - Restoring Data
Vibrant Technologies & Computers
 
Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.
Vibrant Technologies & Computers
 

Recently uploaded (20)

Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Impelsys Inc.
 
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training RoadblocksDown the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Domino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use CasesDomino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use Cases
panagenda
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Secure Access with Azure Active Directory
Secure Access with Azure Active DirectorySecure Access with Azure Active Directory
Secure Access with Azure Active Directory
VICTOR MAESTRE RAMIREZ
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data ResilienceFloods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Impelsys Inc.
 
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training RoadblocksDown the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Domino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use CasesDomino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use Cases
panagenda
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Secure Access with Azure Active Directory
Secure Access with Azure Active DirectorySecure Access with Azure Active Directory
Secure Access with Azure Active Directory
VICTOR MAESTRE RAMIREZ
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data ResilienceFloods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 

PHP - Introduction to PHP Fundamentals

  • 2. Introduction toIntroduction to PHP FundamentalsPHP Fundamentals
  • 3. GoalGoal • Not to teach everything about PHP, but provide the basic knowledge • Explain code of examples • Provide some useful references
  • 4. PHP Basics:PHP Basics: Introduction to PHP • a PHP file, PHP workings, running PHP.  Basic PHP syntax • variables, operators, if...else...and switch, while, do while, and for.  Some useful PHP functions  How to work with • HTML forms, cookies, files, time and date.  How to create a basic checker for user-entered data
  • 5. Server-Side Dynamic Web ProgrammingServer-Side Dynamic Web Programming • CGI is one of the most common approaches to server-side programming  Universal support: (almost) Every server supports CGI programming. A great deal of ready-to-use CGI code. Most APIs (Application Programming Interfaces) also allow CGI programming.  Choice of languages: CGI is extremely general, so that programs may be written in nearly any language. Perl is by far the most popular, with the result that many people think that CGI means Perl. But C, C++, Ruby, and Python are also used for CGI programming.  Drawbacks: A separate process is run every time the script is requested. A distinction is made between HTML pages and code.
  • 6. • Other server-side alternatives try to avoid the drawbacks  Server-Side Includes (SSI): Code is embedded in HTML pages, and evaluated on the server while the pages are being served. Add dynamically generated content to an existing HTML page, without having to serve the entire page via a CGI program.  Active Server Pages (ASP, Microsoft) : The ASP engine is integrated into the web server so it does not require an additional process. It allows programmers to mix code within HTML pages instead of writing separate programs. (Drawback(?) Must be run on a server using Microsoft server software.)  Java Servlets (Sun): As CGI scripts, they are code that creates documents. These must be compiled as classes which are dynamically loaded by the web server when they are run.  Java Server Pages (JSP): Like ASP, another technology that allows developers to embed Java in web pages.
  • 7. PHPPHP • developed in 1995 by Rasmus Lerdorf (member of the Apache Group)  originally designed as a tool for tracking visitors at Lerdorf's Web site  within 2 years, widely used in conjunction with the Apache server  developed into full-featured, scripting language for server-side programming  free, open-source  server plug-ins exist for various servers  now fully integrated to work with mySQL databases • PHP is similar to JavaScript, only it’s a server-side language  PHP code is embedded in HTML using tags  when a page request arrives, the server recognizes PHP content via the file extension (.php or .phtml)  the server executes the PHP code, substitutes output into the HTML page  the resulting page is then downloaded to the client  user never sees the PHP code, only the output in the page
  • 8. What do You Need?What do You Need? • Our server supports PHP o You don't need to do anything special! * o You don't need to compile anything or install any extra tools! o Create some .php files in your web directory - and the server will parse them for you. * Slightly different rules apply when dealing with an SQL database (as will be explained when we get to that point).
  • 9. What is PHP?What is PHP? • PHP == ‘Hypertext Preprocessor’ • Open-source, server-side scripting language • Used to generate dynamic web-pages • PHP scripts reside between reserved PHP tags o This allows the programmer to embed PHP scripts within HTML pages • The acronym PHP means (in a slightly recursive definition)  PHP: Hypertext Preprocessor
  • 10. What is PHP (cont’d)What is PHP (cont’d) • Interpreted language, scripts are parsed at run-time rather than compiled beforehand • Executed on the server-side • Source-code not visible by client o ‘View Source’ in browsers does not display the PHP code • Various built-in functions allow for fast development • Compatible with many popular databases
  • 11. What does PHP codeWhat does PHP code look like?look like? • Structurally similar to C/C++ • Supports procedural and object-oriented paradigm (to some degree) • All PHP statements end with a semi-colon • Each PHP script must be enclosed in the reserved PHP tag <?php … ?>
  • 12. Comments in PHPComments in PHP • Standard C, C++, and shell comment symbols // C++ and Java-style comment # Shell-style comments /* C-style comments These can span multiple lines */
  • 13. Variables in PHPVariables in PHP • PHP variables must begin with a “$” sign • Case-sensitive ($Foo != $foo != $fOo) • Global and locally-scoped variables o Global variables can be used anywhere o Local variables restricted to a function or class • Certain variable names reserved by PHP o Form variables ($_POST, $_GET) o Server variables ($_SERVER) o Etc.
  • 14. ConstantsConstants A constant is an identifier (name) for a simple value. A constant is case-sensitive by default. By convention, constant identifiers are always uppercase. <?php / Valid constant names define("FOO", "something"); define("FOO2", "something else"); define("FOO_BAR", "something more"); // Invalid constant names (they shouldn’t start // with a number!) define("2FOO", "something"); // This is valid, but should be avoided: // PHP may one day provide a “magical” constant // that will break your script define("__FOO__", "something"); ?> You can access constants anywhere in your script without regard to scope.
  • 15. OperatorsOperators • Arithmetic Operators: +, -, *,/ , %, ++, -- • Assignment Operators: =, +=, -=, *=, /=, %= • Comparison Operators: ==, !=, >, <, >=, <= • Logical Operators: &&, ||, ! • String Operators: . and .= (for string concatenation) Example Is the same as x+=y x=x+y x-=y x=x-y x*=y x=x*y x/=y x=x/y x%=y x=x%y $a = "Hello "; $b = $a . "World!"; // now $b contains "Hello World!" $a = "Hello "; $a .= "World!";
  • 16. Variable usageVariable usage <?php $foo = 25; // Numerical variable $bar = “Hello”; // String variable $foo = ($foo * 7); // Multiplies foo by 7 $bar = ($bar * 7); // Invalid expression ?>
  • 17. Basic PHP syntaxA PHP scripting block always starts with <?php and ends with ?>. A PHP scripting block can be placed (almost) anywhere in an HTML document. <html> <!-- hello.php --> <head><title>Hello World</title></head> <body> <p>This is going to be ignored by the PHP interpreter.</p> <?php echo ‘<p>While this is going to be parsed.</p>‘; ?> <p>This will also be ignored by the PHP preprocessor.</p> <?php print(‘<p>Hello and welcome to <i>my</i> page!</p>'); ?> <?php //This is a comment /* This is a comment block */ ?> </body> </html> print and echo for output a semicolon (;) at the end of each statement // for a single-line comment /* and */ for a large comment block.
  • 18. EchoEcho • The PHP command ‘echo’ is used to output the parameters passed to it • The typical usage for this is to send data to the client’s web-browser • Syntax • void echo (string arg1 [, string argn...]) • In practice, arguments are not passed in parentheses since echo is a language construct rather than an actual function
  • 19. Echo exampleEcho example • Notice how echo ‘5x5=$foo’ outputs $foo rather than replacing it with 25 • Strings in single quotes (‘ ’) are not interpreted or evaluated by PHP • This is true for both variables and character escape-sequences (such as “n” or “”) <?php $foo = 25; // Numerical variable $bar = “Hello”; // String variable echo $bar; // Outputs Hello echo $foo,$bar; // Outputs 25Hello echo “5x5=”,$foo; // Outputs 5x5=25 echo “5x5=$foo”; // Outputs 5x5=25 echo ‘5x5=$foo’; // Outputs 5x5=$foo ?>
  • 20. Arithmetic OperationsArithmetic Operations • $a - $b // subtraction • $a * $b // multiplication • $a / $b // division • $a += 5 // $a = $a+5 Also works for *= and /= <?php $a=15; $b=30; $total=$a+$b; Print $total; Print “<p><h1>$total</h1>”; // total is 45 ?>
  • 21. ConcatenationConcatenation • Use a period to join strings into one. <?php $string1=“Hello”; $string2=“PHP”; $string3=$string1 . “ ” . $string2; Print $string3; ?> Hello PHP
  • 22. Escaping the CharacterEscaping the Character • If the string has a set of double quotation marks that must remain visible, use the [backslash] before the quotation marks to ignore and display them. <?php $heading=“”Computer Science””; Print $heading; ?> “Computer Science”
  • 23. PHP Control StructuresPHP Control Structures Control Structures: Are the structures within a language that allow us to control the flow of execution through a program or script.  Grouped into conditional (branching) structures (e.g. if/else) and repetition structures (e.g. while loops).  Example if/else if/else statement: if ($foo == 0) { echo ‘The variable foo is equal to 0’; } else if (($foo > 0) && ($foo <= 5)) { echo ‘The variable foo is between 1 and 5’; } else { echo ‘The variable foo is equal to ‘.$foo; }
  • 24. If ... Else...If ... Else... • If (condition) { Statements; } Else { Statement; } <?php If($user==“John”) { Print “Hello John.”; } Else { Print “You are not John.”; } ?> No THEN in PHP
  • 25. Conditionals: if elseConditionals: if else<html><head></head> <!-- if-cond.php --> <body> <?php $d=date("D"); echo $d, “<br/>”; if ($d=="Fri") echo "Have a nice weekend! <br/>"; else echo "Have a nice day! <br/>"; $x=10; if ($x==10) { echo "Hello<br />"; echo "Good morning<br />"; } ?> </body> </html> if (condition) code to be executed if condition is true; else code to be executed if condition is false; date() is a built-in PHP function that can be called with many different parameters to return the date (and/or local time) in various formats In this case we get a three letter string for the day of the week.
  • 26. While LoopsWhile Loops • While (condition) { Statements; } <?php $count=0; While($count<3) { Print “hello PHP. ”; $count += 1; // $count = $count + 1; // or // $count++; ?> hello PHP. hello PHP. hello PHP.
  • 27. Can loop depending on a "counter"Can loop depending on a "counter" <?php for ($i=1; $i<=5; $i++) { echo "Hello World!<br />"; } ?> loops through a block of code a specified number of times <?php $a_array = array(1, 2, 3, 4); foreach ($a_array as $value) { $value = $value * 2; echo “$value <br/> n”; } ?> loops through a block of code for each element in an array <?php $a_array=array("a","b","c"); foreach ($a_array as $key => $value) { echo $key." = ".$value."n"; } ?>
  • 28. Date DisplayDate Display $datedisplay=date(“yyyy/m/d”); Print $datedisplay; # If the date is June 25th, 2012 # It would display as 2012/25/6 2012/25/6 $datedisplay=date(“l, F m, Y”); Print $datedisplay; # If the date is June 25th ,2012 # Monday, June 25th ,2012 Monday, June 25, 2012
  • 29. Month, Day & Date Format SymbolsMonth, Day & Date Format Symbols M Jan F January m 01 n 1 Day of Month d 01 Day of Month J 1 Day of Week l Monday Day of Week D Mon
  • 30. FunctionsFunctions • Functions MUST be defined before then can be called • Function headers are of the format o Note that no return type is specified • Unlike variables, function names are not case sensitive (foo(…) == Foo(…) == FoO(…)) function functionName($arg_1, $arg_2, …, $arg_n)
  • 31. Functions exampleFunctions example <?php // This is a function function foo($arg_1, $arg_2) { $arg_2 = $arg_1 * $arg_2; return $arg_2; } $result_1 = foo(12, 3); // Store the function echo $result_1; // Outputs 36 echo foo(12, 3); // Outputs 36 ?>
  • 32. Include FilesInclude Files Include “opendb.php”; Include “closedb.php”; This inserts files; the code in files will be inserted into current code. This will provide useful and protective means once you connect to a database, as well as for other repeated functions. Include (“footer.php”); The file footer.php might look like: <hr SIZE=11 NOSHADE WIDTH=“100%”> <i>Copyright © 2001-2012 gsu</i></font><br> <i>ALL RIGHTS RESERVED</i></font><br> <i>URL: http://www.gsu.edu.edu</i></font><br>
  • 33. PHP - FormsPHP - Forms •Access to the HTTP POST and GET data is simple in PHPAccess to the HTTP POST and GET data is simple in PHP •The global variables $_POST[] and $_GET[] contain the request dataThe global variables $_POST[] and $_GET[] contain the request data <?php if ($_POST["submit"]) echo "<h2>You clicked Submit!</h2>"; else if ($_POST["cancel"]) echo "<h2>You clicked Cancel!</h2>"; ?> <form action="form.php" method="post"> <input type="submit" name="submit" value="Submit"> <input type="submit" name="cancel" value="Cancel"> </form>
  • 34. WHY PHP – Sessions ?WHY PHP – Sessions ? Whenever you want to create aWhenever you want to create a websitewebsite that allows you to store and displaythat allows you to store and display information about a user, determine which user groups a person belongs to, utilizeinformation about a user, determine which user groups a person belongs to, utilize permissions on yourpermissions on your websitewebsite or you just want to do something cool on your site,or you just want to do something cool on your site, PHP's SessionsPHP's Sessions are vital toare vital to eacheach of these features.of these features. Cookies are about 30% unreliable right now and it's getting worse every day. More andCookies are about 30% unreliable right now and it's getting worse every day. More and more web browsers are starting to come with security and privacy settings and peoplemore web browsers are starting to come with security and privacy settings and people browsing the net these days are starting to frown upon Cookies because they storebrowsing the net these days are starting to frown upon Cookies because they store information on their local computer that they do not want stored there.information on their local computer that they do not want stored there. PHP has a great set of functions that can achieve the same results of Cookies andPHP has a great set of functions that can achieve the same results of Cookies and more without storing information on the user's computer. PHP Sessions store themore without storing information on the user's computer. PHP Sessions store the information on the web server in a location that you chose in special files. These filesinformation on the web server in a location that you chose in special files. These files are connected to the user's web browser via the server and a special ID called aare connected to the user's web browser via the server and a special ID called a "Session ID". This is nearly 99% flawless in operation and it is virtually invisible to the"Session ID". This is nearly 99% flawless in operation and it is virtually invisible to the user.user.
  • 35. PHP - SessionsPHP - Sessions •Sessions store their identifier in a cookie in the client’s browserSessions store their identifier in a cookie in the client’s browser •Every page that uses session data must be proceeded by theEvery page that uses session data must be proceeded by the session_start()session_start() functionfunction •Session variables are then set and retrieved by accessing the globalSession variables are then set and retrieved by accessing the global $_SESSION[]$_SESSION[] •Save it asSave it as session.phpsession.php <?php<?php session_start();session_start(); if (!$_SESSION["count"])if (!$_SESSION["count"]) $_SESSION["count"] = 0;$_SESSION["count"] = 0; if ($_GET["count"] == "yes")if ($_GET["count"] == "yes") $_SESSION["count"] = $_SESSION["count"] + 1;$_SESSION["count"] = $_SESSION["count"] + 1; echo "<h1>".$_SESSION["count"]."</h1>";echo "<h1>".$_SESSION["count"]."</h1>"; ?>?> <a href="session.php?count=yes">Click here to count</a><a href="session.php?count=yes">Click here to count</a>
  • 36. Avoid Error PHP - SessionsAvoid Error PHP - Sessions PHP Example: <?php echo "Look at this nasty error below:<br />"; session_start(); ?> Error! PHP Example: <?php session_start(); echo "Look at this nasty error below:"; ?> Correct Warning: Cannot send session cookie - headers already sent by (output started at session_header_error/session_error.php:2) in session_header_error/session_error.php on line 3 Warning: Cannot send session cache limiter - headers already sent (output started at session_header_error/session_error.php:2) in session_header_error/session_error.php on line 3
  • 37. Destroy PHP - SessionsDestroy PHP - Sessions Destroying a Session why it is necessary to destroy a session when the session will get destroyed when the user closes their browser. Well, imagine that you had a session registered called "access_granted" and you were using that to determine if the user was logged into your site based upon a username and password. Anytime you have a login feature, to make the users feel better, you should have a logout feature as well. That's where this cool function called session_destroy() comes in handy. session_destroy() will completely demolish your session (no, the computer won't blow up or self destruct) but it just deletes the session files and clears any trace of that session. NOTE: If you are using the $_SESSION superglobal array, you must clear the array values first, then run session_destroy. Here's how we use session_destroy():
  • 38. Destroy PHP - SessionsDestroy PHP - Sessions <?php // start the session session_start(); header("Cache-control: private"); //IE 6 Fix $_SESSION = array(); session_destroy(); echo "<strong>Step 5 - Destroy This Session </strong><br />"; if($_SESSION['name']){     echo "The session is still active"; } else {     echo "Ok, the session is no longer active! <br />";     echo "<a href="page1.php"><< Go Back Step 1</a>"; } ?>
  • 39. PHP OverviewPHP Overview • Easy learning • Syntax Perl- and C-like syntax. Relatively easy to learn. • Large function library • Embedded directly into HTML • Interpreted, no need to compile • Open Source server-side scripting language designed specifically for the web.
  • 40. PHP Overview (cont.)PHP Overview (cont.) • Conceived in 1994, now used on +10 million web sites. • Outputs not only HTML but can output XML, images (JPG & PNG), PDF files and even Flash movies all generated on the fly. Can write these files to the file system. • Supports a wide-range of databases (20+ODBC). • PHP also has support for talking to other services using protocols such as LDAP, IMAP, SNMP, NNTP, POP3, HTTP.
  • 41. • Save as sample.php: <!– sample.php --> <html><body> <strong>Hello World!</strong><br /> <?php echo “<h2>Hello, World</h2>”; ?> <?php $myvar = "Hello World"; echo $myvar; ?> </body></html> First PHP scriptFirst PHP script
  • 42. Example of parameter readingExample of parameter reading • Consider: • contents of php_exec/form.php... • <html><body> • <h1>Hi there</h1> • <? if (!isset($_POST['foo'])): ?> • <h1>'foo' is not set</h1> • <? elseif (!is_array($_POST['foo'])) : ?> • <h1>'foo' has one value <?= $_POST['foo'] ?> </h1> • <? else: ?> • <h1>'foo' has multiple values <?= join(',',$_POST['foo']) ?> </h1> • <? endif ?> • </body></html> • ...end of php_exec/form.php • Call with form: • contents of php_exec/form01.txt... <form action='php_exec/form.php' method='post'> <ul> <li> <input type='checkbox' name='foo[]' value='raisins'> raisins. <li> <input type='checkbox' name='foo[]' value='cranberries'> cranberries. <li> <input type='checkbox' name='foo[]' value='plums'> plums. </ul> <input type='submit'> </form> ...end of php_exec/form01.txt • Here is what it looks like: o  raisins. o  cranberries. o  plums.
  • 43. Example – show data inExample – show data in the tablesthe tables • Function: list all tables in your database. Users can select one of tables, and show all contents in this table. • second.php • showtable.php
  • 44. second.phpsecond.php <html><head><title>MySQL Table Viewer</title></head><body> <?php // change the value of $dbuser and $dbpass to your username and password $dbhost = ‘ codd.cs…….. '; $dbuser = 'nruan'; $dbpass = ‘*****************’; $dbname = $dbuser; $table = 'account'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if (!$conn) { die('Could not connect: ' . mysql_error()); } if (!mysql_select_db($dbname)) die("Can't select database");
  • 45. second.php (cont.)second.php (cont.) $result = mysql_query("SHOW TABLES"); if (!$result) { die("Query to show fields from table failed"); } $num_row = mysql_num_rows($result); echo "<h1>Choose one table:<h1>"; echo "<form action="showtable.php" method="POST">"; echo "<select name="table" size="1" Font size="+2">"; for($i=0; $i<$num_row; $i++) { $tablename=mysql_fetch_row($result); echo "<option value="{$tablename[0]}" >{$tablename[0]}</option>"; } echo "</select>"; echo "<div><input type="submit" value="submit"></div>"; echo "</form>"; mysql_free_result($result); mysql_close($conn); ?> </body></html>
  • 46. showtable.phpshowtable.php<html><head> <title>MySQL Table Viewer</title> </head> <body> <?php $dbhost = 'hercules.cs.kent.edu:3306'; $dbuser = 'nruan'; $dbpass = ‘**********’; $dbname = 'nruan'; $table = $_POST[“table”]; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if (!$conn) die('Could not connect: ' . mysql_error()); if (!mysql_select_db($dbname)) die("Can't select database"); $result = mysql_query("SELECT * FROM {$table}"); if (!$result) die("Query to show fields from table failed!" . mysql_error());
  • 47. showtable.php (cont.)showtable.php (cont.) $fields_num = mysql_num_fields($result); echo "<h1>Table: {$table}</h1>"; echo "<table border='1'><tr>"; // printing table headers for($i=0; $i<$fields_num; $i++) { $field = mysql_fetch_field($result); echo "<td><b>{$field->name}</b></td>"; } echo "</tr>n"; while($row = mysql_fetch_row($result)) { echo "<tr>"; // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row as $cell) echo "<td>$cell</td>"; echo "</tr>n"; } mysql_free_result($result); mysql_close($conn); ?> </body></html>
  • 48. Functions CoveredFunctions Covered • mysql_connect() mysql_select_db() • include() • mysql_query() mysql_num_rows() • mysql_fetch_array() mysql_close()
  • 49. PHP InformationPHP Information The phpinfo() function is used to output PHP information about the version installed on the server, parameters selected when installed, etc. <html><head></head> <!– info.php <body> <?php // Show all PHP information phpinfo(); ?> <?php // Show only the general information phpinfo(INFO_GENERAL); ?> </body> </html> INFO_GENERAL The configuration line, php.ini location, build date, Web Server, System and more INFO_CREDITS PHP 4 credits INFO_CONFIGURATION Local and master values for php directives INFO_MODULESLoaded modules INFO_ENVIRONMENT Environment variable information INFO_VARIABLES All predefined variables from EGPCS INFO_LICENSE PHP license information INFO_ALL Shows all of the above (default)
  • 50. Server VariablesServer VariablesThe $_SERVER array variable is a reserved variable that contains all server information. <html><head></head> <body> <?php echo "Referer: " . $_SERVER["HTTP_REFERER"] . "<br />"; echo "Browser: " . $_SERVER["HTTP_USER_AGENT"] . "<br />"; echo "User's IP address: " . $_SERVER["REMOTE_ADDR"]; ?> <?php echo "<br/><br/><br/>"; echo "<h2>All information</h2>"; foreach ($_SERVER as $key => $value) { echo $key . " = " . $value . "<br/>"; } ?> </body> </html> The $_SERVER is a super global variable, i.e. it's available in all scopes of a PHP script. $_SERVER info on php.net
  • 51. File OpenFile Open The fopen("file_name","mode") function is used to open files in PHP. <?php $fh=fopen("welcome.txt","r"); ?> r Read only. r+ Read/Write. w Write only. w+ Read/Write. a Append. a+ Read/Append. x Create and open for write only. x+ Create and open for read/write. If the fopen() function is unable to open the specified file, it returns 0 (false). <?php if ( !($fh=fopen("welcome.txt","r")) ) exit("Unable to open file!"); ?> For w, and a, if no file exists, it tries to create it (use with caution, i.e. check that this is the case, otherwise you’ll overwrite an existing file). For x if a file exists, this function fails (and returns 0).
  • 52. Form HandlingForm Handling Any form element is automatically available via one of the built-in PHP variables (provided that element has a “name” defined with it). <html> <-- form.html --> <body> <form action="welcome.php" method="POST"> Enter your name: <input type="text" name="name" /> <br/> Enter your age: <input type="text" name="age" /> <br/> <input type="submit" /> <input type="reset" /> </form> </body> </html> <html> <!–- welcome.php --> <body> Welcome <?php echo $_POST["name"].”.”; ?><br /> You are <?php echo $_POST["age"]; ?> years old! </body> </html> $_POST contains all POST data. $_GET contains all GET data.
  • 53. Getting Time and DateGetting Time and Date date() and time () formats a time or a date. <?php //Prints something like: Monday echo date("l"); //Like: Monday 15th of January 2003 05:51:38 AM echo date("l jS of F Y h:i:s A"); //Like: Monday the 15th echo date("l the jS"); ?> date() returns a string formatted according to the specified format. <?php $nextWeek = time() + (7 * 24 * 60 * 60); // 7 days; 24 hours; 60 mins; 60secs echo 'Now: '. date('Y-m-d') ."n"; echo 'Next Week: '. date('Y-m-d', $nextWeek) ."n"; ?> time() returns current Unix timestamp
  • 54. Main ProgramMain Program /*Main Program*/ if (!$_POST["submit"]) { ?> <h3>Please enter your information</h3> <p>Fields with a "<b>*</b>" are required.</p> <?php print_form("","","",""); } else{ check_form($_POST["f_name"],$_POST["l_name"],$_POST["email"],$_POST["os"]); } ?> </body> </html>
  • 55. Recommended Texts for LearningRecommended Texts for Learning PHPPHP • Larry Ullman’s books from the Visual Quickpro series • PHP & MySQL for Dummies • Beginning PHP 5 and MySQL: From Novice to Professional by W. Jason Gilmore o (This is more advanced and dense than the others, but great to read once you’ve finished the easier books. One of the best definition/description of object oriented programming I’ve read)
  • 56. ThankThank You !!!You !!! For More Information click below link: Follow Us on: http://vibranttechnologies.co.in/php-classes-in-mumbai.html