PHP Web Tec Programs

 1.      Write a PHP script to keep track of number of times the web page has been accessed (Use Session Tracking).


Q1web_access.php

<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'];

?>

</body>

</html>


This page is accessed

1
...................

117



1.      2 .Write a PHP script to change the preferences of your web page like font style, font size, font color, background color using cookie. Display selected setting on next web page and actual implementation (with new settings) on third page (Use Cookies).


Q2webpage_font.html


<html>

  <body>

   <form action="Q2webpage_font.php" method="get">

    <center>

<b>Select font style :</b>

     <input type="text" name="fstyle"> <br>

<b>Enter font size : </b>

     <input type="text" name="fsize"><br>

<b>Enter font color : </b>

     <input type="text" name="fcolor"><br>

<b>Enter background color :</b>

     <input type="text" name="fbgcolor"><br>

<input type=submit value="Next">

</center>

</form>

  </body>

</html>



Q2webpage_font.php



<?php

echo "style is ".$_GET['fstyle']."<br>size is ".$_GET['fsize']."<br>color is ".$_GET['fcolor']."<br>Background color is ".$_GET['fbgcolor'];

setcookie("set1",$_GET['fstyle'],time()+3600);

setcookie("set2",$_GET['fsize'],time()+3600);

setcookie("set3",$_GET['fcolor'],time()+3600);

setcookie("set4",$_GET['fbgcolor'],time()+3600);

?>


<html>

 <body>

     <form action="Q2font_display.php">

       <input type=submit value=OK>

     </form>

  </body>

</html>



Q2font_display.php



<?php

$style = $_COOKIE['set1'];

$size = $_COOKIE['set2'];

$color = $_COOKIE['set3'];

$b_color = $_COOKIE['set4'];


$msg = "I'm the top of the world...";

echo "<body bgcolor=$b_color>";

echo "<font color=$color size=$size>$msg ";

echo "</font></body>";

?>

 

I'm the top of the world...




2.     3. Wite a PHP script to accept username and password. If in the first three chances, username and password entered is correct then display second form with “Welcome message” otherwise display error message. [Use Session]

 


Q3user_chance.html

  

  <html>

  <body>

   <form action="Q3user_chance.php" method="POST">

    <center>

<b>Enter the username:</b>

     <input type="text" name="username"> <br>

<b>Enter font Password : </b>

     <input type="text" name="password"><br>

<input type=submit value="Next">

</center>

</form>

  </body>

</html>




Q3user_chance.php


<?php

 

 setCookie("setname",$_POST['username'],time()+60*60*1);

 setCookie("setpass",$_POST['password'],time()+60*60*1);

 

 ?>

 

 <html>

  <body>

   <form action ="Q3chk_pass.php">

    <input type = "submit" name ="submit">

   </form>

  </body>

 </html>




Q3chk_pass.php


        <?php

        $usr = "swapnil";

        $psw = "nil";

        

$name = $_COOKIE['setname'];

        $pass = $_COOKIE['setpass'];

session_start();

// $_SESSION['count2']=0;

if($_SESSION['count2']<3)

{

if (($name == "swapnil" && $pass == "nil")) 

{

echo "WELCOME SIR/MAM Ur LOGIN SUCCESSFULLY DONE...";

}

else {

$_SESSION['count2'] = $_SESSION['count2']+1;

echo "incorrect login try again...<BR> U have ".(3 - $_SESSION['count2']). " chances" ;

}

}

else {

echo "More than 3 chances not allow for incorrect login!!!";

        }

?>




Enter the username: 
Enter font Password : 


WELCOME SIR/MAM Ur LOGIN SUCCESSFULLY DONE...


Enter the username: 
Enter font Password : 

incorrect login try again...
U have 2 chances


incorrect login try again...
U have 1 chances


incorrect login try again...
U have 0 chances

More than 3 chances not allow for incorrect login!!!




3.      4. Write a PHP script to accept Employee details (Eno, Ename, Address) on first page. On second page accept earning (Basic, DA, HRA). On third page print Employee information (Eno, Ename, Address, Basic, DA, HRA, Total) [ Use Session]

 


Q4E_detail.html


<html>

<body>

<form action="Q4E_detail.php" method="get">

<center>  <h2>Enter Enployee Details :</h2>  <br>


<table>

<tr>  <td><b>Emp no :</b></td>            <td><input type=text name=eno></td>        </tr>

<tr>  <td><b> Name :</b></td>             <td><input type=text name=ename></td>        </tr>

<tr>  <td><b>Address :</b></td>                      <td><input type=text name=eaddress></td>        </tr>

</table>

<br>  <input type=submit value=Show name=submit>

</center>

</form>

</body>

</html>



Q4E_detail.php



<?php

session_start();

$eno = $_GET['eno'];

$ename = $_GET['ename'];

$eadd = $_GET['eaddress'];


$_SESSION['eno'] = $eno;

$_SESSION['ename'] = $ename;

$_SESSION['eadd'] = $eadd;

?>


<html>

<body>


<form action="Q4E_earn.php" method="post">

<center>

<h2>Enter Earnings of Employee:</h2>


<table>

<tr><td>Basic : </td><td><input type="text" name="ebasic"></td><tr>

<tr><td>DA : </td><td><input type="text" name="eda"></td></tr>

<tr><td>HRA : </td><td><input type="text" name="ehra"></td></tr>

<tr><td></td><td><input type="submit" value=Next></td></tr>

</table>

</center>

</form>

</body>

</html>



Q4E_earn.php



<?php

session_start();


$basic = $_POST['ebasic'];

$da = $_POST['eda'];

$hra= $_POST['ehra'];


$total = $basic+$da+$hra;


echo "<h3>Employee Details</h3> ";

echo "Name : ".$_SESSION['eno']."<br>";

echo "Address : ".$_SESSION['ename']."<br>";

echo "Class : ".$_SESSION['eadd']."<br><br>";


echo "basic : ".$basic."<br>";

echo "DA : ".$da."<br>";

echo "HRA : ".$hra."<br>";



echo "<h2>Total Of Earnings Is : ".$total."</h2>";

?>



Enter Enployee Details :


Emp no :
Name :
Address :



Enter Earnings of Employee:

Basic :
DA :
HRA :


Employee Details

Name : 32
Address : swapnil
Class : wasunde

basic : 100
DA : 300
HRA : 500

Total Of Earnings Is : 900





4.     5.Create XML file named “Item.xml”with item-name, item-rate, item quantity Store the details of 5 Items of different Types


<?xml version = "1.0" encoding ="UTF-8"?>


 <Item_Detail>

    <item>

    <item_name> Redmi note 8 pro </item_name>

<item_rate> 15000 </item_rate>

<item_quantity> 2 </item_quantity>

    </item>

 

    <item>

    <item_name> Samsung </item_name>

<item_rate> 30000 </item_rate>

<item_quantity> 5 </item_quantity>

    </item>

<item>

    <item_name> Oppo </item_name>

<item_rate> 45000 </item_rate>

<item_quantity> 3 </item_quantity>

    </item>

<item>

    <item_name> Apple </item_name>

<item_rate> 100000 </item_rate>

<item_quantity> 1 </item_quantity>

    </item>

<item>

    <item_name> Iphone </item_name>

<item_rate>500000 </item_rate>

<item_quantity> 1 </item_quantity>

    </item>

 </Item_Detail>





6.      Write PHP script to read “book.xml” file into simpleXML object. Display attributes and elements .

( simple_xml_load_file() function )


Q6book.xml


<?xml version = "1.0" encoding ="UTF-8"?>


 <Book_Detail>

    <book>

    <book_name> wings of fire </book_name>

<book_rate> 5000 </book_rate>

<book_quantity> 2 </book_quantity>

    </book>

 

    <book>

    <book_name> Miracal morning </book_name>

<book_rate> 500 </book_rate>

<book_quantity> 10 </book_quantity>

    </book>

<book>

    <book_name> 101 habits </book_name>

<book_rate> 1000 </book_rate>

<book_quantity> 4 </book_quantity>

    </book>

 </Book_Detail>

 


Q6book.php


<?php

 $doc = new DOMDocument();

  $doc->load("Q6book.xml");

  

  $name = $doc->getElementsByTagName("book_name");

  

  echo "Names of the Books are:<BR>";

  foreach($name as $value)

   {

     echo "$value->textContent<BR>";

   }

 

?>


Names of the Books are:
wings of fire
Miracal morning
101 habits




6.      7 Write a PHP script to read “Movie.xml” file and print all MovieTitle and ActorName of file using DOMDocument Parser. “Movie.xml” file should contain following information with at least 5 records with values. MovieInfoMovieNo, MovieTitle, ActorName ,ReleaseYear


 Q7movie.xml


<?xml version="1.0" encoding="UTF-8"?>

<Movie>

    <MovieInfo>

        <MovieNo>1</MovieNo>

        <MovieTitle>Shawshank Redemption</MovieTitle>

        <ActorName>Mann </ActorName>

        <ReleaseYear>1998</ReleaseYear>

    </MovieInfo>

    <MovieInfo>

        <MovieNo>2</MovieNo>

        <MovieTitle>Welcome</MovieTitle>

        <ActorName>Akshay </ActorName>

        <ReleaseYear>2010</ReleaseYear>

    </MovieInfo>

    <MovieInfo>

        <MovieNo>3</MovieNo>

        <MovieTitle>The perfect girl</MovieTitle>

        <ActorName>sam</ActorName>

        <ReleaseYear>2019</ReleaseYear>

    </MovieInfo>

    <MovieInfo>

        <MovieNo>4</MovieNo>

        <MovieTitle>Harry potter</MovieTitle>

        <ActorName>Harry</ActorName>

        <ReleaseYear>1999</ReleaseYear>

    </MovieInfo>

    <MovieInfo>

        <MovieNo>5</MovieNo>

        <MovieTitle>London has fallen</MovieTitle>

        <ActorName>gerard buttler</ActorName>

        <ReleaseYear>2013</ReleaseYear>

    </MovieInfo>

</Movie>




 Q7movie.php


<?php

    $xmldata = simplexml_load_file("Q7movie.xml") or die("Failed to load");

    foreach($xmldata->children() as $mov){

        echo $mov->MovieNo . ", ";

        echo $mov->MovieTitle . ", ";

        echo $mov->ActorName . ", ";

        echo $mov->ReleaseYear . "<br>";

    }

?>



1, Shawshank Redemption, Mann , 1998
2, Welcome, Akshay , 2010
3, The perfect girl, sam, 2019
4, Harry potter, Harry, 1999
5, London has fallen, gerard buttler, 2013



7.      8. Create a student.xml file containing at least 5 student information

 

<?xml version="1.0" encoding="UTF-8"?>

<Student_Detail>

    <Student>

        <studentno>1</studentno>

        <studentname>Swapnil </studentname>

        <studentcity>patas </studentcity>

        <studentphno>9356111111</studentphno>

    </Student>

<Student>

        <studentno>2</studentno>

        <studentname> Omu</studentname>

        <studentcity>Baramati </studentcity>

        <studentphno>914599999</studentphno>

    </Student>

<Student>

        <studentno>3</studentno>

        <studentname> Sam</studentname>

        <studentcity> Daund </studentcity>

        <studentphno>923847933</studentphno>

    </Student>

<Student>

        <studentno>4</studentno>

        <studentcity>Avi </studentcity>

        <studentphno>1993843388</studentphno>

    </Student>

<Student>

        <studentno>5</studentno>

        <studentname> Anu</studentname>

        <studentcity>supe </studentcity>

        <studentphno>2934848484</studentphno>

    </Student>

</Student_Detail>



 

8.      9.  Write a PHP script to create student.xml file which contains student roll no, name, address, college and course. Print students detail of specific course in tabular format after accepting course as input.


           Q9student.xml

 

<?xml version="1.0" encoding="UTF-8"?>

<Student_Detail>

    <Student>

        <studentrnno>1</studentrnno>

        <studentname>Swapnil </studentname>

        <studentAddress>patas </studentAddress>

        <studentCollege>Vidya Pratishthan</studentCollege>

<studentCource> Core Java </studentCource>

    </Student>

<Student>

        <studentrnno>2</studentrnno>

        <studentname>Omu </studentname>

        <studentAddress>patas </studentAddress>

        <studentCollege>Vidya Pratishthan</studentCollege>

<studentCource> Python </studentCource>

    </Student>

<Student>

        <studentrnno>3</studentrnno>

        <studentname>Avi </studentname>

        <studentAddress>Baramati </studentAddress>

        <studentCollege>Vidya Pratishthan</studentCollege>

<studentCource> Php wala </studentCource>

    </Student>

</Student_Detail>



Q9stud_cource.php



<?php 


$doc = new DOMDocument();


 $doc->load("Q9student.xml");

 $cname = $doc->getElementsByTagName("studentCource");

 

 echo "Cource name of students:<BR>";

 

 foreach($cname as $value)

 {

  echo "<BR> $value->textContent";


  }

  

  ?>







Cource name of students:

Core Java
Python
Php wala





   10.   Write a script to create “cricket.xml” file with multiple elements as shown below:

 

<CricketTeam>

<Team country=”Australia”>

<player>____</player>

<runs>______</runs>

<wicket>____</wicket>

</Team>

</CricketTeam>

 

Write a script to add multiple elements in “cricket.xml” file of category, country=”India”.


Q10cricket.xml


<?xml version = "1.0" encoding ="UTF-8" ?>



<CricketTeam>


<Team country="India">


<player>Dhoni</player>


<runs>10000</runs>


<wicket>50</wicket>


</Team>

<Team country="Austrelia">


<player>maxwell</player>


<runs>5000</runs>


<wicket>80</wicket>


</Team>

<Team country="Pakistan">


<player>wasim</player>


<runs>500</runs>


<wicket>100</wicket>


</Team>

</CricketTeam>


 


Q10cricket.php


<?php


$xml = simplexml_load_file("Q10cricket.xml") or die("Failed to load");

    $xmlstring = $xml->asXML();

    echo $xmlstring;


?>


Dhoni 10000 50 maxwell 5000 80 wasim 500 100




 11. Write a PHP script for the following: Design a form to accept a number from the user. Perform the operations and show the results.

1)      Fibonacci Series.

2)      To find sum of the digits of that number.

 

(Use the concept of self-processing page.)

  

<html>


<body bgcolor = "navyblue">


<form action = "<?php echo $_SERVER['PHP_SELF'] ?>" method = "POST">


 Enter the first number:

  <input type = "text" name = "n1" id = "n1"> <BR>

 

  <input type = "submit" value = "submit">

  

  </form>

  

  

  <?php

   $num = $_POST['n1'];

  

 if ($_SERVER["REQUEST_METHOD"] == "POST") 

 {

    if(isFibonacci($num))                    //0, 1, 1, 2, 3, 5, 8, 13, 21

        echo "$num is a Fibonacci Number \n";

    else

        echo "$num is a not Fibonacci Number \n" ;

 }

 


function isPerfectSquare($x)

{

$s = (int)(sqrt($x));

return ($s * $s == $x);

}



function isFibonacci($n)

{

// n is Fibonacci if one of

// 5*n*n + 4 or 5*n*n - 4 or

// both is a perfect square

return isPerfectSquare(5 * $n * $n + 4) ||

isPerfectSquare(5 * $n * $n - 4);

}

     $temp = $num;

$sum=0;

  while($temp!=0)

    {

        $sum += $temp % 10;

        $temp = $temp / 10;

    }

    echo "<BR>sum of digits of ".$num." is :".$sum;

  ?>

  </body>

 </html>



Enter the first number: 

21 is a Fibonacci Number
sum of digits of 21 is :3





12. Create a XML file which gives details of books available in “Bookstore” from following categories.

1)      Yoga

2)      Story

3)      Technical

and elements in each category are in the following format

<Book>

<Book_Title> --------------</Book_Title>

<Book_Author> ---------------</Book_Author>

<Book_Price> --------------</Book_Price>

</Book>

Save the file as “Bookcategory.xml”



Q12book.php


<?xml version="1.0" encoding="utf-8"?>


<Book_Detail>

<Technical>

<BOOK>

<Book_Title>TechBook </Book_Title>

<Book_Author> Sam </Book_Author>

<Book_Price>  1000 </Book_Price>

</BOOK>

</Technical>

<Cooking>

<BOOK>

<Book_Title>CookBook </Book_Title>

<Book_Author>Nil </Book_Author>

<Book_Price>  500 </Book_Price>

</BOOK>

</Cooking>

<Yoga>

<BOOK>

<Book_Title>YogaBook </Book_Title>

<Book_Author>Avi </Book_Author>

<Book_Price>  3000 </Book_Price>

</BOOK>

</Yoga>

</Book_Detail>




Q12book.php


<?php

$xml=simplexml_load_file("Q12book.xml") or die("cannnot load");

$xmlstring=$xml->asXML();

echo $xmlstring;

?>


TechBook Sam 1000 CookBook Nil 500 YogaBook Avi 3000








 

Comments

Popular posts from this blog

Practical slips programs : Machine Learning

Full Stack Developement Practical Slips Programs

Android App Developement Practicals Programs