Vous êtes sur la page 1sur 34

Name of the Program1: ex1.html <html> <head> <title>Structures and Functions first page</title> </head> <body> <form action="php1.

php" method="post"> X value: <input type="text" name="x" size="3"><br> N value: <input type="text" name="n" size="3"><br> <input type="radio" name="choice" value="add" checked="checked"> Addition table<br> <input type="radio" name="choice" value="mul"> Multiplication table<br> <input type="radio" name="choice" value="div"> Division table <br> <input type="radio" name="choice" value="sub"> Subtraction table<br> <input type="submit" value="submit" /> </form> </body> </html> Name of the Program1: php1.php <?php $x=$_POST['x']; $n=$_POST['n']; $in=$_POST['choice']; if($in=="add") add( $x, $n ); elseif($in=="mul") mul( $x, $n ); elseif($in=="div") div( $x, $n ); elseif($in=="sub") sub( $x, $n );

function add( $x, $n ) { echo "Addition Table <br>"; for ($i = 1; $i <= $n; $i++) { echo "$i + $x = ".($i + $x)."<br>"; } } function mul( $x, $n ) { echo "Multiplication Table <br>"; $i = 1; while ($i <= $n) { echo $i." * ".$x." = ".($i * $x)."<br>"; $i++; } } function div( $x, $n ) { echo "Division Table <br>"; $i=1; do { echo "$i / $x = ".($i / $x)."<br>"; $i++; }while($i<=$n); } function sub( $x, $n ) {

echo "Subtraction Table <br>"; for ($i = 1; $i <= $n; $i++) { echo "$i - $x = ".($i - $x)."<br>"; } } ?>

Output for ex1.html:

Output for php1.php

Name of the Program2: ex2.html <html> <head> <title>Login</title> </head> <body> <form method="POST" action="php3_page3.php"> <pre> <center><h1>Login Form</h1> User Name Pass Word <input type="text" name="uname"> <input type="password" name="pwd">

<a href="php2_page2.php?uname=User1&pwd=****"> Click here if want skip Login</a> <input type="Submit" name="s1"> <input type="reset" name="s2"> </form> </body> </html> Name of the Program2: php2_page2.php <html> <body> <pre> <b>PAGE 2#</b> <h1>Welcome to Php </h1> <h3>This Page print the user name and password from the previous page</h3> <h4>Using Query String method...........</h4> </pre> <?php echo "<font color=red>User Name =".$_GET['uname']."<br>"; echo "Password(hidden)=".$_GET['pwd'];

?> </body> </html> Name of the Program2: php2_page3.php <html> <body> <pre> <b>PAGE 3#</b> <h1>Welcome to Php </h1> <h3>This Page print the user name and password from the previous page</h3> <h4>Using POST method...........</h4> </pre> <?php echo "<font color=red>User Name=".$_POST['uname']."<br>"; $strlenth=strlen($_POST['pwd']); echo "Password(hidden)="; for($i=0;$i<$strlenth;$i++) echo "*"; echo "<br>"; ?> </body> </html>

Output for ex2.html:

php2_page2.php

Output for ex2.html:

Output for php2_page3.php

Name Of the Program3:ex3.html <html> <head> <center><h2>Resume Preparation</h2></center> </head> <body> <form method="post" action="php3.php"> <pre> First Name Last Name Address Email ID Mobile Date Of Birth <input type="text" name="fname"> <input type="text" name="lname"> <textarea name="address"></textarea> <input type="text" name="email"> <input type="text" name="mobile"> <input type="text" name="dob">

Father's Name <input type="text" name="faname"> Marital Status <input type="text" name="mstatus"> Educational Qualification <table> <tr> <th>Degree</th><th>Institution</th><th>Year Of Pass</th><th>Marks(%)</th> </tr> <tr> <td><input name="degree" size=8></td> <td><input name="inst" size=8></td> <td><input name="yop" size=8></td> <td><input name="marks" size=8></td> </tr> </table> <input type="submit" name="s1" value="Submit"> <input type="reset" name="r1">

</form> </body> </html> Name Of Program3:php3.php <html> <body> <form method="post" action="labex3.html"> <?php $fname=$_POST['fname']; $fullname=$_POST['fname']." ".$_POST['lname']; $fullname=ucwords($fullname); $email=$_POST['email']; $testemail=strpos($email,"@"); $testemail1=strpos($email,".com"); $mobile=$_POST['mobile']; if(strcmp($fname,"")==0) echo "Please Enter some text in FIRST NAME<br><br>"; if($testemail=="") echo "Email id is Not valid, it must contain txt@txt.com<br><br>"; elseif($testemail1=="") echo "Email id is Not valid, it must contain txt@txt.com<br><br>"; if(strlen($mobile)!=10) echo "Mobile Number is Not Valid, it must have 10 digit<br><br>"; echo "<center><b>Resume</b></center>"; echo "<div align=right>".$_POST['address']."<br><br>"; echo $email."<br><br>"; echo "Mobile: ".$mobile."<br><br></div>"; echo "<hr>"; echo "<b>Name</b> ",strtoupper($fullname)."<br><br>";

echo "<b>Father's Name</b> ",ucwords($_POST['faname'])."<br><br>"; echo "<b>Date Of Birth</b> ",$_POST['dob']."<br><br>"; echo "<b>Marital Status</b> ",strtolower($_POST['mstatus'])."<br><br>"; $qual=array("Degree"=>$_POST['degree'],"Institution"=>$_POST['inst'],"YearOfP ass"=>$_POST['yop'],"Marks"=>$qual[3]=$_POST['marks']); echo "<center><table border=3><tr><th>Degree</th><th>Institution</th><th>Year Of Pass</th><th>Marks(%)</th></tr>"; echo "<tr><td>".$qual["Degree"]."</td>"; echo "<td>".$qual["Institution"]."</td>"; echo "<td>".$qual["YearOfPass"]."</td>"; echo "<td>".$qual["Marks"]."</td></tr></table>"; ?> </form> </body> </html>

output for ex3.html

Output for php3.php

Name Of the Program4:ex4.php <html> <body> <form method="post"> <center> <pre> Select Name of the Field to Sort <select name="fields"> <option>sname <option>m1 <option>m2 <option>tot <option>avg </select> <input type="radio" name="rb1" value="asc">ASC <input type="radio" name="rb1" value="desc">DESC <input type="submit" name="s1" value="submit"> </form> </body> </html> <?php $connection=mysql_connect("localhost","root","") or die("coonect error"); $db=mysql_select_db("stdt",$connection); if($_POST['rb1']=="asc") $query="select * from tbl1 order by($_POST[fields]) asc"; else $query="select * from tbl1 order by($_POST[fields]) desc"; $result=mysql_query($query); echo "<table ><tr><th>Name</th><th>M1</th><th>M2</th><th>Tot</th> <th>Avg</th></tr>";

while($row=mysql_fetch_array($result)) { echo "<tr><td>".$row['sname']."</td>"; echo "<td>".$row['m1']."</td>"; echo "<td>".$row['m2']."</td>"; echo "<td>".$row['tot']."</td>"; echo "<td>".$row['avg']."</td>"; echo "</tr>"; } echo "</table>"; mysql_close($connection); ?>

Output for ex4.php

Name Of the Program5 :application.html <html> <head> <title> application </title> </head> <body> <form method="post" action="application.php"> <pre> <center> <h1>College Application</h1></center> Candidate Name Father's Name Date Of Birth Gender <input type="text" name="cname"> <input type="text" name="fname"> <input type="text" name="dob"> <input type="radio" name="gender"

value="female">Female<input type="radio" name="gender" value="male">Male Community <input type="radio" name="comm" value="oc/fc">oc/fc

<input type="radio" name="comm" value="bc/mbc">bc/mbc<input type="radio" name="comm" value="sc/st">sc/st Religion <option>hindu</option> <option>muslim</option> <option>christion</option> </select> Nationality <option> indian</option> <option> pakisthan</option> </select> Address <textarea name="address"> <select name="nationality"> <select name="religion">

</textarea> <table> <tr> <th>Qualification</th> <th>Inst</th> <th>YOJ</th> <th>Major</th> <th>YOP</th> <th>Marks</th> </tr> <tr> <td><input type="text" name="qual" size="8"></td> <td><input type="text" name="inst" size="20"></td> <td><input type="text" name="yoj" size="5"></td> <td><input type="text" name="msub" size="10"></td> <td><input type="text" name="yop" size="10"></td> <td><input type="text" name="marks" size="3"></td> </tr></table> Offering Courses<select name="offercourse"> <option>BCA</option> <option>B.Sc(I.T)</option> <option>B.Sc(C.S)</option> </select> <input type="submit" name="submit" value="Submit"> name="reset"> </form> </body> </html> <input type="reset"

Name Of the Program5:application.php <html> <center><h1>college application form</h1> </center> <body></head> <form method="post" action="lab5.html"> <pre><center> <h1>congradulation!...</h1> <h3>you application register successfully.</h3> <?php $connection=mysql_connect("localhost","root","")or die("couldnot connect server"); $db=mysql_select_db("collapp",$connection)or die ("could not connect to db"); $query="insert into personalinfo values('$_POST[cname]', '$_POST[fname]','$_POST[dob]','$_POST[gender]','$_POST[comm]','$_POST[religion]','$ _POST[nationality]','$_POST[address]')"; $query1="insert into admininfo values('$_POST[cname]','$_POST[qual]','$_POST[inst]','$_POST[yoj]','$_POST[msub]','$ _POST[yop]','$_POST[marks]','$_POST[offercourse]')"; $result=mysql_query($query) or die("query err"); $result1=mysql_query($query1) or die("query err"); ?> <b>soon you will receive call letter</b> <input type="submit" value="goto applicationform"> </form> </body> </html>

Output for application.html

Output for application.php

Name of the program6 :ex6.php <?php echo "<h3>Read File Information Using Parser Function</h3>"; echo "<b>Prints the file information with same farmat as it saved</b><br><br>"; $file = file_get_contents("http://localhost/durga/text1.txt"); print nl2br(htmlentities($file)); echo "<br><br><b>Remove newlines and Prints the file information </b><br><br>"; $fp=fopen("text1.txt","r"); while ($data = fread($fp, 4096)) { $data = preg_replace("/\n|\r/","",$data); echo $data; } ?>

Output1 for ex6.php: Parser Functions

Name of the Program7: ex7.php <html> <head> <title> Regular Expression </title> </head> <body> <form method="POST" action=""> <pre> Enter Your Name <input type="text" name="t1"> Enter Your E-Mail ID <input type="text" name="t2"> Enter Your Fav Color <input type="text" name="t3"> Enter Date(yyyy-mm-dd) <input type="text" name="t4"> <input type="Submit" name="s1" value="Check Validation"> </form> </body> </html> <?php if(isset($_POST[t1])) { $pattern = '/^[a-zA-Z0-9_.-]{4,20}$/'; $username = $_POST[t1]; if (preg_match($pattern,$username)) echo "<br>Entered Name Format is Correct<br>"; else cho"<br>Entered Name Format is Not match<br>"; } $pattern = "/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/"; $email =$_POST[t2]; if(isset($_POST[t2]))

{ if (preg_match($pattern,$email)) echo "<br>Entered Email Format is Correct<br>"; else echo "<br>Entered Email Format is Not match<br>"; } if(isset($_POST[t3])) { $pattern = '/^#(([a-fA-F0-9]{3}$)|([a-fA-F0-9]{6}$))/'; $color = $_POST[t3]; if (preg_match($pattern,$color)) echo "<br>Entered Color Format is Correct<br>"; else echo "<br>Entered Color Format is Not match<br>"; } if(isset($_POST[t4])) { echo "Your Entered Date is (mm/dd/yyyy)"; echo preg_replace("/(\d+)-(\d+)-(\d+)/", "$2/$3/$1", $_POST[t4]); } ?>

Output1 for ex7.php: Regular Expression Validation

Output2 for ex7.php: Regular Expression Validation

Name of the Program8: ex8.php <?php echo"<h3>NetWork Functions</h3>"; echo "<b>216.239.115.148 IP</b> Address to Long".ip2long('216.239.115.148'); echo "<br><br>"; echo "<b>-655395948</b> Long to IP Address".long2ip(-655395948); echo "<br><br>"; $ip=gethostbyname('www.google.com'); echo "<b>wwww.google.com</b>- Gets IP Address from Internet Host name = ".$ip; echo "<br><br>"; $hostname=gethostbyaddr($_SERVER['REMOTE_ADDR']); echo "<b>SERVER['REMOTE_ADDR']</b>- Gets Internet hostname from given IP Address =".$hostname; echo"<h3>File System Functions</h3>"; echo "<b>The Size Of File is=</b>".filesize("text1.txt"); $file=fopen("text1.txt","a+"); echo "<h4>Reading and Appanding File Information </h4>".fread($file,"200"); fwrite($file,"durga"); fclose($file); echo"<h3>Date and Time Functions</h3>"; echo "<b>Check the Given date(M D Y) is valid or not(23,31,2000) </b>"; var_dump(checkdate(23,31,2000)); echo "<br><br><b>Date=</b>".date("D M d Y"); echo "<br><br><b>Sunrise Time=</b>". (date_sunrise(time(),SUNFUNCS_RET_STRING,38.4,-9,90,1)); echo "<br><br><b>getdate Function</b>"; print_r(getdate()); ?>

Output1 for ex8.php :Network , file system , date time functions

Name of the Program9: ex9.html <html> <head> <title> Lab Ex 10 </title> <h1><center> Saving and Retrieving the Session Information </center></h1> </head> <body> <form method="post" action="sess.php"> <pre> <center> Name of the Variable to Store Information <input type="text" name="t1"> Enter Information To Store Enter the time, how long to store <input type="text" name="t2"> <input type="text" name="t3">

Do You want <input type="radio" value="Save" name="op">Save <input type="radio" value="Retrieve" name="op">Retrieve <input type="hidden" name="h1" value="session"> <input type="submit" name="s1"> </center> </form> </body> </html>

Name Of the Program9: sess.php <?php if($_POST['h1']=="session") { session_start(); $value=$_POST['t2']; $var=$_POST['t1']; if($_POST[op]=="Save") { $_SESSION[$var]=$value; echo "<center> Session Information saved "; } else { echo "<center> Session Information "; echo $_SESSION[$var]; } } ?>

Output1 for ex9.html: Saving and Retrieving Session Information

Output2 for ex9.html: Saving and Retrieving Session Information

Output3 for ex9.html: Saving and Retrieving Session Information

Output4 for ex9.html: Saving and Retrieving Session Information

Name Of the Program10 : ex10.html <html> <head> <title> Lab Ex 10 </title> <h1><center> Session Info and Cookie Information </center></h1> </head> <body> <form method="post" action="sess_cookie.php"> <pre> <center> Name of the Variable to Store Information <input type="text" name="t1"> Enter Information To Store Enter the time, how long to store <input type="text" name="t2"> <input type="text" name="t3">

Do You want <input type="radio" value="+" name="op">Increment <input type="radio" value="-" name="op">Decrement <input type="radio" name="rb1" value="session"> Session Variable <input type="radio" name="rb1" value="cookie"> Cookie Variable <input type="submit" name="s1"> </center> </form> </body> </html>

Name Of the Program10: sess_cookie.php <?php if($_POST['rb1']=="cookie") { $var=$_POST['t1']; $value=$_POST['t2']; if($_POST[op]=="+") setcookie("$var",$value,time()+$_POST['t3']); else setcookie("$var",$value,time()-$_POST['t3']); echo "<center>"; if(isset($_COOKIE["$var"])) echo "Cookie Information is <b>". $_COOKIE["$var"]."</b>"; } if($_POST['rb1']=="session") { session_start(); $value=$_POST['t2']; $var=$_POST['t1']; $_SESSION[$var]=$value; if($_POST[op]=="+") { } Else { if($_POST[t3]<=3600) $_SESSION[$var]="0"; echo "<center> Session Information "; echo $_SESSION[$var]; } } ?> echo "<center> Session Information "; echo $_SESSION[$var];

Output for ex10.html

Output for sess_cook.php

Output for ex10.html

Output for cookie:

Vous aimerez peut-être aussi