Академический Документы
Профессиональный Документы
Культура Документы
<html>
<head>
<title>Controls And Functions</title>
</head>
<body>
<form action="index.php" method="post">
<table cellpadding="5px" align="center">
<tr>
<td>Name</td>
<td><input type="text" name="nam"></td>
</tr>
<tr>
<td>Age</td>
<td><input type="text" name="age" ></td>
</tr>
<tr>
<td><input type="submit" name="submit"
value="Registar"></td>
<td><input type="reset" name="reset" Value="Clear
All"></td>
</tr>
</table>
</form>
<?php
if(isset($_POST["submit"]))
{
validate($_POST["nam"],$_POST["age"]);
}
function validate($name,$age)
{
if($age>=18)
{
echo $name." Age $age You are Eligible For Voting...";
}
else
{
echo $name." Age $age You are Not Eligible For Voting...";
}
}
?>
</body>
</html>
Program using controls and functions
Output
Message passing mechanism between pages
Index.php
<html>
<head>
<title>Message Passing Mechanism</title>
</head>
<body>
<h1 align="center">Student Registration</h1>
<form action="secondpage.php" method="post">
<table cellpadding="5px" align="center">
<tr>
<td>Name</td>
<td><input type="text" name="nam"></td>
</tr>
<tr>
<td>Age</td>
<td><input type="text" name="age" ></td>
</tr>
<tr>
<td>Department</td>
<td><input type="text" name="dep" ></td>
</tr>
<tr>
<td><input type="submit" name="submit"
value="Registar"></td>
<td><input type="reset" name="reset" Value="Clear
All"></td>
</tr>
</table>
</form>
<?php
if(isset($_GET["err"]))
{
echo "<i style='color:red;'>".$_GET["err"]."</i>";
}
?>
</body>
</html>
secondpage.php
<?php
if(isset($_POST["submit"]))
{
$a="";
if($_POST["nam"]!=""&&$_POST["age"]!=""&&$_POST["dep"]!="")
{
$a.="<h1>Student Registration</h1>";
$a.="<table border='1px' cellpadding='5px'>";
$a.="<tr><td>Name</td><td>".$_POST["nam"]."</td></tr>";
$a.="<tr><td>Age</td><td>".$_POST["age"]."</td></tr>";
$a.="<tr><td>Department</td><td>".$_POST["dep"]."</td></tr>";
$a.="<table>";
echo $a;
}
else
{
header("location:first.php?err=Enter All Feilds");
}
}
else
{
header("location:first.php?err=Access Denied");
}
?>
Output
String Functions and Arrays
<html>
<head>
<title>Strings And Array</title>
</head>
<body>
<form action="index.php" method="post">
Enter The Names :
<input type="text" name="nam">
<input type="submit" name="submit">
</form>
<?php
if(isset($_POST["submit"]))
{
$names=explode(",",$_POST["nam"]);
echo "<br>Array Format : ";print_r($names);
echo "<br><br>";
foreach($names as $a)
{
echo "<br>Upper case : ".strtoupper($a);
echo "<br>Lower case : ".strtolower($a);
echo "<br>Reverse : ".strrev($a);
echo "<br><br>";
}
asort($names);
echo "<br>Name In Ascending Order ";
echo "<br><br>";
foreach($names as $a)
{
echo "<br>".$a;
}
echo "<br><br>";
rsort($names);
echo "<br>Name Reverse Sort ";
echo "<br><br>";
foreach($names as $a)
{
echo "<br>".$a;
}
}
else
{
echo "Enter The Name List Separate By Comma(,)";
}
?></body> </html>
Output
Array Format : Array ( [0] => sun [1] => mon [2] => tue [3] => wed [4] => thu [5] => fri [6] =>
sat )
fri
mon
sat
thu
tue
wed
sun
sun
wed
tue
thu
sat
mon
fri
Parsing Functions using Tokenizing
Index.php
<?php
$parser=xml_parser_create();
function char($parser,$data)
{
echo $data;
}
xml_set_character_data_handler($parser,"char");
$fp=fopen("test.xml","r");
while ($data=fread($fp,filesize("test.xml")))
{
xml_parse($parser,$data,feof($fp)) or
die (sprintf("XML Error: %s at line %d",
xml_error_string(xml_get_error_code($parser)),xml_get_current_line_number($parser)));
}
xml_parser_free($parser);
?>
Test.xml
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<body>
<?php
$_SESSION["name"] = "Rani";
$_SESSION["depart"] = "BCA";
?>
</body>
</html>
Output
Session In PHP
Destroy Variable
Index.php
<!DOCTYPE html>
<html>
<title>Session and Cookies</title>
<body>
<h1>Session And Cookies</h1>
<ol>
<li><a href="setcookie.php" target="_blank">Set Cookie Values</a></li>
<li><a href="view.php" target="_blank">Set Session Using Cookie</a></li>
</ol>
</body>
</html>
Setcookie.php
<!DOCTYPE html>
<?php
session_start();
$cookie_name = "Tutor";
$cookie_value = "Joes";
setcookie($cookie_name, $cookie_value, time()+1000, "/");
?>
<html>
<body>
<?php
if(!isset($_COOKIE[$cookie_name]))
{
echo "Cookie value is not set!";
// remove all session variables
session_unset();
<?php
// Echo session variables that were set on previous page
if(isset($_SESSION["name"]))
{
echo "Welcome ".$_SESSION["name"].".<br>";
}
else
{
echo "Session Variables is already destroy.";
}
?>
</body>
</html>
Output
Welcome Joes.
Checking file system functions, network functions, date and time functions
Index.php
<!DOCTYPE html>
<html>
<title>PHP Functions</title>
<body>
<ol>
<li><a href="regular.php" target="_blank">Regular Expression
Functions</a></li>
<li><a href="hash.php" target="_blank">Hash Function</a></li>
<li><a href="html.php" target="_blank">HTML
Function</a></li>
</ol>
</body>
</html>
Regular.php
<?php
// create a string
$string = 'abcdefghijklmnopqrstuvwxyz0123456789';
if(preg_match("/abc/", $string))
{
if(preg_match("/^abc/", $string))
{
echo 'The string begins with abc.<br>';
}
else
{
echo 'No match found .<br>';
}
if(preg_match("/89\z/i", $string))
{
echo 'The string ends with 89';
}
else
{
echo 'No match found';
}
?>
Hash.php
<?php
echo "<h1>Sha1 HASHING</h1>";
$str = "Hello";
echo sha1($str);
if (sha1($str) == "f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0")
{
echo "<br>Hello world!";
}
if (md5($str) == "8b1a9953c4611296a827abf8c47804d7")
{
echo "<br>Hello world!";
}
?>
Html.php
<!DOCTYPE html>
<html>
<body>
<?php
$str = "Jane & 'Tarzan'";
echo htmlentities($str, ENT_COMPAT); // Will only convert double quotes
echo "<br>";
echo htmlentities($str, ENT_QUOTES); // Converts double and single quotes
echo "<br>";
echo htmlentities($str, ENT_NOQUOTES); // Does not convert any quotes
?>
</body>
</html>
Output
File Function
File is Present.
Write File Content.
Read File Content.
Hello World. Testing!Hello World. Testing!Hello World. Testing!Hello World. Testing!Hello
World. Testing!Hello World. Testing!
File Size :126
Last modified: January 20 2015 08:50:32.
Checking regular expression, html functions and hashing functions
Index.php
<!DOCTYPE html>
<html>
<title>PHP Functions</title>
<body>
<ol>
<li><a href="date.php" target="_blank">Date And Time
Functions</a></li>
<li><a href="network.php" target="_blank">Network Function
(works only through Internet)</a></li>
<li><a href="file.php" target="_blank">File Function</a></li>
</ol>
</body>
</html>
Date.php
<html>
<head>
<title>Date and Functions In PHP</title>
</head>
<body>
<?php
echo "Data in Short Format : ".date("d/m/Y");
echo"<br>";
echo "Data in Long Format : ".date("d F Y");
echo"<br>";
date_default_timezone_set("Asia/Kolkata");
echo"<br>";
echo date("l dS F Y h:i:s A");
?>
<body>
</html>
Network.php
<?php
$hosts = array();
$ret = getmxrr('google.com', $hosts);
if ($ret) {
print_r($hosts);
} else {
echo 'MX retrieval failed';
}
echo "<br>";
echo gethostbyaddr('127.0.0.1');
echo "<br>";
echo gethostbyname('joe');
echo "<br>";
echo ip2long('216.239.115.148');
echo "<br>";
echo long2ip(-655395948);
$data = dns_get_record('google.com');
print_r($data);
?>
File.php
<?php
if(file_exists("test.txt"))
{
echo "File is Present.<br>";
}
else
{
echo "File Not Found.<br>";
}
Hash function
Sha1 HASHING
f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0
Hello world!
MD5 HASHING
8b1a9953c4611296a827abf8c47804d7
Hello world!
HTML function