Practical Assignment -1 Creating and Drawing Images
$im = ImageCreate(200,200);
$white = ImageColorAllocate($im,0xFF,0xFF,0xFF);
$black = ImageColorAllocate($im,0x00,0x00,0x00);
ImageFilledRectangle($im,50,50,150,150,$black);
header('Content-Type: image/png');
ImagePNG($im);
?>
Practical Assignment -2 Images with Text
<?php
$im = ImageCreate(200,200);
$white = ImageColorAllocate($im,0xFF,0xFF,0xFF);
$black = ImageColorAllocate($im,0x00,0x00,0x00);
ImageFilledRectangle($im,50,50,150,150,$black);
ImageString($im,5,50,160,"A black box",$black);
Header('Content-Type: image/png');
ImagePNG($im);
?>
Practical Assignment -3
Resizing with ImageCopyResampled( )
<?php
$src=imagecreatefromjpeg('download.jpg');
$width=ImageSx($src);
$height=ImageSy($src);
$x=$width/2;
$y=$height/2;
$dst=ImageCreateTrueColor($x,$y);
ImageCopyResampled($dst,$src,0,0,0,0,$x,$y,$width,$height);
header('Content-Type: image/png');
ImagePNG($dst);
?>
Practical Assignment -4
Checking for image format support
<?php
$im = ImageCreate(200,200);
$white = ImageColorAllocate($im,0xFF,0xFF,0xFF);
$black = ImageColorAllocate($im,0x00,0x00,0x00);
ImageFilledRectangle($im,50,50,150,150,$black);
if (ImageTypes( ) & IMG_PNG) {
header("Content-Type: image/png");
ImagePNG($im);
} elseif (ImageTypes( ) & IMG_JPG) {
header("Content-Type: image/jpeg");
ImageJPEG($im);
} elseif (ImageTypes( ) & IMG_GIF) {
header("Content-Type: image/gif");
ImageGIF($im);
}
?>
Practical Assignment -5
Write a PHP Script to read ‘book.xml’ file and print specific content of a file using DOMDocument parser. ‘book.xml’ file should contain following information with at least 5 records with values.
BookInfo : book_no, book_Name, author_name, Price, Year.
BookInfo : book_no, book_Name, author_name, Price, Year.
book.xml:
<?xml version='1.0' encoding ='UTF-8' ?>
<?xml-stylesheet type="text/css"?>
<bookstore>
<books category="technical">
<book_no>1</book_no>
<book_name>Mrutunjay</book_name>
<author_name>shivaji sawant</author_name>
<price>500</price>
<year>1990</year>
</books>
<books category="Cooking">
<book_no>2</book_no>
<book_name>ccc</book_name>
<author_name>aaa</author_name>
<price>200</price>
<year>1950</year>
</books>
<books category="YOGA">
<book_no>3</book_no>
<book_name>ddd</book_name>
<author_name>zzz</author_name>
<price>150</price>
<year>2016</year>
</books>
<books category="technical">
<book_no>1</book_no>
<book_name>def</book_name>
<author_name>xxx</author_name>
<price>100</price>
<year>1990</year>
</books>
<books category="technical">
<book_no>1</book_no>
<book_name>def</book_name>
<author_name>xxx</author_name>
<price>100</price>
<year>1990</year>
</books>
</bookstore>
book.php :
<?php
$doc=new DOMDocument();
$doc->load("book.xml");
$name=$doc->getElementsByTagName("book_name");
$year=$doc->getElementsByTagName("year");
echo "Books Names";
foreach($name as $val)
{
echo "<br>".$val->textContent;
}
echo "<br><br> Year";
foreach($year as $value)
{
echo "<br>".$value->textContent;
}
Practical Assignment -6
Write a PHP script to check how many times the web page access.[ Use cookies]<?php
if(isset($_COOKIE['cnt']))
{
$x=$_COOKIE['cnt'];
$x=$x+1;
setcookie('cnt',$x);
}
else
{
setcookie('cnt',2);
echo "you accessed this page 1st time";
}
echo "you accessed this page $x times";
?>
Practical Assignment -7
Write a PHP script to keep track of number of times the web page has been access. [Use Session]<html>
<head>
<title> Number of times the web page has been viited.</title>
</head>
<body>
<?php
session_start();
if(isset($_SESSION['count']))
$_SESSION['count']=$_SESSION['count']+1;
else
$_SESSION['count']=1;
echo "<h3>This page is accessed</h3>".$_SESSION['count'];
?>
Practical Assignment -8
Write a script to create XML file as ‘Employee.xml’. The element of this xml file are as follows:
<Empdetails>
<Employee EMPno= Empname=>
<Salary>--------</Salary>
<Designation>-------</Designation>
</Employee>
</Empdetails>
<Empdetails>
<Employee EMPno= Empname=>
<Salary>--------</Salary>
<Designation>-------</Designation>
</Employee>
</Empdetails>
XML file : employee.xml
<?xml version="1.0" encoding="UTF-8"?>
<Empdetails>
<Emp Empno="1" Empname="Mansi">
<Sal>15000</Sal>
<Desg>Developer</Desg>
</Emp>
<Emp Empno="2" Empname="Gautam">
<Sal>35000</Sal>
<Desg>HR</Desg>
</Emp>
<Emp Empno="3" Empname="Jack">
<Sal>25000</Sal>
<Desg>Tester</Desg>
</Emp>
</Empdetails>
PHP file :
<?php
$xml=simplexml_load_file("employee.xml") or die("error:cannot create object");
echo "<table border=1 align=center>";
echo "<tr><td>Employee no</td><td>Employee Name</td><td>Employee Salary</td> <td>Employee Employee Designation</td></tr>";
foreach($xml->children() as $emp)
{
$arr = $emp->attributes();
echo "<tr><td>".$arr["Empno"]."</td>";
echo "<td>".$arr["Empname"]."</td>";
echo "<td>".$emp->Sal."</td>";
echo "<td>".$emp->Desg."</td></tr>";
}
echo "<table>";
?>
<?xml version="1.0" encoding="UTF-8"?>
<Empdetails>
<Emp Empno="1" Empname="Mansi">
<Sal>15000</Sal>
<Desg>Developer</Desg>
</Emp>
<Emp Empno="2" Empname="Gautam">
<Sal>35000</Sal>
<Desg>HR</Desg>
</Emp>
<Emp Empno="3" Empname="Jack">
<Sal>25000</Sal>
<Desg>Tester</Desg>
</Emp>
</Empdetails>
PHP file :
<?php
$xml=simplexml_load_file("employee.xml") or die("error:cannot create object");
echo "<table border=1 align=center>";
echo "<tr><td>Employee no</td><td>Employee Name</td><td>Employee Salary</td> <td>Employee Employee Designation</td></tr>";
foreach($xml->children() as $emp)
{
$arr = $emp->attributes();
echo "<tr><td>".$arr["Empno"]."</td>";
echo "<td>".$arr["Empname"]."</td>";
echo "<td>".$emp->Sal."</td>";
echo "<td>".$emp->Desg."</td></tr>";
}
echo "<table>";
?>
Practical Assignment -9
Write a php script to create database connection.
<?php
$servername = "localhost";
$username = "root";
$password = "";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
Practical Assignment -10
Write a php script to create employee table with attribute (eno,ename,mobile_no,email)
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mahesh";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// sql to create table
$sql = "create table employee (eno INT(6) primary key,
ename varchar(20),mobileno int(10),email varchar(50))";
if (mysqli_query($conn, $sql)) {
echo "Table employee created successfully";
} else {
echo "Error creating table: " . mysqli_error($conn);
}
mysqli_close($conn);
?>
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mahesh";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// sql to create table
$sql = "create table employee (eno INT(6) primary key,
ename varchar(20),mobileno int(10),email varchar(50))";
if (mysqli_query($conn, $sql)) {
echo "Table employee created successfully";
} else {
echo "Error creating table: " . mysqli_error($conn);
}
mysqli_close($conn);
?>
Practical Assignment -11
write php script to insert record in employee table : employee((eno,ename,mobile_no,email)
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mahesh";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "insert into employee values(11, 'ramesh',9730477888,'john@example.com')";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>