Ganesh5 Merged
Ganesh5 Merged
<form method="post">
Enter your DOB:
<input type="text" name="D">
<input type="submit" name="enter">
</form>
<?php
$dob=date($_POST['D']);
$today=date('Y-M-D');
$age=$today - $dob;
echo "DOB: $dob <br>";
echo "your age is: $age" ;
?>
</html>
<?php
session_start();
if(isset($_SESSION['count']))
{
echo "your session count:".$_SESSION['count']."<br>";
$_SESSION['count']++ ;
}
else
{
$_SESSION['count']=1;
echo "session does not exist";
}
?>
<?php
$arr=array(array(23,45,67,90), array(80,60,48,99), array(100, 60, 40, 30));
$temp=0;
foreach($arr as $val)
{
foreach($val as $key=>$val_1)
{
if($val_1 > $temp)
{
$temp =$val_1;
}
}
}
echo("the maximum value is: $temp");
?>
<html>
<body>
<form method="post">
Enter a N value:
<input type="number" name="N"><br>
Enter a M value:
<input type="number" name="M"><br>
<input type="submit" name="Enter">
</form>
<?php
$N=$_POST['N'];
$M=$_POST['M'];
$temp=$N % $M;
echo "N= $N <br> M=$M<br>";
if($temp == 0)
{
echo "N divisible by M";
}
else
{
echo "N not divisible by M";
}
?>
</body>
<html>
<body>
<form method="post">
Enter a number: <input type="number" name="num">
<input type="submit">
</form>
<?php
if ($_POST['num']) {
$fact = 1;
for ($i = 1; $i <= $_POST['num']; $i++) $fact *= $i;
echo "Factorial: $fact";
}
?>
</body>
</html>
<html>
<head>
</title>SIMPLE CALCULATOR</title>
</head>
<body>
<form method="post" action="">
<input type="number" name="num1" placeholder="enter first number">
<select name="operator">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="number" name="num2" placeholder="enter second number">
<input type="submit" name="submit" value="calculate">
</form>
<?php
if(isset($_POST['submit']))
{
$num1=$_POST['num1'];
$num2=$_POST['num2'];
$operator=$_POST['operator'];
switch($operator)
{
case"+":$result=$num1+$num2;break;
case"-":$result=$num1-$num2;break;
case"*":$result=$num1*$num2;break;
case"/":$result=$num1/$num2;break;
default:$result=0;
}
echo"$num1 $operator $num2=$result";}
?>
</body>
</html>
<?php
$time=time()+(60*60*24*60);
setcookie('last_visit',date("H:m:s-y/m/d"),$time);
if(isset($_COOKIE['last_visit']))
{
$visit=$_COOKIE['last_visit'];
echo "Your Last Visit is :", $visit;
}
else
{
echo "You have Some State cookies!";
}
?>
<html>
<body>
<form method="post">
enter a number:
<input type="text" name="n">
<input type="submit" name="enter">
</form>
<?php
$n=$_POST['n'];
for($i=1;$i<=10; $i++)
{
$res=$i * $n;
echo "$i * $n = $res<br>";
}
?>
</html>
</body>
<html>
<form method="post">
n1:
<input type="number" name="n1"><br>
n2:
<input type="number" name="n2"><br>
<input type="submit" name="Enter"><br>
</form>
<?php
function gcd($a,$b)
{
if($b==0)
{
return $a;
}
return gcd($b,$a%$b);
}
$n1=$_POST['n1'];
$n2=$_POST['n2'];
$res=gcd($n1,$n2);
echo "n1= $n1 <br> n2=$n2 <br> ";
echo "GCD= $res";
?>
</html>
<a href="download.php?file=example.txt">Download</a>
<?php
if ($file = $_GET['file'] ?? '') {
$path = 'files/' . basename($file);
if (file_exists($path)) {
header('Content-Disposition: attachment; filename=' . basename($path));
header('Content-Length: ' . filesize($path));
readfile($path);
exit;
}
}
echo 'File download!';
?>