You are on page 1of 69

PROGRAMMING IN PHP

(16SCCCA6P/16SCCCS6P)

LABORATORY MANUAL
Handled By
Mr.S.Boobalathandayuthapani

Mr.S.Tamilselvan

Register Number
Name

DEPARTMENT OF COMPUTER SCIENCE


VALLUVAR COLLEGE OF SCIENCE AND MANAGEMENT
(Affiliated to Bharathidasan University, Trichy)
Karur-Madurai National Highway(NH-7),
Puthambur(Post),
Karur-639 003.

DECEMBER 2020

Copyright © VALLUVAR COLLEGE OF SCIENCE AND MANAGEMENT


GRADE SHEET

Register Number Name

Year Semester

Instructor Name

Ex.No Lab Exercise Date Grading Details Signature


Getting started to work with Initial and learn
1
how to do basic programs.

Practical understand of Conditional Statements


2
and its types

3 Array Concepts

4 Functions and its usages

5 Designing a Webpage

6 Designing Date Related Programs

7 File Operations

8 PHP Cookies

9 PHP Session

10 Image Processing in PHP

11 Designing a Simple Calculator

12 Working with Database


TABLE OF CONTENTS

Duration Programs Page No


Getting started to work with Initial and learn how to do basic programs
 Application to Add Two Numbers using PHP and HTML using Form Method
Week1  Program to Print Subtraction, Multiplication and Division of two Values 7
 Calculate the Factorial Number from user input

Practical understand of Conditional Statements and its types


 Application to Check given Number is odd or Even using PHP and HTML using Form
Method
Week2  Program to Check Biggest of Three Number using If, elseif Statement. 11
 Program to do Arithmetic Operations using Switch statement.
 Program to check the given number is negative or positive.

Array Concepts
 Application to Find Minimum Value from an Array
Week3  Program to Change instead of Colon(:) to make like (@,#,%,&). 16
 Program to Find Maximum Number from Multidimensional Array.

Functions and its usages


 Application to Check the given Number is Prime number or not using Functions
Week4  Program to solve Sum of Natural Numbers Using Recursion 21
 Create user-defined functions to solve GCD(Greatest Common Divisor) Using Recursion

Designing a Webpage
 Application to Generate Addition Table
Week5  Generate the Table for Subtraction and Division 26
 Generate Multiplication table for the given numbers

Designing Date Related Programs


 Application to show the Current age, month and days.
Week6  program to find the month, year and date for the given day 30
 Compute the current age of the given date of birth

File Operations
 Application to List out the folders and files
Week7  Program to list out the files present in the given directory. 34
 Program to download a file from the server

PHP Cookies
 Cookies - Basic Programs
Week8 38
 Program to show the “Last Visited” date and time of a webpage.

PHP Session
 Session - Basic Programs
Week9 43
 Program to show the number of views (Count) of a website.

Image Processing in PHP


 How to draw a circle
Week10 48
 Program to draw a Face using image creation.

Designing a Simple Calculator


Week11  Program to make a Simple Calculator 51

Working with Database


 Program to design database operations
Week12  Program to design login page with validation 55
 Program to design Signup page
16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Introduction to PHP

PHP stands for Hypertext Preprocessor. PHP is a very popular and


widely-used open source server-side scripting language to write dynamically
generated web pages. PHP was originally created by Rasmus Lerdorf in 1994.
It was initially known as Personal Home Page.

PHP scripts are executed on the server and the result is sent to the web
browser as plain HTML. PHP can be integrated with the number of popular
databases, including MySQL, PostgreSQL, Oracle, Microsoft SQL Server,
Sybase, and so on. The current major version of PHP is 8.
There are lots more things to do with PHP.

 Generate pages and files dynamically.


 Create, open, read, write and close files on the server.
 Collect data from a web form such as user information, email, phone no, etc.
 Send emails to the users of your website.
 Send and receive cookies to track the visitor of your website.
 Store, delete, and modify information in your database.
 Restrict unauthorized access to your website.
 Encrypt data for safe transmission over internet.

What is PHP

PHP is an open source, interpreted and object-oriented scripting language


i.e. executed at server side. It is used to develop web applications (an
application i.e. executed at server side and generates dynamic page).

 PHP is a server side scripting language.


 PHP is an interpreted language, i.e. there is no need for compilation.
 PHP is an object-oriented language.
 PHP is an open-source scripting language.
 PHP is simple and easy to learn language.

Department of Computer Science, Valluvar College of Science and Management - Karur 1


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Advantages of PHP over Other Languages

If you're familiar with other server-side languages like ASP.NET or Java,


you might be wondering what makes PHP so special. There are several
advantages why one should choose PHP.

 Easy to learn: PHP is easy to learn and use. For beginner programmers who
just started out in web development, PHP is often considered as the preferable
choice of language to learn.
 Open source: PHP is an open-source project. It is developed and maintained by
a worldwide community of developers who make its source code freely available
to download and use.
 Portability: PHP runs on various platforms such as Microsoft Windows, Linux,
Mac OS, etc. and it is compatible with almost all servers used today such Apache,
IIS, etc.
 Fast Performance: Scripts written in PHP usually execute or runs faster than
those written in other scripting languages like ASP, Ruby, Python, Java, etc.
 Vast Community: Since PHP is supported by the worldwide community, finding
help or documentation related to PHP online is extremely easy.

PHP Features

The features of PHP are follows.

o Performance: Script written in PHP executes much faster than those


scripts written in other languages such as JSP & ASP.
o Open Source Software: PHP source code is freed available on the web
developed all the version of PHP according to your requirement without
paying any cost.
o Platform Independent: PHP are available for WINDOWS, MAC, LINUX &
UNIX operating system. A PHP application developed in one OS can be
easily executed in other OS also.
o Compatibility: PHP is compatible with almost all local servers used today
like Apache, IIS etc.
o Embedded: PHP code can be easily embedded within HTML tags and
script.

Department of Computer Science, Valluvar College of Science and Management - Karur 2


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Web Development

PHP is widely used in web development now a day. PHP can develop
dynamic websites easily. But you must have the basic the knowledge of following
technologies for web development as well.

o HTML
o CSS
o JavaScript
o Ajax
o XML and JSON
o jQuery

PHP Installation

To install PHP, we will suggest you to install AMP (Apache, MySQL, PHP)
software stack. It is available for all operating systems. There are many AMP
options available in the market that is given below:

o WAMP for Windows (Windows, Apache, MySQL, PHP)


o LAMP for Linux (Linux, Apache, MySQL, PHP)
o MAMP for Mac (Mac OS, Apache, MySQL, PHP)
o SAMP for Solaris (Solaris, Apache, MySQL, PHP)
o XAMPP (Cross, Apache, MySQL, PHP, Perl) for Cross Platform: It includes
some other components too such as FileZilla, OpenSSL, Webalizer,
Mercury Mail etc.
o FAMP for FreeBSD

If you are on Windows and don't want Perl and other features of XAMPP,
you should go for WAMP. In a similar way, you may use LAMP for Linux and
MAMP for Macintosh.

Department of Computer Science, Valluvar College of Science and Management - Karur 3


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Week 1 Laboratory: To Understand the PHP usage and how to work with Initial and
learn to do basic programs and solve related to it.

DATE:

Getting Started with PHP after installation

Step 1: After Login in to the Windows 7

Step 2: Now we have to start the server to create the Local Hosting Environment to
make the real feel of server side operations.

Department of Computer Science, Valluvar College of Science and Management - Karur 4


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Step 3: After Started the Server it looks like and you minimize it.

Step 4: To check whether the server is working properly or not.

Take any one of the browser like Chrome, Mozilla, Internet Explorer etc.

Open the Browser here we take Chrome to check whether localhost is properly
connected or not.

Department of Computer Science, Valluvar College of Science and Management - Karur 5


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Step 5: Open the Notepad for typing Program, before that you all know how to type
java programs in notepad, same like that but with some similar changes. You have to
follow the following steps.

 Now you have successfully Started WAMP Server on your computer.


o We will create a very simple PHP script that displays the text "Hello,
world!" in the browser window.
o Ok, click on the WAMP icon somewhere on your Windows task bar and
select the “www directory". Alternatively, you can access the "www"
directory through navigating the C:\wamp\www. Create a subdirectory
in "www” directory let's say "your Register number (CB16SXXXXXXX)".
 Now open up your favorite code editor like Notepad and create a new PHP file.
Type the following code:

<?php
// Display greeting message
echo "Hello, world!";
?>

 Now save this file as "hello.php" in your project folder


(Located at C:\wamp\www\CB16SXXXXXXX), and
view the result in your browser through visiting this URL:
http://localhost/CB16SXXXXXXX/hello.php
 PHP can be embedded within a normal HTML web page. That means inside your
HTML document you can write the PHP statements, as demonstrated in the
following example:
<html>
<head>
<title>PHP Application</title>
</head>
<body>
<?php
// Display greeting message
echo 'Hello World!';
?>
</body>
</html>

Department of Computer Science, Valluvar College of Science and Management - Karur 6


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Week 1 Laboratory: Understand the PHP usage and how to work with Initial
and learn to do basic programs.

DATE:

Sample Exercise: Application to Add Two Numbers using PHP and HTML
using Form Method

Input Read the Two Numbers and Post the Value From html to PHP
Output Sum of Two Numbers
Process Use Textbox to feed values and press Submit button to run.
Test Cases Input Expected Output Obtained Output
10,20 30 ????

Design
 Place Two Input Box for getting Input A and B
 Enter two Value and get the Result

Department of Computer Science, Valluvar College of Science and Management - Karur 7


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Source Code
<html>
<head>
<title>Addition Program </title>
</head>
<body>
<form method="post">
Enter the First Number:<br>
<input type="text" name="a"> <br>
Enter the Second Number:<br>
<input type="text" name="b"> <br>
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if($_POST){
//Assign A and B Value
$a = $_POST['a'];
$b = $_POST['b'];
//Calculate the Addition
$c=$a+$b;
//Print the Result
echo "The Addition of $a and $b is :".$c;
}
?>
</body>
</html>
Extra Credit
Modify the Program to Print Subtraction, Multiplication and Division of two Values.
 Now you all know how to assign the Values in PHP and How to Embedded HTML
in PHP.

Exercise
In our Lab Exercise 1, need to Calculate the Factorial Number from user input.
What is Factorial?
It means multiply the value from 1 to user given input
If input is 5 means then (1 X 2 X3 X4 X 5) = so the Result will be 120.
Condition is
 If the input is 0(Zero) means then Result will be 1.
 Don’t Accept any Negative Values Like -1 or else.
Hint
You Must have to Know For Loop in PHP. (Example)
<?php
for($i=1; $i<=3; $i++){
echo "The number is " . $i . "<br>";
}
?>
Algorithm:
Initialize variables : factorial←1,Assign value of n,
Repeat the steps until i=n factorial←factorial*i , Display factorial Result

Department of Computer Science, Valluvar College of Science and Management - Karur 8


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 9


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 10


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Week 2 Laboratory: Practical understanding of Conditional Statements and


its types.

DATE:

Like most programming languages, PHP also allows you to write code that
perform different actions based on the results of a logical or comparative test conditions
at run time. This means, you can create test conditions in the form of expressions that
evaluates to either true or false and based on these results you can perform certain
actions.
There are several control statements in PHP that you can use and make decisions:
 The if statement
 The if...else statement
 The if...elseif....else statement
 The switch...case statement

Statement Syntax Example


if(condition){ 1. <?php
// Code to be executed
} 2. $num=12;
3. if($num<100){
if
4. echo "$num is less than 100";
5. }
6. ?>
if(condition){ 1. <?php
// Code to be
executed if condition 2. $num=12;
is true 3. if($num%2==0){
} else{
4. echo "$num is even number";
if...else // Code to be
executed if condition 5. }else{
is false 6. echo "$num is odd number";
}
7. }
8. ?>
if(condition1){ <?php
// Code to be executed $a=10;$b=20;
if condition1 is true if ($a > $b) {
} elseif(condition2){ echo "a is bigger than b";
// Code to be executed } elseif ($a == $b) {
if the condition1 is echo "a is equal to b";
if...elseif....else
false and condition2 is } else {
true } else{ echo "a is smaller than b";
// Code to be executed }
if both condition1 and ?>
condition2 are false
}

Department of Computer Science, Valluvar College of Science and Management - Karur 11


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

switch(n){ <?php
case label1: $num=20;
// Code to be executed switch($num){
if n=label1 case 10:
break; echo("number is equals to 10");
case label2: break;
// Code to be executed case 20:
if n=label2 echo("number is equal to 20");
break; ... break;
switch...case
default: case 30:
// Code to be executed echo("number is equal to 30");
if n is different from break;
all labels default:
} echo("number is not equal to 10,
20 or 30");
}
?>

Sample Exercise: Application to Check given Number is odd or even using


PHP and HTML using Form Method

Input Read the Number and Post the Value From html to PHP
Output To Check the Given Number is Odd or Even Using Conditional Statement
Process Use Textbox to feed values and press Submit button to run.
Test Cases Input Expected Output Obtained Output
10 Even Number ????
5 Odd Number ????

Design
 Place an Input Box for getting the Input and Print the Result

Department of Computer Science, Valluvar College of Science and Management - Karur 12


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Source Code
<html>
<head>
<title>Odd or Even checking using conditional Statement </title>
</head>
<body>
<form method="post">
Enter the Number:<br>
<input type="text" name="num"> <br> <br>
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if($_POST){
//Getting User Value and Assign
$num = $_POST['num'];
//Check Odd or Even and Print Result
if ($num%2==0) {
echo "The Given $num is Even Number<br> ";
}
else {
echo "The Given $num is Odd Number<br> ";
}
}
?>
</body>
</html>
Extra Credit
1. Modify or Create a Program to Check Biggest of Three Numbers with If, elseif
Statement.
2. Create an Arithmetic Operations program (Example : if we give 1 Means Addition
of Two values, 2 Means Subtraction ,3 Means Multiplication and 4 Means
Division) using Switch statement. Use the Idea of Last Week Module and Solve it.

Exercise
In our Lab Exercise 2 we need to use Conditional Statement
 To check the given inputted number is negative or positive.
If We Give, 10 Means Positive Number
If We Give, -10 Means Negative Number
Hint
 Check the given number is Greater than Zero it must be Positive otherwise it
must be Negative

Department of Computer Science, Valluvar College of Science and Management - Karur 13


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 14


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 15


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Week 3 Laboratory: To know about Array Concept in PHP.

DATE:

Arrays are complex variables that allow us to store more than one value or
a group of values under a single variable name.

Types of Arrays in PHP


There are three types of arrays. They are:
 Indexed array — an array with a numeric key.
 Associative array — an array where each key has its own specific value.
 Multidimensional array — an array containing one or more arrays
within it.
Array Type Example Output
<?php 7.
$colors = array("Red","Green","Blue");
Indexed array // Printing array structure
print_r($colors);
?>
<?php
$ages = array("Peter"=>22, "Clark"=>32,
"John"=>28);
Associative array // Printing array structure
print_r($ages);
?>
<?php // Define nested array
$contacts = array(
array(
"name" => "Peter Parker",
"email" =>
"peterparker@mail.com",
),
array(
"name" => "Clark Kent",
"email" => "clarkkent@mail.com",
Multidimensional ),
array array(
"name" => "Harry Potter",
"email" =>
"harrypotter@mail.com",
)
);
// Access nested value
echo "Peter Parker's Email-id is: " .
$contacts[0]["email"];print_r($contacts);
?>

Department of Computer Science, Valluvar College of Science and Management - Karur 16


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Sample Exercise: Application to Find the Minimum Value from an Array

Input Read the Numbers and Post the Value From html to PHP
Output To Find the Minimum from Array
Process Use Text Area to feed values and press Submit button to get result.
Test Cases Input Expected Output Obtained Output
2:3:5:1:4 1(Minimum) ????

Design

Before After Result

Department of Computer Science, Valluvar College of Science and Management - Karur 17


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Source Code
<html>
<head>
<title>Small Value in Muldimensional Array</title>
</head>
<body>
<form method="post">
Enter the numbers with Colon(:) like 2:3:5:1:4<br>
<textarea name="a"> </textarea> <br>
<input type="submit" name="submit" value="Find Minimum Value" />
</form>
</body>
</html>
<?php
if($_POST){
$a=$_POST['a'];
//to filter array values of given symbol
$new = array_values(array_filter(explode(':', $a)));
//print_r($new);
echo "The Values in the array as <br> ";
$b = 999;
//to take the value from array one by one
foreach ($new as $val) {
echo $val."<br>";
if ($val < $b) {
$b = $val;
}
}
echo "The Minimum Value is ".$b;
}
?>
Extra Credit
1. Modify or Create a program to Change instead of Colon Give like (@,#,%,&) to
Check the Program flow of above.

Exercise
In our Lab Exercise 3 we need to use Multidimensional Array to Find Maximum
Number.
Use Comma (,) to add number in Text area box like (2, 7, 6, 1, 2) among these values
find the maximum.
Hint
 Same as above example, have to find maximum value in multidimensional array

Department of Computer Science, Valluvar College of Science and Management - Karur 18


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 19


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 20


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Week 4 Laboratory: Functions and its usage.

DATE:

A function is a self-contained block of code that performs a specific task.

PHP Built-in Functions


PHP has a huge collection of internal or built-in functions that you can call
directly within your PHP scripts to perform a specific task, like gettype(), print_r(),
var_dump, etc.
PHP User-Defined Functions
PHP also allows you to define your own functions. It is a way to create reusable
code packages that perform specific tasks and can be kept and maintained separately
form main program. Here are some advantages of using functions:
 Functions reduces the repetition of code within a program
 Functions makes the code much easier to maintain
 Functions makes it easier to eliminate the errors
 Functions can be reused in other application

Syntax Example Output


function functionName(){ <?php 8. Sum of the two
// Code to be executed // Defining function
function getSum($num1, $num2){ numbers 10 and 20
}
$sum = $num1 + $num2; is : 30
echo "Sum of the two numbers
$num1 and $num2 is : $sum";
}
// Calling function
getSum(10, 20);
?>

Department of Computer Science, Valluvar College of Science and Management - Karur 21


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Sample Exercise: Application to Check the Given Number is Prime number or


not using Functions.

Input Read the Number and Post the Value From html to PHP
Output To check whether number is prime or not
Process Use Text Area to feed values and press Submit button to get result.
Test Cases Input Expected Output Obtained Output
2 Prime Numer ????
4 Not Prime Numer ????

Design
 Place Input Box for getting Input and check the value its prime or not.

Department of Computer Science, Valluvar College of Science and Management - Karur 22


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Source Code
<html>
<head>
<title>Prime number or Not</title>
</head>
<body>
<form method="post">
Enter the Number to check Prime number or Not<br>
<input type="text" name="n"> <br>
<input type="submit" name="submit" value="Check" />
</form>
</body>
</html>
<?php
if($_POST){
$n=$_POST['n'];
$check = IsPrime($n);
if ($check==0)
echo 'This is not a Prime Number.....'."\n";
else
echo 'This is a Prime Number..'."\n";
}
function IsPrime($n)
{
for($x=2; $x<$n; $x++)
{
if($n%$x ==0) { return 0;
}
}
return 1;
}

?>
Extra Credit
1. Create a program using Function to solve Sum of Natural Numbers using
Recursion.
Logic : addNumbers(n){ if(n != 0) return (n + addNumbers(n-1));else return n; }

Exercise
In our Lab Exercise 4 we need to Create user-defined function to solve GCD
(Greatest Common Divisor) Using Recursion.
Example : Given Value 1 is 36 = 2X2X3X3 and Given Value 2 is 60 = 2X2X3X5 then Multiply Common
Factor is (2X2X3=12) So GCD or HCF for 36 and 60 is 12
Hint
Algorithm: function hcf($n1, $n2)
{ if ($n2 != 0) return hcf($n2, $n1%$n2);
else return $n1; }

Department of Computer Science, Valluvar College of Science and Management - Karur 23


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 24


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 25


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Week 5 Laboratory: Designing a Webpage.

DATE:

Sample Exercise: Application to Generate Addition Table

Input Read two numbers, one for range and another for table value
Output To generate a table for the corresponding range
Process Use textbox and buttons to process data

Design

Department of Computer Science, Valluvar College of Science and Management - Karur 26


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Source Code
<html>
<head>
<title>Generate Table</title>
</head>
<body>
<form method=‛post‛>
<h2>Addition Table</h2>
<table>
<tr>
<td>Enter the Table number </td>
<td><input type=‛text‛ name=‛tn‛></td>
</tr>
<tr>
<td>Enter the Range </td>
<td><input type=‛text‛ name=‛tr‛></td>
</tr>
<tr>
<td></td>
<td><input type=‛submit‛ name=‛submit‛ value=‛Generate Table‛ /></td>
</tr>
</table>
</form>
<?php
if($_POST){
$tn = $_POST[‘tn’];
$tr=$_POST[‘tr’];
echo ‚Addition Table for $tn as<br><br>‛;
for ($i = 1; $i <= $tr; $i++){
echo $i.‛ + ‚.$tn.‛ = ‚.($tn+$i).‛<br>‛;
}
}
?>
</body>
</html>
Extra Credit
1. Generate the Table for Subtraction and Division like same as above but you
must implement two button one for Subtraction and another for Division. If we
click Subtraction a subtraction table has to generate else if we click Division a
division table has to generate.

Exercise
In our Lab Exercise 5 we need to Generate Multiplication table for a given
number.
Hint
Use the Sample Program as model to do multiplication table.

Department of Computer Science, Valluvar College of Science and Management - Karur 27


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 28


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 29


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Week 6 Laboratory: Designing Date Related Programs.

DATE:

Sample Exercise: Application to show the Current age, month and days.

Input Assign any date


Output To show Current age, month and days.

Design /Output

Source Code
<?php
$bday = new DateTime(‘11.4.1987’); // Your date of birth
$today = new Datetime(date(‘m.d.y’));
$diff = $today->diff($bday);
echo ‚Your age : $diff->y years, $diff->m month, $diff->d days<br>‛;
?>
Extra Credit
1. Using the above model program, make one text box to enter the date as
DD.MM.YYYY format and post the value to find the year, month and days using
html and php.

Department of Computer Science, Valluvar College of Science and Management - Karur 30


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Exercise
In our Lab Exercise 6 we need to Compute the age of a person from his/her Date Of
Birth. To find present age have to deduce the DOB from current date and get the age.
The screen is like as
Screen1 Input

Screen2 Ouput

Hint
Use Date Time Selection HTML as

<input type="date" name="dob">

Use in PHP as

$dob=$_POST["dob"];
$dob = date("Y-m-d",strtotime($dob));
$dobObject = new DateTime($dob);
$nowObject = new DateTime();
$diff = $dobObject->diff($nowObject);
echo "Age is ".$diff->y;

Department of Computer Science, Valluvar College of Science and Management - Karur 31


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 32


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 33


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Week 7 Laboratory: File Operations

DATE:

PHP File System

It allows you to work with files and directories stored on the web server.

Sample Exercise: Application to List out the folders and files

Input Assign any of folder (c:\test)


Output To show the list of file on corresponding folder

Design

Department of Computer Science, Valluvar College of Science and Management - Karur 34


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Source Code
<?php
$dir = "c:/wamp";
$allFiles = scandir($dir);
$files = array_diff($allFiles, array('.', '..')); // To remove . and ..
echo "<b><u>".$dir." Which has following files as ....</u> </b><br>";
foreach($files as $file){
echo $file."<br>";
}
?>

Extra Credit
1. Create a program using File, for the given folder path in text box it have to list
out the files in corresponding folder.

Exercise
In our Lab Exercise 7 Program to download a file from the server.
Hint
Step 1: Here we have know about anchor tag in html for example
<a href=‛Your File Path‛>Any Name</a>
Use this List out File in php.
Step 2: Create a folder named File, In File folder create two php files one as
index.php and another as download.php.
Index.php for list out files
Download.php for check file exist or not and download.

Script for Download.php

<?php
$filename = basename($_GET['file']);
// Specify file path.
$path = ''; // '/uplods/'
$download_file = $path.$filename;
if(!empty($filename)){
// Check file is exists on given path.
if(file_exists($download_file))
{
header('Content-Disposition: attachment; filename=' . $filename);
readfile($download_file); exit;
} else
{
echo 'File does not exists on given path';
} }
?>

Department of Computer Science, Valluvar College of Science and Management - Karur 35


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 36


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 37


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Week 8 Laboratory: PHP Cookies


DATE:

What is a Cookie?
A cookie is a small text file that lets you store a small amount of data (nearly 4KB) on
the user's computer. They are typically used to keeping track of information such as username
that the site can retrieve to personalize the page when user visit the website next time.

Setting a Cookie in PHP


The setcookie() function is used to set a cookie in PHP. Make sure you call
the setcookie()function before any output generated by your script otherwise cookie will not
set. The basic syntax of this function can be given with:
setcookie(name, value, expire, path, domain, secure);
The parameters of the setcookie() function have the following meanings:

Parameter Description
Name The name of the cookie.
Value The value of the cookie. Do not store sensitive information since this value is
stored on the user's computer.
Expires The expiry date in UNIX timestamp format. After this time cookie will become
inaccessible. The default value is 0.
Path Specify the path on the server for which the cookie will be available. If set to /,
the cookie will be available within the entire domain.
Domain Specify the domain for which the cookie is available to e.g www.example.com.
Secure This field, if present, indicates that the cookie should be sent only if a secure
HTTPS connection exists.

Here's an example that uses setcookie() function to create a cookie


named username and assign the value value Raja to it. It also specify that the cookie will
expire after 30 days (30 days * 24 hours * 60 min * 60 sec).
Example1
<?php
// Setting a cookie
setcookie("username", "Raja", time()+30*24*60*60);
?>

Department of Computer Science, Valluvar College of Science and Management - Karur 38


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Accessing Cookies Values


The PHP $_COOKIE superglobal variable is used to retrieve a cookie value. It typically
an associative array that contains a list of all the cookies values sent by the browser in the
current request, keyed by cookie name. The individual cookie value can be accessed using
standard array notation, for example to display the username cookie set in the previous
example, you could use the following code.
Example 2
<?php
// Accessing an individual cookie value
echo $_COOKIE["username"];
?>

Example 3
<?php
// Verifying whether a cookie is set or not
if(isset($_COOKIE["username"])){
echo "Hi " . $_COOKIE["username"];
} else{
echo "Welcome Guest!";
}
?>

You can use the print_r() function like print_r($_COOKIE); to see the structure of
this $_COOKIE associative array, like you with other arrays.

Removing Cookies
You can delete a cookie by calling the same setcookie() function with the cookie name
and any value (such as an empty string) however this time you need the set the expiration date
in the past, as shown in the example below:
Example 4
<?php
// Deleting a cookie
setcookie("username", "", time()-3600);
?>

Sample Exercise: Work the Above Example 1,2,3,4

Department of Computer Science, Valluvar College of Science and Management - Karur 39


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Exercise
In our Lab Exercise 8 Program to store the current date and time in a cookie and
display the “Last Visited” date and time on the webpage.
Hint
Script for Cookie.php

<?php
//date_default_timezone_set('Asia/Calcutta'); - You can choose any timezone
//Calculate 60 days in the future
//seconds * minutes * hours * days + current time
$inTwoMonths = 60 * 60 * 24 * 60 + time();
setcookie('lastVisit', date("G:i - m/d/y"), $inTwoMonths);
if(isset($_COOKIE['lastVisit']))
{
$visit = $_COOKIE['lastVisit'];
echo "<b>Your last visit was - ". $visit."</b>";
}
else
echo "Welcome to Cookie Program";
?>

Screenshot

Department of Computer Science, Valluvar College of Science and Management - Karur 40


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 41


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 42


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Week 9 Laboratory: PHP Session


DATE:

What is a Session?
Although you can store data using cookies but it has some security issues. Since
cookies are stored on user's computer it is possible for an attacker to easily modify a
cookie content to insert potentially harmful data in your application that might break
your application.
Also every time the browser requests a URL to the server, all the cookie data for
a website is automatically sent to the server within the request. It means if you have
stored 5 cookies on user's system, each having 4KB in size, the browser needs to
upload 20KB of data each time the user views a page, which can affect your site's
performance.
You can solve both of these issues by using the PHP session. A PHP session
stores data on the server rather than user's computer. In a session based environment,
every user is identified through a unique number called session identifier or SID. This
unique session ID is used to link each user with their own information on the server like
emails, posts, etc.

Starting a PHP Session


Before you can store any information in session variables, you must first start up
the session. To begin a new session, simply call the PHP session_start() function. It
will create a new session and generate a unique session ID for the user.
The PHP code in the example below simply starts a new session.
Example 1
<?php
// Starting session
session_start();
?>

The session_start() function first checks to see if a session already exists by


looking for the presence of a session ID. If it finds one, i.e. if the session is already
started, it sets up the session variables and if doesn't, it starts a new session by
creating a new session ID.

Storing and Accessing Session Data


You can store all your session data as key-value pairs in
the $_SESSION[] superglobal array. The stored data can be accessed during lifetime of
a session. Consider the following script, which creates a new session and registers two
session variables.

Department of Computer Science, Valluvar College of Science and Management - Karur 43


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Example 2
<?php
// Starting session
session_start();
// Storing session data
$_SESSION["firstname"] = "John";
$_SESSION["lastname"] = "Peter";
?>

To access the session data we set on our previous example from any other page
on the same web domain — simply recreate the session by calling session_start() and
then pass the corresponding key to the $_SESSION associative array.
Example 3
<?php
// Starting session
session_start();
// Accessing session data
echo 'Hi, ' . $_SESSION["firstname"] . ' ' . $_SESSION["lastname"];
?>

The above PHP code produces the following output:


Hi, John Peter

Destroying a Session
If you want to remove certain session data, simply unset the corresponding key
of the $_SESSION associative array, as shown in the following example:
Example 4
<?php
// Starting session
session_start();
// Removing session data
if(isset($_SESSION["lastname"])){
unset($_SESSION["lastname"]);
}
?>

However, to destroy a session completely, simply call


the session_destroy() function. This function does not need any argument and a
single call destroys all the session data.

Department of Computer Science, Valluvar College of Science and Management - Karur 44


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Example 6
<?php
// Starting session
session_start();
// Destroying session
session_destroy();
?>

Every PHP session has a timeout value — a duration, measured in seconds


which determines how long a session should remain alive in the absence of any user
activity. You can adjust this timeout duration by changing the value
of session.gc_maxlifetime variable in the PHP configuration file (php.ini).

Sample Exercise: Work the Above Example 1, 2, 3, 4, 5, 6 and see the Output.
It will be helpful to learn how to work with session.

Exercise
In our Lab Exercise 9 Program to store the page views count in session, to increment
the count on each refresh and to show the count on webpage.
Hint
Script for Session.php

<?php
session_start();
if(isset($_SESSION['views']))
$_SESSION['views'] = $_SESSION['views']+1;
else
$_SESSION['views']=1;
echo"views = ".$_SESSION['views'];
?>

Screenshot

Department of Computer Science, Valluvar College of Science and Management - Karur 45


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 46


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 47


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Week 10 Laboratory: Image Processing in PHP


DATE:
Sample Exercise: Program to draw a circle; it will be useful to do our lab
exercise using image.

Exercise
In our Lab Exercise 9 Program to draw the Face like structure using image creation.
Hint
Script for image.php
<?php
header ("Content-type:image/png");
$c=imagecreate(500,500);
$bc=imagecolorallocate($c,200,100,100);
$fc=imagecolorallocate($c,225,225,150);
$lc=imagecolorallocate($c,20,20,20);
imagefilledellipse($c,250,250,400,400,$fc);
imagefilledellipse($c,150,150,50,50,$lc);
imagefilledellipse($c,350,150,50,50,$lc);
imageline($c,250,200,280,275,$lc);
imageline($c,250,275,280,275,$lc);
imagearc($c,250,300,250,150,0,180,$lc);
imagepng($c);
imagedestroy($c);
?>

Screenshot

Department of Computer Science, Valluvar College of Science and Management - Karur 48


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 49


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 50


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Week 11 Laboratory: Designing a Simple Calculator

DATE:

Sample Exercise: Work with below example to recall the Switch statement.
switch (date('l')) {
case "Monday":
echo "Monday to take New task";
break;
case "Tuesday":
echo "Tuesday to take task2";
break;
case "Wednesday":
echo "Wednesday to take task3";
break;
case "Thursday":
echo "Thursday Review this completed task";
break;
case "Friday":
echo "Friday present the task";
break;
case "Saturday":
echo "Saturday plan to go to the movie";
break;
case "Sunday":
echo "Rest on Sunday";
break;
default:
echo "unpredicted day";
break;
}

Extra credit
1. Design the application to choose the color using switch statement to solve on
post values from html.
Sample Screen for Calculator

Department of Computer Science, Valluvar College of Science and Management - Karur 51


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Exercise
In our Lab Exercise 11 Program to create a Simple Calculator.
Hint
In HTML
<select name="operator">
<option>None</option>
<option>Add</option>
<option>Subtract</option>
<option>Multiply</option>
<option>Divide</option>
<option>Square</option>
</select>
Script for Calculator.php
<?php
if (isset($_POST['submit'])) {
$result1 = $_POST['numb1'];
$result2 = $_POST['numb2'];
$operator = $_POST['operator'];
switch ($operator) {
case 'None':
echo "You need to select any operator";
break;
case 'Add':
echo "<br><b>".($result1 + $result2)."</b>";
break;
case 'Subtract':
echo "<br><b>".($result1 - $result2)."</b>";
break;
case 'Multiply':
echo "<br><b>".($result1 * $result2)."</b>";
break;
case 'Divide':
echo "<br><b>".($result1 / $result2)."</b>";
break;
case 'Square':
echo $result1*$result1."<br>" ;
echo $result2*$result2."<br>" ;
break;
}
}
?>

Department of Computer Science, Valluvar College of Science and Management - Karur 52


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 53


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 54


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Week 12 Laboratory: Working with Database

DATE:

What is MySQL?
MySQL is one of the most popular relational database systems being used
on the Web today. It is freely available and easy to install, however if you have installed
Wampserver it already there on your machine. MySQL database server offers several
advantages:
 MySQL is easy to use, yet extremely powerful, fast, secure, and scalable.
 MySQL runs on a wide range of operating systems, including UNIX or Linux,
Microsoft Windows, Apple Mac OS X, and others.
 MySQL supports standard SQL (Structured Query Language).
 MySQL is ideal database solution for both small and large applications.
 MySQL is developed, and distributed by Oracle Corporation.
 MySQL includes data security layers that protect sensitive data from intruders.

MySQL database stores data into tables like other relational database. A table is
a collection of related data, and it is divided into rows and columns.
Connecting PHP with MySQL Server
In order to store or access the data inside a MySQL database, you first need to
connect to the MySQL database server. PHP offers two different ways to connect to
MySQL server: MySQLi (Improved MySQL) and PDO (PHP Data Objects)
extensions.
While the PDO extension is more portable and supports more than twelve
different databases, MySQLi extension as the name suggests supports MySQL
database only. MySQLi extension however provides an easier way to connect to, and
execute queries on, a MySQL database server. Both PDO and MySQLi offer an
object-oriented API, but MySQLi also offers a procedural API which is relatively
easy for beginners to understand.

Connecting to MySQL Database Server


In PHP you can easily do this using the mysqli_connect() function. All
communication between PHP and the MySQL database server takes place through this
connection. Here're the basic syntaxes for connecting to MySQL using MySQLi and PDO
extensions:

Syntax: MySQLi, Procedural way


$link = mysqli_connect("hostname", "username", "password", "database");

Department of Computer Science, Valluvar College of Science and Management - Karur 55


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Syntax: MySQLi, Object Oriented way


$mysqli = new mysqli("hostname", "username", "password", "database");

Syntax: PHP Data Objects (PDO) way


$pdo = new PDO("mysql:host=hostname;dbname=database", "username", "password");

The hostname parameter in the above syntax specify the host name (e.g. localhost),or
IP address of the MySQL server, whereas the username and password parameters
specifies the credentials to access MySQL server, and the database parameter, if
provided will specify the default MySQL database to be used when performing queries.
Example for Connecting Database

Procedural
<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "root", "");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Print host information
echo "Connect Successfully. Host info: " . mysqli_get_host_info($link);
?>
Object Oriented
<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$mysqli = new mysqli("localhost", "root", "", "demo");
// Check connection
if($mysqli === false){
die("ERROR: Could not connect. " . $mysqli->connect_error);
}
// Print host information
echo "Connect Successfully. Host info: " . $mysqli->host_info;
?>
PDO
<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
try{
$pdo = new PDO("mysql:host=localhost", "root", "");
// Set the PDO error mode to exception
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Print host information
echo "Connect Successfully. Host info: " .
$pdo->getAttribute(constant("PDO::ATTR_CONNECTION_STATUS"));
} catch(PDOException $e){
die("ERROR: Could not connect. " . $e->getMessage());
} ?>

Department of Computer Science, Valluvar College of Science and Management - Karur 56


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Sample Exercise: Work with below examples to know how to create a


database, table and inserting values to database using procedural type.

Creating a Database
<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "root", "");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Attempt create database query execution
$sql = "CREATE DATABASE demo";
if(mysqli_query($link, $sql)){
echo "Database created successfully";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>
Creating a Table
<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "root", "", "demo");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Attempt create table query execution
$sql = "CREATE TABLE persons(
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
first_name VARCHAR(30) NOT NULL,
last_name VARCHAR(30) NOT NULL,
email VARCHAR(70) NOT NULL UNIQUE
)";
if(mysqli_query($link, $sql)){
echo "Table created successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>
Inserting Values in a Table
<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "root", "", "demo");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Attempt insert query execution
$sql = "INSERT INTO persons (first_name, last_name, email) VALUES ('Peter', 'Parker',
'peterparker@mail.com')";

Department of Computer Science, Valluvar College of Science and Management - Karur 57


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

if(mysqli_query($link, $sql)){
echo "Records inserted successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>
Inserting Multiple Values in a Table
<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "root", "", "demo");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Attempt insert query execution
$sql = "INSERT INTO persons (first_name, last_name, email) VALUES
('John', 'Rambo', 'johnrambo@mail.com'),
('Clark', 'Kent', 'clarkkent@mail.com'),
('John', 'Carter', 'johncarter@mail.com'),
('Harry', 'Potter', 'harrypotter@mail.com')";
if(mysqli_query($link, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>

Sample Exercise: Work with below example, Login screen Validation.

Design

Department of Computer Science, Valluvar College of Science and Management - Karur 58


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Steps to Follow
 Go to Browser and type http://localhost/phpmyadmin
 Choose Database and create new database as login
 Create table name as users to follow query as

CREATE TABLE IF NOT EXISTS `users` ( `userId` int(8) NOT NULL


AUTO_INCREMENT, `userName` varchar(55) NOT NULL, `password` varchar(55) NOT
NULL, `displayName` varchar(55) NOT NULL, PRIMARY KEY (`userId`) )

 Insert in the user table as one example as

INSERT INTO `users` (`userId`, `userName`, `password`, `displayName`)


VALUES (1, 'admin', 'admin123', 'Admin')

Code
<?php
$message="";
if(count($_POST)>0) {
$conn = mysqli_connect("localhost","root","","login");
$result = mysqli_query($conn,"SELECT * FROM users WHERE userName='" . $_POST["userName"] .
"' and password = '". $_POST["password"]."'");
$count = mysqli_num_rows($result);
if($count==0) {
$message = "Invalid Username or Password!";
} else {
$message = "You are successfully authenticated!";
}
}
?>
<html>
<head>
<title>User Login</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<form name="frmUser" method="post" action="">
<div class="message"><?php if($message!="") { echo $message; } ?></div>
<table border="0" cellpadding="10" cellspacing="1" width="500"
align="center" class="tblLogin">
<tr class="tableheader">
<td align="center" colspan="2">Enter Login Details</td>
</tr>
<tr class="tablerow">
<td>
<input type="text" name="userName" placeholder="User Name"
class="login-input"></td>
</tr>
<tr class="tablerow">
<td>
<input type="password" name="password" placeholder="Password"
class="login-input"></td>
</tr>
<tr class="tableheader">
<td align="center" colspan="2"><input type="submit" name="submit"
value="Submit" class="btnSubmit"></td>
</tr> </table> </form> </body></html>

Department of Computer Science, Valluvar College of Science and Management - Karur 59


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Extra Credit
1. Do validation for the above Login page like required field validation, the
password field should accept the combination of alphanumeric and special
characters.

Exercise
In our Lab Exercise 12 Program to design authentication webpage in php with MySQL
to check username and password.
Rules
 Use Session to implement login and logout.
 It will have Signup for new user for registration.
 Doesn’t show password in the table, to do this learn hash concept.
Design Model for Signup and Login Page

Signup/Register

Login

Hint
CREATE TABLE users ( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, username VARCHAR(50)
NOT NULL UNIQUE, password VARCHAR(255) NOT NULL, created_at DATETIME DEFAULT
CURRENT_TIMESTAMP );

Department of Computer Science, Valluvar College of Science and Management - Karur 60


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 61


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 62


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 63


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 64


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 65


16SCCCA6P/16SCCCS6P PROGRAMMING IN PHP LABORATORY

Department of Computer Science, Valluvar College of Science and Management - Karur 66

You might also like