Slip 20 - C) 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 settings on next web page and actual implementation (with new settings) on third web page.

Solution:

1.html-

<html>
<body>
<form action="2.php" method="get">
<center>
<b>Select font style :</b><input type=text name=s1>
<b>Enter font size : </b><input type=text name=s>
<b>Enter font color :</b><input type=text name=c>
<b>Enter background color :</b><input type=text name=b>
<input type=submit value="Next">
</center>
</form>
</body>
</html>

2.php-

<?php
echo "style is ".$_GET['s1']."
color is ".$_GET['c']."
Background color is ".$_GET['b']."
size is ".$_GET['s'];
setcookie("set1",$_GET['s1'],time()+3600);
setcookie("set2",$_GET['c'],time()+3600);
setcookie("set3",$_GET['b'],time()+3600);
setcookie("set4",$_GET['s'],time()+3600);
?>
<a href="3.php">Show</a>

3.php-

<?php
$style=$_COOKIE['set1'];
$color=$_COOKIE['set2'];
$size=$_COOKIE['set4'];
$b_color=$_COOKIE['set3'];
$msg="Genus iT Solution";
echo "<body bgcolor=$b_color>";
echo "<font color=$color size=$size face=$style>$msg";
echo "</font></body>";
?>

Post a Comment

0 Comments