Forms of PHP

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Forms of php echo"<h4>POST METHOD</h4>";

Example: 01 print_r($_POST);

<body> echo "<h2>Welcome ".$_POST['n']."</h2>";

}
<form name="f1" action="f1p.php" method="post">
?>
Name:<input type="text" name="n" /><br />
</pre>
Age: <input type="text" name="a" /><br />
Example: 03 (upload)
<input type="submit" value="SUBMIT" /> <form name="frm1" action="<?
=$_SERVER['PHP_SELF']?>" method="post"
</form> enctype="multipart/form-data">

</body> <input type="hidden" name="MAX_FILE_SIZE"


value="50000" />
Next page
<input type="file" name="f" />
<? <input type="submit" name="up" value="UPLOAD" />
echo"<h4>GET METHOD</h4>"; </form>

print_r($_GET); <?

echo "Your Name is: ".$_GET['n']." <br />"; if(isset($_POST['up'])):

print_r($_FILES);
echo"<h4>POST METHOD</h4>";
$on=$_FILES['f']['name']; //originam name
print_r($_POST);
$tn=$_FILES['f']['tmp_name']; // temporary
echo "Your Name is: ".$_POST['n']."<br />"; name and path

$ty=$_FILES['f']['type'];// type of the file


echo"<h4>REQUEST METHOD</h4>";
$sz=$_FILES['f']['size']; // size of the file
print_r($_REQUEST);
$dd="upload/".$on;
echo "Your Name is: ".$_REQUEST['n']."<br />";

?>
if($_FILES['f']['error']==0 and
Example: 02 $ty=="image/jpeg"){

<form name="f1" action="server.php" method="post"> move_uploaded_file($tn,$dd) or


die("problem occured while uploding");
Name:<input type="text" name="n" /><br />
echo"<h4>File uploaded
Age: <input type="text" name="a" /><br /> successfully</h4>";

<input type="submit" value="SUBMIT" /> }else{

</form> echo"<h4>Different File or size</h4>";

<pre> }

<? endif;

if(isset($_POST['n']) and !empty($_POST['n'])){ ?>


Example: 04 (mail) ';

<?

$to="[email protected]"; $headers = 'MIME-Version: 1.0' . "\r\n";


$sub="You got a job in Wipro"; $headers .= 'Content-type: text/html; charset=utf-8' .
"\r\n";
$msg="<h1>antaaaaaaa Blah... Blah... Blahh....</h1>";

$headers="From:[email protected]";
$headers .= 'From: [email protected]' . "\r\n" .
mail($to,$sub,$msg,$headers);
'Reply-To: [email protected]' . "\r\n" .
?>
'X-Mailer: PHP/' . phpversion()."\r\n" ;
Example: 05 (mail 2)
$headers .= 'Bcc: [email protected]' . "\r\n";
<?
$headers .= 'Cc: [email protected]' . "\r\n";
$to="[email protected]";

$sub="Offer letter from infosis";


mail($to,$sub,$msg,$headers);
$msg='<p>Dear Aplicant,</p>
?>
<p><strong>Congratulations.</strong> You are selected
for the job in PHP. fnlkf dfkld</p> <h4>Mail Sent Successfully</h4>
<h4>Your Salary Details:</h4>

Example: 06
<table width="400" border="0" cellspacing="0" <?
cellpadding="0">
echo "<h4>Client IP Address: ".
<tr bgcolor="#ccc"> $_SERVER['REMOTE_ADDR']."</h4>";
<th scope="col">Salary</th> echo "<h4>Script FielName: ".
$_SERVER['SCRIPT_FILENAME']."</h4>";
<th scope="col">HRA</th>
echo "<h4>Script Name: ".
<th scope="col">TD & BD</th>
$_SERVER['SCRIPT_NAME']."</h4>";
</tr>
echo "<h4>Referer Name: ".
<tr> $_SERVER['HTTP_REFERER']."</h4>";

<td>30000</td> echo "<h4>Script Name: ".


$_SERVER['REQUEST_URI']."</h4>";
<td>12000</td>
echo getcwd();
<td>12000</td>
?>
</tr>
Forms read
</table><br />
<?
<p>regards,<br />
$f=fopen("aa.txt","r");
HR,

Infosis.com</p>
echo fread($f,10)."<br>";
rewind($f); ?>

echo fgetc($f)."<br />";

fseek($f,0);

while(!feof($f)){

echo fgets($f)."<br />";

fclose($f);

?>

Form open

<?

$f=fopen("aa.txt","w");

fwrite($f,"This is written by PHP.\n");

fwrite($f,"This is written by PHP.\n");

fwrite($f,"This is written by PHP.\n");

fwrite($f,"This is written by PHP.\n");

fclose($f);

?>

Form opend

<?

$f=fopen("aa.txt","a+");

fwrite($f,"Thi si supdated1.\n");

fwrite($f,"Thi si supdated2.\n");

fwrite($f,"Thi si supdated3.\n");

fseek($f,0);

while(!feof($f)){

echo fgets($f)."<br />";

fclose($f);

You might also like