Thursday, 9 January 2020

PHP PROGRAMMING

CH-1 PHP 7 OVERVIEW

1.<?php
echo "Hello wap";
?>

2.<?php
echo "<h1>Hello wap</h1>";
?>

3.<?php
echo "<h1 style='color:red'>Hello wap</h1>";
?>

4.<?php
echo "<h1 align='center'>Hello wap</h1>";
?>

5.<html>
<body>
<?php
echo "Hello wap";
?>
</body>
</html>

6.<?php
echo "Hello wap";
?> 
<html>
<body>
</body>
</html>

7.<html>
<body>
</body>
</html>
<?php
echo "Hello wap";
?>

8.<html>
<body>
</body>
<?php
echo "Hello wap";
?>
</html>

9.<html>
<body bgcolor="<?php echo "blue" ?>">
</body>
</html>

10.<html>
<body>
<?php
function demo(){
echo "hello wap";
}
demo();
?>
</body>
</html>

11.<html>
<body>
<?php
$x=6;
$y=10;
echo $x+$y;
?>
</body>
</html>

12.<html>
<body>
<?php
$x=i;
for($i=0;$i<5;$i++)
{
echo "Hello wap <br>"; 
}
?>
</body>
</html>

13.<html>
<body>
<?php
$x="saurav";
echo $x." kumar";
?>
</body>
</html>

14.<html>
<body>
<?php
$x=1;
if($x > 10)
{
echo "x is greater than 10";
}
else{
 echo "x is less than 10";
}
?>
</body>
</html>

15.<html>
<body>
<?php
echo "a<br>";
echo "b";
?>
</body>
</html>

16.<html>
<body>
<?php
echo "a<br>b<br>c";
?>
</body>
</html>

17.<?php
echo "<script>window.alert()</script>";
?>


CH-2 PHP EXTERNAL AND SUPERGLOBALS

1.<?php
$x=123;
$y="Thanks !";
echo $x." is the value of x".$y';
?>

2.<html>
<body>
<h1>
<?php
include("welcome.php");
?>
</h1>
</body>
</html>

=> welcome.php
<?php
$x="my name is saurav";
echo $x;
?>

3.<html>
<body>
<h1>
<?php
include("welcome.php");
echo $x;
?>
</h1>
</body>
</html>

=>welcome.php
<?php
$x="my name is saurav";
?>

4.<html>
<body>
<h1>
<?php
include("welcome.php");
echo $x+$y;
?>
</h1>
</body>
</html>

=>welcome.php
<?php
$x=10;
$y=12;
?>

5.<html>
<body>
<h1>
<?php
require("welcome.php");
echo $x+$y;
?>
</h1>
</body>
</html>

=>welcome.php
<?php
$x=10;
$y=12;
?>

6.<html>
<body>
<h1>
<?php
require("welcome.php");
echo $x+$y;
?>
</h1>
<h2>
<?php
require("welcome.php");
echo $x+$y;
?>
</h2>
</body>
</html>

=>welcome.php
<?php
$x=10;
$y=12;
?>

7.<html>
<body>
<form action="welcome.php" method="get">
email id<br>
<input type="email" name="email">
<br>
<input type="submit">
</form>
</body>
</html>

=>welcome.php
<?php
$result=$_GET['email'];
echo $result;
?>

8.<html>
<body>
<form action="welcome.php" method="post">
email id<br>
<input type="email" name="email">
<br>
<input type="submit">
</form>
</body>
</html>

=>welcome.php
<?php
$result=$_POST['email'];
echo $result;
?>

9.<html>
<body>
<form action="welcome.php" method="post">
email id<br>
<input type="email" name="email">
password
<input type="password" name="password">
<br>
<input type="submit">
</form>
</body>
</html>

=>welcome.php
<?php
$email=$_POST['email'];
$password=$_POST['password'];
echo $email."<br>".$password;
?>

10.<html>
<body>
<form action="welcome.php" method="post">
email id<br>
<input type="email" name="email">
password
<input type="password" name="password">
<br>
<input type="submit">
</form>
</body>
</html>

=>welcome.php
<?php
$email=$_POST['email'];
$password=$_POST['password'];
echo "username = ".$email."<br>"."password = ".$password;
?>

11.<html>
<body>
<form action="welcome.php" method="post">
email id<br>
<input type="email" name="email">
password
<input type="password" name="password">
<br>
<input type="submit">
</form>
</body>
</html>

=>welcome.php
<?php
$email=$_POST['email'];
$password=$_POST['password'];
?>
<html>
<body>
<form>
recieved email<br>
<input type="email" name="re-email" value="<?php echo $email ?>">
<br>
recieved password
<input type="password" name="re-password" value="<?php echo $password ?>">
</form>
</body>
</html>


CH-3 PHP 7 DIRECTORY CONTROL AND TRIGGER SUBMIT 

1.<html>
<body>
<form method="post" action="result.php">
<input type="email" name="email">
<input type="submit">
</form>
</body>
</html>

=>result.php
<?php
$result=$_POST['email'];
echo $result;
?>

2.<html>
<body>
<form method="post" action="result.php">
<input type="email" name="email">
<input type="submit">
</form>
</body>
</html>

=>result.php
<?php
$result=$_POST['email'];
echo $result;
echo $_SERVER['REQUEST_METHOD'];
?>

3.<html>
<body>
<form method="get" action="result.php">
<input type="email" name="email">
<input type="submit">
</form>
</body>
</html>

=>result.php
<?php
$result=$_GET['email'];
echo $result;
echo $_SERVER['REQUEST_METHOD'];
?>

4.<html>
<body>
<form method="post" action="result.php">
<input type="email" name="email">
<input type="submit">
</form>
</body>
</html>

=>result.php
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$result=$_POST['email'];
echo $result;
}
?>

5.<html>
<body>
<form method="post" action="result.php">
<input type="email" name="email">
<input type="submit">
</form>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$result=$_POST['email'];
echo $result;
}
?>

6.<html>
<body>
<form method="post" action="result.php">
<input type="email" name="email">
<input type="submit">
</form>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$result=$_POST['email'];
echo $result;
echo $_SERVER['PHP_SELF'];
}
?>

7.<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="email" name="email">
<input type="submit">
</form>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$result=$_POST['email'];
echo $result;
}
?>

8.<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="email" name="email">
<input type="submit">
</form>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$result=$_POST['email'];
echo $result;
echo "<h1 style='color:red'>$result</h1>";
}
?>

9.<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="email" name="email">
<input type="submit">
</form>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$result=$_POST['email'];
if($result == "")
{
echo "empty";
}
}
?>

10.<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="email" name="email">
<input type="submit">
</form>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$result=$_POST['email'];
if(empty($result))
{
echo "empty";
}
}
?>

11.<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="email" name="email">
<input type="submit">
</form>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$result=$_POST['email'];
if(!empty($result))
{
echo $_POST['email'];
}
else{
echo "empty";
}
}
?>

12.<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="email" name="email">
<input type="submit">
</form>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$result=$_POST['email'];
if(!empty($result))
{
echo $_POST['email'];
}
else{
echo "<script>alert('empty')</script>";
}
}
?>

13.<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="email" name="email">
<input type="submit">
</form>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$result=$_POST['email'];
if(!empty($result))
{
echo $_POST['email'];
}
else{
echo "<script>window.location='https://google.com'</script>";
}
}
?>

14.<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="email" name="email">
<input type="submit">
</form>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$result=$_POST['email'];
if(!empty($result))
{
echo $_POST['email'];
}
else{
header('Location:https://google.com');
}
}
?>

15.<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="folder_name">
<input type="submit">
</form>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$folder_name=$_POST['folder_name'];
mkdir($folder_name);
}
?>

16.<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="folder_name">
<input type="submit">
</form>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$folder_name=$_POST['folder_name'];
if(mkdir($folder_name))
{
echo "Folder created";
}
else{
echo "Folder already exist";
}
}
?>

17.<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="folder_name">
<input type="submit">
</form>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$folder_name=$_POST['folder_name'];
if(mkdir($folder_name))
{
echo "Folder created";
}
else{
echo "<style>.xe-warning{display:none}</style>";
echo "Folder already exist";
}
}
?>

18.<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="folder_name">
<input type="submit">
</form>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$folder_name=$_POST['folder_name'];
if(mkdir("c:/".$folder_name))
{
echo "Folder created";
}
else{
echo "<style>.xe-warning{display:none}</style>";
echo "Folder already exist";
}
}
?>

19.<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="folder_name">
<input type="submit">
</form>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$folder_name=$_POST['folder_name'];
if(mkdir("c:/wamp/".$folder_name))
{
echo "Folder created";
}
else{
echo "<style>.xe-warning{display:none}</style>";
echo "Folder already exist";
}
}
?>

20.<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="folder_name">
<input type="submit">
</form>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$folder_name=$_POST['folder_name'];
if(rmdir("c:/wamp/".$folder_name))
{
echo "Folder deleted";
}
else{
echo "<style>.xe-warning{display:none}</style>";
echo "Folder not found or some content available in folder";
}
}
?>

21.<html>
<body>
</body>
</html>
<?php
$array=scandir("c:/");
echo $array;
?>

22.<html>
<body>
</body>
</html>
<?php
$array=scandir("c:/");
echo $array[0];
?>

23.<html>
<body>
</body>
</html>
<?php
$array=scandir("c:/");
echo sizeOf($array);
?>

24.<html>
<body>
</body>
</html>
<?php
$array=scandir("c:/");
$length=sizeOf($array);
$i;
for($i=0;$i<length;$i++)
{
echo $array[$i]."<br>";
}
?>


CH-4 PHP 7 WITH MYSQL INTRO

1.<?php
$db=new mysqli("localhost","root","");
?>

2.<?php
$db=new mysqli("localhost","root","");
if($db->connect_error)
{
echo "database not connected";
}
else{
echo "database connected";
}
?>

3.<?php
$db=new mysqli("localhost","root","");
if($db->connect_error)
{
echo "database not connected";
}
else{
$sql_code="CREATE DATABASE adse";
if($db->query($sql_code))
{
echo "database created";
}
else{
echo "database not created";
}
}
?>

4.<?php
$db=new mysqli("localhost","root","");
if($db->connect_error)
{
echo "database not connected";
}
else{
$sql_code="DROP DATABASE adse";
if($db->query($sql_code))
{
echo "database deleted";
}
else{
echo "database not deleted";
}
}
?>

CH-5 PHP 7 SIGN UP WITH DATABASE

1.<?php
$db=new mysqli("localhost","root","");
if($db->connect_error)
{
echo "error";
}
else{
$sql_code="CREATE DATABASE demo";
$check=$db->query($sql_code);
if($check)
{
echo "database created";
}
else{
echo "database not created";
}
}
?>

2.<?php
$db=new mysqli("localhost","root","","wap");
if($db->connect_error)
{
echo "error";
}
else{
$sql_code="CREATE TABLE users(
id INT(11) NOT NULL AUTO_INCREMENT,
full_name VARCHAR(50),
email VARCHAR(50),
password VARCHAR(50),
PRIMARY KEY(id)
)";
$check=$db->query($sql_code);
if($check)
{
echo "table created";
}
else{
echo "table not created";
}
}
?>

3.<?php
$db=new mysqli("localhost","root",''","wap");
if($db->connect_error)
{
echo "database not connected";
}
else{
if($_SERVER['REQUEST_METHOD']=="POST")
{
$fullname=$_POST['fullname'];
$email=$_POST['email'];
$password=$_POST['password'];
$sql_code="INSERT INTO users(full_name,email,password)
VALUES('$fullname','$email','$password')";
if($db->query($sql_code))
{
echo "Sign up success";
}
else{
echo "Sign up failed";
}
}
}
?>
<html>
<body>
<form method="post" action="test.php">
<fieldset>
<legend>Sign up</legend>
FULL NAME<br>
<input type="text" name="fullname">
<br><br>
Email<br>
<input type="email" name="email">
<br><br>
PASSWORD<br>
<input type="password" name="password">
<br><br>
<input type="submit" value="signup now">
</fieldset>
</form>
</body>
</html>

4.<?php
$db=new mysqli("localhost","root","","wap");
$message="";
if($db->connect_error)
{
echo "database not connected";
}
else{
if($_SERVER['REQUEST_METHOD']=="POST")
{
$fullname=$_POST['fullname'];
$email=$_POST['email'];
$password=md5($_POST['password']);
$sql_code="INSERT INTO users(full_name,email,password)
VALUES('$fullname','$email','$password')";
if($db->query($sql_code))
{
$message="Sign up success";
}
else{
$message="Sign up failed";
}
}
}
?>
<html>
<body>
<form method="post" action="test.php">
<fieldset>
<legend>Sign up</legend>
FULL NAME<br>
<input type="text" name="fullname">
<br><br>
Email<br>
<input type="email" name="email">
<br><br>
PASSWORD<br>
<input type="password" name="password">
<br><br>
<input type="submit" value="signup now">
<br>
<?php echo $message; ?>
</fieldset>
</form>
</body>
</html>

CH-6 PHP 7 WITH MYSQL LOGIN SYSTEM

1.<html>
<body>
<form method="post" action="signup.php">
<fieldset>
<legend>Sign up</legend>
FULL NAME<br>
<input type="text" name="fullname">
<br><br>
Email<br>
<input type="email" name="username">
<br><br>
PASSWORD<br>
<input type="password" name="password">
<br><br>
<input type="submit" value="signup now">
<br>
</fieldset>
</form>
</body>
</html>
<?php
$db=new mysqli("localhost","root","","app");
if($db->connect_error)
{
echo "database not connected";
}
else{
if($_SERVER['REQUEST_METHOD']=="POST")
{
$fullname=$_POST['fullname'];
$email=$_POST['username'];
$password=md5($_POST['password']);
$check_user="SELECT username FROM users WHERE username='$email'";
$response=$db->query($check_user);
echo $response->num_rows;
}
}
?>

2.<html>
<body>
<form method="post" action="signup.php">
<fieldset>
<legend>Sign up</legend>
FULL NAME<br>
<input type="text" name="fullname">
<br><br>
Email<br>
<input type="email" name="username">
<br><br>
PASSWORD<br>
<input type="password" name="password">
<br><br>
<input type="submit" value="signup now">
<br>
</fieldset>
</form>
</body>
</html>
<?php
$db=new mysqli("localhost","root","","app");
if($db->connect_error)
{
echo "database not connected";
}
else{
if($_SERVER['REQUEST_METHOD']=="POST")
{
$fullname=$_POST['fullname'];
$email=$_POST['username'];
$password=md5($_POST['password']);
$check_user="SELECT username FROM users WHERE username='$email'";
$response=$db->query($check_user);
if($response->num_rows==0)
{
$store_user="INSERT INTO users(full_name,username,password)
VALUES('$fullname','$email','$password')";
if($db->query($store_user))
{
echo "signup success";
}
else{
echo "Signup failed !";
}
}
else{
echo "User already exist";
}
}
}
?>

3.<html>
<body>
<form method="post" action="register.php">
<fieldset>
<legend>Sign up</legend>
FULL NAME<br>
<input type="text" name="fullname">
Email<br>
<input type="email" name="username">
<br><br>
PASSWORD<br>
<input type="password" name="password">
<br><br>
<input type="submit" value="signup now">
<br>
</fieldset>
</form>
<br><br>
<form method="post" action="login.php">
<fieldset>
<legend>LOGIN</legend>
USERNAME<br>
<input type="text" name="username">
<br><br>
PASSWORD<br>
<input type="password" name="password">
<br><br>
<input type="submit" value="Login">
<br>
</fieldset>
</form>
</body>
</html>

=>register.php
<?php

$db=new mysqli("localhost","root","","app");

if($db->connect_error)

{

echo "database not connected";

}

else{

if($_SERVER['REQUEST_METHOD']=="POST")

{

$fullname=$_POST['fullname'];

$email=$_POST['username'];

$password=md5($_POST['password']);

$check_user="SELECT username FROM users WHERE username='$email'";

$response=$db->query($check_user);

if($response->num_rows==0)

{

$store_user="INSERT INTO users(full_name,username,password)

VALUES('$fullname','$email','$password')";

if($db->query($store_user))

{

echo "signup success";

}

else{

echo "Signup failed !";

}

}

else{

echo "User already exist";

}

}

}

?>

=>login.php

<?php
$db=new mysqli("localhost","root","","app");
if($db->connect_error)
{
echo "database not connected";
}
else{
if($_SERVER['REQUEST_METHOD']=="POST")
{
$username=$_POST['username'];
$password=md5($_POST['password']);
$check_user="SELECT username FROM users WHERE username='$username'";
$response=$db->query($check_user);
if($response->num_rows==1)
{
echo "user exit";
}
else{
echo "user not found !";
}
}
}
?>



4.<html>

<body>
<form method="post" action="register.php">
<fieldset>
<legend>Sign up</legend>
FULL NAME<br>
<input type="text" name="fullname">
Email<br>
<input type="email" name="username">
<br><br>
PASSWORD<br>
<input type="password" name="password">
<br><br>
<input type="submit" value="signup now">
<br>
</fieldset>
</form>
<br><br>
<form method="post" action="login.php">
<fieldset>
<legend>LOGIN</legend>
USERNAME<br>
<input type="text" name="username">
<br><br>
PASSWORD<br>
<input type="password" name="password">
<br><br>
<input type="submit" value="Login">
<br>
</fieldset>
</form>
</body>
</html>

=>register.php
<?php

$db=new mysqli("localhost","root","","app");

if($db->connect_error)

{

echo "database not connected";

}

else{

if($_SERVER['REQUEST_METHOD']=="POST")

{

$fullname=$_POST['fullname'];

$email=$_POST['username'];

$password=md5($_POST['password']);

$check_user="SELECT username FROM users WHERE username='$email'";

$response=$db->query($check_user);

if($response->num_rows==0)

{

$store_user="INSERT INTO users(full_name,username,password)

VALUES('$fullname','$email','$password')";

if($db->query($store_user))

{

echo "signup success";

}

else{

echo "Signup failed !";

}

}

else{

echo "User already exist";

}

}

}

?>
=>login.php

<?php
$db=new mysqli("localhost","root","","app");
if($db->connect_error)
{
echo "database not connected";
}
else{
if($_SERVER['REQUEST_METHOD']=="POST")
{
$username=$_POST['username'];
$password=md5($_POST['password']);
$check_user="SELECT username FROM users WHERE username='$username'";
$response=$db->query($check_user);
if($response->num_rows==1)
{
$check_password="SELECT password FROM users WHERE password='$password'";
$pwd_response=$db->query($check_password);
if($pwd_response->num_rows==1)
{
header("Location:https://google.com");
}
else{
echo "wrong password !";
}
}
else{
echo "user not found !";
}
}
}
?>



CH-7 PHP 7 WITH MYSQL AJAX REQUEST



1.<html>
<head>
</head>
<body>
<button>Request php page</button>
<script>
$(document).ready(function(){
$("button").click(function(){
$.ajax({
type:"GET",
url:"result.php",
success:function(response){
alert(response);
}
});
});
});
</body>
</html>
=>result.php
<?php
echo "success";
?>

2.<html>
<head>
</head>
<body>
<input type="email" id="username" name="email">
<button>Check user</button>
<p></p>
<script>
$(document).ready(function(){
$("button").click(function(){
var username=$("#username").val();
$.ajax({
type:"GET",
url:"result.php?email="+username,
success:function(response){
$("p").html(response);
}
});
});
});
</body>
</html>
=>result.php
<?php
$username=$_GET['email'];
$db=new mysqli("localhost","root"."","app");
if($db->connect_error)
{
echo "database not connected";
}
else{
$check_user="SELECT email FROM users WHERE email='$username'";
$response=$db->query($check_user);
if($response->num_rows !=0)
{
echo "user already exist";
}
else{
echo "user not found";
}
}
?>

3.<html>
<head>
</head>
<body>
<input type="email" id="username" name="email">
<button>Check user</button>
<p></p>
<script>
$(document).ready(function(){
$("button").click(function(){
var username=$("#username").val();
$.ajax({
type:"POST",
url:"result.php",
data:{
email:username
},
success:function(response){
$("p").html(response);
}
});
});
});
</body>
</html>
=>result.php
<?php
$username=$_POST['email'];
$db=new mysqli("localhost","root"."","app");
if($db->connect_error)
{
echo "database not connected";
}
else{
$check_user="SELECT email FROM users WHERE email='$username'";
$response=$db->query($check_user);
if($response->num_rows !=0)
{
echo "user already exist";
}
else{
echo "user not found";
}
}
?>

4.<html>
<head>
</head>
<body>
<input type="email" id="username" name="email">
<button>Check user</button>
<p></p>
<script>
$(document).ready(function(){
$("button").click(function(){
var username=btoa($("#username").val());
$.ajax({
type:"POST",
url:"result.php",
data:{
email:username
},
success:function(response){
$("p").html(response);
}
});
});
});
</body>
</html>
=>result.php
<?php
$username=base64_decode($_POST['email']);
$db=new mysqli("localhost","root"."","app");
if($db->connect_error)
{
echo "database not connected";
}
else{
$check_user="SELECT email FROM users WHERE email='$username'";
$response=$db->query($check_user);
if($response->num_rows !=0)
{
echo "user already exist";
}
else{
echo "user not found";
}
}
?>


CH-8 PHP 7 WITH MYSQL AJAX RESPONSE CONTROLS

1.<html>
<body>
<form>
<fieldset>
<legend>Sign up</legend>
FULL NAME<br>
<input type="text" name="fullname">
<br><br>
EMAIL<br>
<input type="email" name="email" id="email">
<span id="message"></span>
<br><br>
PASSWORD<br>
<input type="password" name="password">
<br><br>
<input type="submit" value="signup now">
<br>
</fieldset>
</form>
<script>
$(document).ready(function(){
$("#email").on("change",function(){
$.ajax({
type:"POST",
url:"check_user.php",
data:{
email:$(this).val()
},
success:function(response)
{
$("#message").html(response);
}
});
});
});
</script>
</body>
</html>
=>check_user.php
<?php
$username=$_POST['email'];
$db=new mysqli("localhost","root"."","wap");
if($db->connect_error)
{
echo "database not connected";
}
else{
$check_user="SELECT email FROM users WHERE email='$username'";
$response=$db->query($check_user);
if($response->num_rows !=0)
{
echo "user already exist";
}
else{
echo "user not found";
}
}
?>

2.<html>
<body>
<form>
<fieldset>
<legend>Sign up</legend>
FULL NAME<br>
<input type="text" name="fullname">
<br><br>
EMAIL<br>
<input type="email" name="email" id="email">
<span id="message"></span>
<br><br>
PASSWORD<br>
<input type="password" name="password">
<br><br>
<input type="submit" value="signup now">
<br>
</fieldset>
</form>
<script>
$(document).ready(function(){
$("#email").on("change",function(){
$.ajax({
type:"POST",
url:"check_user.php",
data:{
email:$(this).val()
},
success:function(response)
{
$("#message").html(response);
}
});
});
});
</script>
</body>
</html>
=>check_user.php
<?php
$username=$_POST['email'];
$db=new mysqli("localhost","root"."","wap");
if($db->connect_error)
{
echo "database not connected";
}
else{
$check_user="SELECT email FROM users WHERE email='$username'";
$response=$db->query($check_user);
if($response->num_rows !=0)
{
echo "<i class='fa fa-times-circle' style='color:red'></i>";
}
else{
echo "<i class='fa fa-check' style='color:blue'></i>";
}
}
?>

3.<html>
<body>
<form>
<fieldset>
<legend>Sign up</legend>
FULL NAME<br>
<input type="text" name="fullname">
<br><br>
EMAIL<br>
<input type="email" name="email" id="email">
<span id="message"></span>
<br><br>
PASSWORD<br>
<input type="password" name="password">
<br><br>
<input type="submit" value="signup now">
<br>
</fieldset>
</form>
<script>
$(document).ready(function(){
$("#email").on("change",function(){
$.ajax({
type:"POST",
url:"check_user.php",
data:{
email:$(this).val()
},
success:function(response)
{
if(response.trim()=="user alredy exists")
{
$(#message).html("<i class='fa fa-times-circle' style='color:red'></i>");
}
else{
$(#message).html("<i class='fa fa-check' style='color:blue'></i>");
}
}
});
});
});
</script>
</body>
</html>
=>check_user.php
<?php
$username=$_POST['email'];
$db=new mysqli("localhost","root"."","wap");
if($db->connect_error)
{
echo "database not connected";
}
else{
$check_user="SELECT email FROM users WHERE email='$username'";
$response=$db->query($check_user);
if($response->num_rows !=0)
{
echo "user already exist";
}
else{
echo "user not found";
}
}
?>

4.<html>
<body>
<form>
<fieldset>
<legend>Sign up</legend>
FULL NAME<br>
<input type="text" id="fullname" required="required" name="fullname">
<br><br>
EMAIL<br>
<input type="email" required="required" name="email" id="email">
<span id="message"></span>
<br><br>
PASSWORD<br>
<input required="required" id="password" type="password" name="password">
<br><br>
<input type="submit" id="submit" value="signup now" disabled="disabled">
<span id="s-message"></span>
<br>
</fieldset>
</form>
<script>
$(document).ready(function(){
$("#email").on("change",function(){
$.ajax({
type:"POST",
url:"register.php",
data:{
email:$(this).val()
},
beforeSend:function(){
$("#message").html("<i class='fa fa-spinner fa-spin'></i>");
},
success:function(response)
{
if(response.trim()=="user alredy exists")
{
$(#message).html("<i class='fa fa-times-circle' style='color:red'></i>");
$("#submit").attr("disabled","disabled");
}
else{
$(#message).html("<i class='fa fa-check' style='color:blue'></i>");
$("#submit").removeAttr("disabled");
}
}
});
});
$("form").submit(function(e){
e.preventDefault();
$.ajax({
type:"POST",
url:"register.php",
data:{
fullname:$("#fullname").val(),
password:$("#password").val(),
email:$("#email").val(),
},
beforeSend:function(){
$("#s-message").html("<i class='fa fa-spinner fa-spin'></i>");
},
success:function(response)
{
$("#s-message").html(response);
}
});
});
});
</script>
</body>
</html>
=>register.php
<?php
$db=new mysqli("localhost","root"."","app");
if($db->connect_error)
{
echo "database not connected";
}
else{
if($_SERVER['REQUEST_METHOD']=="POST")
{
$fullname=$_POST['fullname'];
$email=$_POST['email'];
$password=md5($_POST['password']);
$check_user="SELECT username FROM users WHERE username='$email'";
$response=$db->query($check_user);
if($response->num_rows==0)
{
$store_user="INSERT INTO users(
full_name,username,password)
VALUES('$fullname','$email','$password')
";
if($db->query($store_user))
{
echo "signup success !";
}
else{
echo "signup failed !";
}
}
else{
echo "User already exist";
}
}
}
?>


CH-9 PHP 7 WITH MYSQL FETCH DATA

1.<?php
$data=array("s1"=>"saurav","s1"=>"gautam");
echo $data["s1"];
?>

2.<?php
$db=new mysqli("localhost","root"."","app");
if($db->connect_error)
{
echo "database not connected";
}
else{
$show_data="SELECT * FROM users";
$response=$db->query($show_data);
if($response->num_rows !=0)
{
print_r($response->fetch_assoc());
}
else{
echo "no data found";
}
}
?>

3.<?php
$db=new mysqli("localhost","root"."","app");
if($db->connect_error)
{
echo "database not connected";
}
else{
$show_data="SELECT * FROM users";
$response=$db->query($show_data);
if($response->num_rows !=0)
{
while($data=$response->fetch_assoc())
{
echo $data['id']."<br>";
}
}
else{
echo "no data found";
}
}
?>

4.<?php
$db=new mysqli("localhost","root"."","app");
if($db->connect_error)
{
echo "database not connected";
}
else{
$show_data="SELECT * FROM users WHERE id='2'";
$response=$db->query($show_data);
if($response->num_rows !=0)
{
while($data=$response->fetch_assoc())
{
echo $data['username']."<br>";
}
}
else{
echo "no data found";
}
}
?>

5.<?php
$response;
$db=new mysqli("localhost","root"."","app");
if($db->connect_error)
{
echo "database not connected";
}
else{
$show_data="SELECT * FROM users";
$response=$db->query($show_data);
}
?>
<html>
<body>
<table border="1" width="80%" align="center">
<tr>
<th>id</th>
<th>fullname</th>
<th>username</th>
<th>password</th>
<th>registration date</th>
</tr>
<?php
if($response->num_rows !=0)
{
while($data=$response->fetch_assoc())
{
echo "<tr>
<td>".$data['id']."</td>
<td>".$data['full_name']."</td>
<td>".$data['username']."</td>
<td>".$data['password']."</td>
<td>".$data['reg_date']."</td>
</tr>";
}
}
else{
echo "no data found";
}
?>
</table>
</body>
</html>

6.<head>
<style>
table{
display:none;
}
</style>
</head>
<body>
<input type="nuber" id="user">
<button>display data from server</button>
<table border="1" width="80%" align="center">
<tr>
<th>id</th>
<th>fullname</th>
<th>username</th>
<th>password</th>
<th>date</th>
</tr>
</table>
<p></p>
<script>
$(document).ready(function(){
$("button").click(function(){
var id=$("#user").val();
if(id !="")
{
$.ajax({
type:"POST",
url:"display.php",
data:{
id:id
},
success:function(response){
if(response.trim() !="no data found")
{
$("p").html("");
$("table").css({
display:"block"
});
$("table").append(response);
}
else{
$("p").html(response);
}
}
});
}
});
});
</script>
</body>
=>display.php
<?php
$db=new mysqli("localhost","root"."","app");
if($db->connect_error)
{
echo "database not connected";
}
else{
$id=$_POST['id'];
$show_data="SELECT * FROM users WHERE id='$id'";
$response=$db->query($show_data);
if($response->num_rows !=0)
{
while($data=$response->fetch_assoc())
{
echo "<tr>
<td>".$data['id']."</td>
<td>".$data['full_name']."</td>
<td>".$data['username']."</td>
<td>".$data['password']."</td>
<td>".$data['reg_date']."</td>
</tr>";
}
}
else{
echo "no data found";
}
}
?>


CH-10 PHP 7 WITH MYSQL PICDRIVE PART 1
1.<?php
echo rand(0,12);
?>

2.<?php
$pattern="GA0a!b1|cBdN@efg2hCiH3
`jkD#lP4OmM%n^JVo\Q5pRE_<q=)SIK9rs6&tT*uUF,L-(vZ/7w~Wx+8yX>zY";
echo $pattern[3];
?>

3.<?php
$data[1,2,3];
echo sizeOf($data);
?>

4.<?php
$pattern="GA0a!b1|cBdN@efg2hCiH3
`jkD#lP4OmM%n^JVo\Q5pRE_<q=)SIK9rs6&tT*uUF,L-(vZ/7w~Wx+8yX>zY";
echo strlen($pattern);
?>

5.<?php
$pattern="GA0a!b1|cBdN@efg2hCiH3
`jkD#lP4OmM%n^JVo\Q5pRE_<q=)SIK9rs6&tT*uUF,L-(vZ/7w~Wx+8yX>zY";
$length=strlen($pattern);
$i;
$password=[];
for($i=0;$i<8;$i++)
{
$indexing_number=rand(0,$length);
$password[]=$pattern[$indexing_number];
}
print_r($password);
?>

6.<?php
$pattern="GA0a!b1|cBdN@efg2hCiH3
`jkD#lP4OmM%n^JVo\Q5pRE_<q=)SIK9rs6&tT*uUF,L-(vZ/7w~Wx+8yX>zY";
$length=strlen($pattern);
$i;
$password=[];
for($i=0;$i<8;$i++)
{
$indexing_number=rand(0,$length);
$password[]=$pattern[$indexing_number];
}
echo implode($password);
?>

7.<?php
$pattern="GA0a!b1|cBdN@efg2hCiH3
`jkD#lP4OmM%n^JVo\Q5pRE_<q=)SIK9rs6&tT*uUF,L-(vZ/7w~Wx+8yX>zY";
$length=strlen($pattern)-1;
$i;
$password=[];
for($i=0;$i<8;$i++)
{
$indexing_number=rand(0,$length);
$password[]=$pattern[$indexing_number];
}
echo implode($password);
?>


CH-10 PHP 7 WITH MYSQL PICDRIVE PART 2
1.<?php
mail("ersaurav@gmail.com","testing email","my name is saurav");
?>


CH-10 PHP 7 WITH MYSQL PICDRIVE PART 3
1.<?php
die("welcome to webpage");
echo("hello wap");
?>

2.<?php
echo("hello wap<br>");
die("welcome to webpage");
?>

3.<?php
$db=new mysqli("localhost","root","","picdrive");
if($db->connect_error)
{
die("database not connected");
}
?>


CH-10 PHP 7 WITH MYSQL PICDRIVE PART 5
1.<body>
<form method="post" action="welcome.php">
<button type="submit">submit</button>
</form>
<?php
session_start();
$_SESSION['username']="wap@1234";
?>
</body>
=>welcome.php
<body>
<?php
session_start();
echo $_SESSION['username'];
?>
</body>

2.<body>
<form method="post" action="welcome.php">
<button type="submit">submit</button>
</form>
<?php
session_start();
$_SESSION['username']="wap@1234";
$_SESSION['password']="demo";
?>
</body>
=>welcome.php
<body>
<?php
session_start();
echo $_SESSION['username'];
echo "<br>";
echo $_SESSION['password'];
?>
</body>


CH-10 PHP 7 WITH MYSQL PICDRIVE PART 7
1.<body>
<form method="post" enctype="multipart/form-data" action="upload.php">
<input type="file" name="data" accept="image/*">
<input type="submit">
</form>
</body>
</html>
=>upload.php
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
print_r($_FILES["data"]);
}
?>

2.<body>
<form method="post" enctype="multipart/form-data" action="upload.php">
<input type="file" name="data" accept="image/*">
<input type="submit">
</form>
</body>
</html>
=>upload.php
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$uploaded_file=$_FILES["data"];
echo $uploaded_file["name"];
echo "<br>";
echo $uploaded_file["type"];
echo "<br>";
echo $uploaded_file["tmp_name"];
echo "<br>";
echo $uploaded_file["size"];
echo "<br>";
echo $uploaded_file["error"];
}
?>

3.<body>
<form method="post" enctype="multipart/form-data" action="upload.php">
<input type="file" name="data" accept="image/*">
<input type="submit">
</form>
</body>
</html>
=>upload.php
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$uploaded_file=$_FILES["data"];
$location=$uploaded_file["tmp_name"];
$name=$uploaded_file["name"];
move_uploaded_file($location,"wap/".$name);
}
?>


CH-10 PHP 7 WITH MYSQL PICDRIVE PART 10

1.<body>
<script>
sessionStorage.setItem("name","ravi");
</script>
</body>

2.<body>
<script>
alert(sessionStorage.getItem("name"));
</script>
</body>


CH-10 PHP 7 WITH MYSQL PICDRIVE PART 12
1.SELECT COUNT(id) FROM user_4

2.SELECT COUNT(id) AS total FROM user_4

3.<?php
echo str_replace("../","","../gallery/user_4/demo.jpg");

?>


CH-10 PHP 7 WITH MYSQL PICDRIVE PART 13
1.<?php
$path="images/doc/pic.jpg";
$data=pathinfo($path);
print_r($data);
?>

2.<?php
$path="images/doc/pic.jpg";
$data=pathinfo($path);
echo $data['dirname']."<br>";
echo $data['basename']."<br>";
echo $data['filename']."<br>";
echo $data['extension'];
?>


CH-13 PHP 7 IMAGE PROCESSING PART 1
1.<?php
$db->close();
?>

2.<body>
<?php
$raw_image=imagecreate(500,500);
imagecolorallocate($raw_image,0,36,255);
?>
</body>

3.<body>
<?php
$raw_image=imagecreate(500,500);
imagecolorallocate($raw_image,0,36,255);
if(imagejpeg($raw_image,"images/a.jpg"))
{
echo "success";
}
?>
</body>

4.<body>
<?php
$raw_image=imagecreate(500,500);
imagecolorallocate($raw_image,255,155,105);
$ran=rand(1,500000);
if(imagepng($raw_image,"images/".$ran".png"))
{
echo "success";
}
imagedestroy($raw_image);
?>
</body>

5.<body class="p-5">
<input type="number" id="width" placeholder="width">
<br><br>
<input type="number" id="height" placeholder="height">
<br><br>
<input type="color" id="color">
<br><br>
<select id="format">
<option>jpeg</option>
<option>png</option>
<option>gig</option>
</select>
<button>Generate</button>
<script>
$(document).ready(function(){
$("button").click(function(){
var width=$("#width").val();
var height=$("#height").val();
var color=$("#color").val();
var format=$("#format").val();
alert(color);
});
});
</script>
</body>

6.<body class="p-5">
<input type="number" id="width" placeholder="width">
<br><br>
<input type="number" id="height" placeholder="height">
<br><br>
<input type="color" id="color">
<br><br>
<select id="format">
<option>jpeg</option>
<option>png</option>
<option>gig</option>
</select>
<button>Generate</button>
<script>
$(document).ready(function(){
$("button").click(function(){
var width=$("#width").val();
var height=$("#height").val();
var color=$("#color").val();
var format=$("#format").val();
alert(color[1]);
});
});
</script>
</body>

7.<body class="p-5">
<input type="number" id="width" placeholder="width">
<br><br>
<input type="number" id="height" placeholder="height">
<br><br>
<input type="color" id="color">
<br><br>
<select id="format">
<option>jpeg</option>
<option>png</option>
<option>gig</option>
</select>
<button>Generate</button>
<script>
$(document).ready(function(){
$("button").click(function(){
var width=$("#width").val();
var height=$("#height").val();
var color=$("#color").val();
var format=$("#format").val();
var a=color[1]+color[2];
var b=color[3]+color[4];
var c=color[5]+color[6];
var r=parseInt(a,16);
var g=parseInt(b,16);
var b=parseInt(c,16);
alert(r+","+g+","+b);
});
});
</script>
</body>

8.<body class="p-5">
<input type="number" id="width" placeholder="width">
<br><br>
<input type="number" id="height" placeholder="height">
<br><br>
<input type="color" id="color">
<br><br>
<select id="format">
<option>jpeg</option>
<option>png</option>
<option>gig</option>
</select>
<button>Generate</button>
<script>
$(document).ready(function(){
$("button").click(function(){
var width=$("#width").val();
var height=$("#height").val();
var color=$("#color").val();
var format=$("#format").val();
var a=color[1]+color[2];
var b=color[3]+color[4];
var c=color[5]+color[6];
var r=parseInt(a,16);
var g=parseInt(b,16);
var b=parseInt(c,16);
$.ajax({
type:"POST",
url:"php/image.php",
data:{
width:width,
height:height,
red:r,
green:g,
blue:b,
format:format
},
success:function(response)
{
alert(response);
}
});
});
});
</script>
</body>
=>image.php
<?php
$width=$_POST['width'];
$height=$_POST['height'];
$r=$_POST['red'];
$g=$_POST['green'];
$b=$_POST['blue'];
$format=$_POST['format'];
$raw_image=imagecreate($width,$height);
imagecolorallocate($raw_image,$r,$g,$b);
$ran=rand(1,500000);
if($format=="jpeg")
{
if(imagejpeg($raw_image,"images/".$ran".jpg"))
{
echo "success";
}
imagedestroy($raw_image);
}
else if($format=="png")
{
if(imagepng($raw_image,"images/".$ran".png"))
{
echo "success";
}
imagedestroy($raw_image);
}
else if($format=="gif")
{
if(imagegif($raw_image,"images/".$ran".gif"))
{
echo "success";
}
imagedestroy($raw_image);
}
?>
CH-13 PHP 7 IMAGE PROCESSING PART 2
1.<head>
<style>
*:focus{
box-shadow:none !important;
outline:none !important;
}
</style>
</head>
<body>
<div class="container-fluid p-4 bg-light">
<div class="row main">
<div class="col-md-3">
<form>
<h4>Create custom image</h4>
<hr>
<input type="number" class="form-control mb-4" id="width" placeholder="width" required="required">
<input type="number" class="form-control mb-4" id="height" placeholder="height" required="required">
<input id="color" type="color" class="form-control mb-4">
<select id="format" class="form-control mb-4">
<option>jpeg</option>
<option>png</option>
<option>gif</option>
</select>
<button class="btn btn-primary generate-btn p-2">Generate image</button>
</form>
<br>
</div>
<div class="col-md-9 text-center bg-white shadow-sm overflow-auto">
<div class="result" class="mt-5">
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$(".main").css({
height:$(window).height()-50
});
$(window).resize(function(){
$(".main").css({
height:$(window).height()-50
});
});
$("button").click(function(){
var width=$("#width").val();
var height=$("#height").val();
var color=$("#color").val();
var format=$("#format").val();
var a=color[1]+color[2];
var b=color[3]+color[4];
var c=color[5]+color[6];
var r=parseInt(a,16);
var g=parseInt(b,16);
var b=parseInt(c,16);
$.ajax({
type:"POST",
url:"php/image.php",
data:{
width:width,
height:height,
red:r,
green:g,
blue:b,
format:format
},
success:function(response)
{
$(#"result").html("");
var name=response;
var img=document.createElement("img");
img.src="images/"+name;
img.style.width="80%";
img.style.marginLeft="10%";
img.style.marginRight="10%";
$("#result").append(img);
var a=document.createElement("a");
a.href="images/"+name;
a.download=name;
a.innerHTML="Download now";
a.className="btn btn-danger py-2 my-5";
$("#result").append(a);
}
});
});
});
</script>
</body>
=>image.php
<?php
$width=$_POST['width'];
$height=$_POST['height'];
$r=$_POST['red'];
$g=$_POST['green'];
$b=$_POST['blue'];
$format=$_POST['format'];
$raw_image=imagecreate($width,$height);
imagecolorallocate($raw_image,$r,$g,$b);
$ran=rand(1,500000);
if($format=="jpeg")
{
if(imagejpeg($raw_image,"images/".$ran".jpg"))
{
echo $ran.".jpg";
}
imagedestroy($raw_image);
}
else if($format=="png")
{
if(imagepng($raw_image,"images/".$ran".png"))
{
echo $ran.".png";;
}
imagedestroy($raw_image);
}
if($format=="gif")
{
if(imagegif($raw_image,"images/".$ran".gif"))
{
echo $ran.".gif";;
}
imagedestroy($raw_image);
}
?>

2.<?php
$image_pixels=imagecreatefromjpeg('demo.jpg');
echo "width=".imagesx($image_pixels);
echo "height=".imagesy($image_pixels);
?>

3.<?php
$image_pixels=imagecreatefromjpeg('demo.jpg');
$o_width=imagesx($image_pixels);
$_oheight=imagesy($image_pixels);
$canvas=imagecreatetruecolor(300,300);
imagejpeg($canvas,"test.jpg");
?>

4.<?php
$image_pixels=imagecreatefromjpeg('demo.jpg');
$o_width=imagesx($image_pixels);
$_oheight=imagesy($image_pixels);
$canvas=imagecreatetruecolor(300,300);
imagecopyresampled($canvas,$image_pixels,0,0,0,0,300,300,$o_width,$o_height);
imagejpeg($canvas,"final.jpg");
?>

5.<?php
$image_pixels=imagecreatefromjpeg('demo.jpg');
imagejpeg($image_pixels,"final.jpg",10);
?>

6.<head>
<style>
*:focus{
box-shadow:none !important;
outline:none !important;
}
</style>
</head>
<body>
<div class="container-fluid p-4 bg-light">
<div class="row main">
<div class="col-md-3">
<form>
<h4>Create custom image</h4>
<hr>
<input type="number" class="form-control mb-4" id="width" placeholder="width" required="required">
<input type="number" class="form-control mb-4" id="height" placeholder="height" required="required">
<input id="color" type="color" class="form-control mb-4">
<select id="format" class="form-control mb-4">
<option>jpeg</option>
<option>png</option>
<option>gif</option>
</select>
<button class="btn btn-primary generate-btn p-2">Generate image</button>
</form>
<br><br>
<h4>Resize image</h4>
<hr>
<input type="file" accept="image/*" id="file-input" class="form-control mb-4">
<input type="number" id="r-width" class="form-control mb-4" placeholder="width">
<input type="number" id="r-height" class="form-control mb-4" placeholder="height">
<button class="btn btn-primary py-2 resize-btn">Resize now</button>
</div>
<div class="col-md-9 text-center bg-white shadow-sm overflow-auto">
<div class="result" class="mt-5">
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$(".main").css({
height:$(window).height()-50
});
$(window).resize(function(){
$(".main").css({
height:$(window).height()-50
});
});
$(".generate-btn").click(function(e){
e.preventDefault();
var width=$("#width").val();
var height=$("#height").val();
var color=$("#color").val();
var format=$("#format").val();
var a=color[1]+color[2];
var b=color[3]+color[4];
var c=color[5]+color[6];
var r=parseInt(a,16);
var g=parseInt(b,16);
var b=parseInt(c,16);
$.ajax({
type:"POST",
url:"php/image.php",
data:{
width:width,
height:height,
red:r,
green:g,
blue:b,
format:format
},
success:function(response)
{
$(#"result").html("");
var name=response;
var img=document.createElement("img");
img.src="images/"+name;
img.style.width="80%";
img.style.marginLeft="10%";
img.style.marginRight="10%";
$("#result").append(img);
var a=document.createElement("a");
a.href="images/"+name;
a.download=name;
a.innerHTML="Download now";
a.className="btn btn-danger py-2 my-5";
$("#result").append(a);
}
});
});
});
//upload file
$(document).ready(function(){
$("#file-input").on("change",function(){
var file=this.files[0];
var url=URL.createObjectURL(file);
var image=document.createElement("img");
image.src=url;
$("#result").html(image);
image.onload=function(){
var o_width=image.width;
var o_height=image.height;
$("#r-width").on("input",function(){
var typed_width=Number(this.value);
var ratio=typed_width/o_width;
var rec_height=o_height*ratio;
$("#r-height").val(rec_height);
image.width=typed_width;
image.height=rec_height;
});
$("#r-height").on("input",function(){
var typed_height=this.value;
image.height=typed_height;
});
}
});
});
</script>
</body>
=>image.php
<?php
$width=$_POST['width'];
$height=$_POST['height'];
$r=$_POST['red'];
$g=$_POST['green'];
$b=$_POST['blue'];
$format=$_POST['format'];
$raw_image=imagecreate($width,$height);
imagecolorallocate($raw_image,$r,$g,$b);
$ran=rand(1,500000);
if($format=="jpeg")
{
if(imagejpeg($raw_image,"images/".$ran".jpg"))
{
echo $ran.".jpg";
}
imagedestroy($raw_image);
}
else if($format=="png")
{
if(imagepng($raw_image,"images/".$ran".png"))
{
echo $ran.".png";;
}
imagedestroy($raw_image);
}
if($format=="gif")
{
if(imagegif($raw_image,"images/".$ran".gif"))
{
echo $ran.".gif";;
}
imagedestroy($raw_image);
}
?>


CH-13 PHP 7 IMAGE PROCESSING PART 3
1.<head>
<style>
*:focus{
box-shadow:none !important;
outline:none !important;
}
</style>
</head>
<body>
<div class="container-fluid p-4 bg-light">
<div class="row main">
<div class="col-md-3">
<form>
<h4>Create custom image</h4>
<hr>
<input type="number" class="form-control mb-4" id="width" placeholder="width" required="required">
<input type="number" class="form-control mb-4" id="height" placeholder="height" required="required">
<input id="color" type="color" class="form-control mb-4">
<select id="format" class="form-control mb-4">
<option>jpeg</option>
<option>png</option>
<option>gif</option>
</select>
<button class="btn btn-primary generate-btn p-2">Generate image</button>
</form>
<br><br>
<h4>Resize image</h4>
<hr>
<form id="resize-form">
<input type="file" accept="image/*" name="file-input" id="file-input" class="form-control mb-4">
<input type="number" id="r-width" name="r-width" class="form-control mb-4" placeholder="width">
<input type="number" id="r-height" name="r-height" class="form-control mb-4" placeholder="height">
<button class="btn btn-primary py-2 resize-btn">Resize now</button>
</form>
</div>
<div class="col-md-9 text-center bg-white shadow-sm overflow-auto">
<div class="result" class="mt-5">
</div>
</div>
</div>
</div>
</body> <script>
$(document).ready(function(){
$(".main").css({
height:$(window).height()-50
});
$(window).resize(function(){
$(".main").css({
height:$(window).height()-50
});
});
$(".generate-btn").click(function(e){
e.preventDefault();
var width=$("#width").val();
var height=$("#height").val();
var color=$("#color").val();
var format=$("#format").val();
var a=color[1]+color[2];
var b=color[3]+color[4];
var c=color[5]+color[6];
var r=parseInt(a,16);
var g=parseInt(b,16);
var b=parseInt(c,16);
$.ajax({
type:"POST",
url:"php/image.php",
data:{
width:width,
height:height,
red:r,
green:g,
blue:b,
format:format
},
success:function(response)
{
$(#"result").html("");
var name=response.trim();
var img=document.createElement("img");
img.src="images/"+name;
img.style.width="80%";
img.style.marginLeft="10%";
img.style.marginRight="10%";
$("#result").append(img);
var a=document.createElement("a");
a.href="images/"+name;
a.download=name;
a.innerHTML="Download now";
a.className="btn btn-danger py-2 my-5";
$("#result").append(a);
}
});
});
});
//upload file
$(document).ready(function(){
$("#file-input").on("change",function(){
var file=this.files[0];
var url=URL.createObjectURL(file);
var image=document.createElement("img");
image.src=url;
$("#result").html(image);
image.onload=function(){
var o_width=image.width;
var o_height=image.height;
$("#r-width").on("input",function(){
var typed_width=Number(this.value);
var ratio=typed_width/o_width;
var rec_height=Math.floor(o_height*ratio);
$("#r-height").val(rec_height);
image.width=typed_width;
image.height=rec_height;
});
$("#r-height").on("input",function(){
var typed_height=this.value;
image.height=typed_height;
});
}
$("#resize-form").submit(function(e){
e.preventDefault();
var c_width=$("#r-width").val();
var c_height=$("#r-height").val();
$.ajax({
type:"POST",
url:"php/resize.php",
data:new FormData(this),
processData:false,
contentType:false,
cache:false,
success:function(response)
{
var link="images/"+response.trim();
var a=document.createElement("A");
a.href=link;
a.download=response.trim();
a.innerHTML="Download now";
a.className="btn btn-danger py-2 my-2";
$("#result").append(a);
}
});
});
});
});
</script>
</body>
=>image.php
<?php
$width=$_POST['width'];
$height=$_POST['height'];
$r=$_POST['red'];
$g=$_POST['green'];
$b=$_POST['blue'];
$format=$_POST['format'];
$raw_image=imagecreate($width,$height);
imagecolorallocate($raw_image,$r,$g,$b);
$ran=rand(1,500000);
if($format=="jpeg")
{
if(imagejpeg($raw_image,"images/".$ran".jpg"))
{
echo $ran.".jpg";
}
imagedestroy($raw_image);
}
else if($format=="png")
{
if(imagepng($raw_image,"images/".$ran".png"))
{
echo $ran.".png";;
}
imagedestroy($raw_image);
}
if($format=="gif")
{
if(imagegif($raw_image,"images/".$ran".gif"))
{
echo $ran.".gif";;
}
imagedestroy($raw_image);
}
?>
=>resize.php
<?php
$width=$_POST['r-width'];
$height=$_POST['r-height'];
$file=$_FILES['file-input'];
$uploaded_image=$file['tmp_name'];
$type=$file['type'];
$ran=rand(1,25298518);
if($type=="image/jpeg")
{
$image_pexels=imagecreatefromjpeg($uploaded_image);
$o_width=imagesx($image_pexels);
$o_height=imagesy($image_pexels);
$canvas=imagecreatetruecolor($width,$height);
imagecopyresampled($canvas,$image_pexels,0,0,0,0,$width,$height,$o_width,$o_height);
if(imagejpeg($canvas,"../images/".$ran.".jpg"))
{
echo $ran.".jpg";
}
imagedestroy($image_pexels);
}
if($type=="image/png")
{
$image_pexels=imagecreatefrompng($uploaded_image);
$o_width=imagesx($image_pexels);
$o_height=imagesy($image_pexels);
$canvas=imagecreatetruecolor($width,$height);
imagecopyresampled($canvas,$image_pexels,0,0,0,0,$width,$height,$o_width,$o_height);
if(imagepng($canvas,"../images/".$ran.".png"))
{
echo $ran.".png";
}
imagedestroy($image_pexels);
}
if($type=="image/gif")
{
$image_pexels=imagecreatefromgif($uploaded_image);
$o_width=imagesx($image_pexels);
$o_height=imagesy($image_pexels);
$canvas=imagecreatetruecolor($width,$height);
imagecopyresampled($canvas,$image_pexels,0,0,0,0,$width,$height,$o_width,$o_height);
if(imagegif($canvas,"../images/".$ran.".gif"))
{
echo $ran.".gif";
}
imagedestroy($image_pexels);
}
if($type=="image/bmp")
{
$image_pexels=imagecreatefrombmp($uploaded_image);
$o_width=imagesx($image_pexels);
$o_height=imagesy($image_pexels);
$canvas=imagecreatetruecolor($width,$height);
imagecopyresampled($canvas,$image_pexels,0,0,0,0,$width,$height,$o_width,$o_height);
if(imagebmp($canvas,"../images/".$ran.".bmp"))
{
echo $ran.".bmp";
}
imagedestroy($image_pexels);
}
if($type=="image/webp")
{
$image_pexels=imagecreatefromwebp($uploaded_image);
$o_width=imagesx($image_pexels);
$o_height=imagesy($image_pexels);
$canvas=imagecreatetruecolor($width,$height);
imagecopyresampled($canvas,$image_pexels,0,0,0,0,$width,$height,$o_width,$o_height);
if(imagewebp($canvas,"../images/".$ran.".webp"))
{
echo $ran.".webp";
}
imagedestroy($image_pexels);
}
?>


CH-13 PHP 7 IMAGE PROCESSING PART 6

1.<body>
<form id="login-form">
username
<br>
<input type="text" name="data-1" id="username">
<br><br>
password
<br>
<input type="password" name="data-2" id="password">
<br><br>
<input type="file" name="file-input">
<button type="submit">submit</button>
</form>
<script>
$(document).ready(function(){
$("#login-form").submit(function(e){
e.preventDefault();
$.ajax({
type:"POST",
url:"result.php",
data:new FormData(this),
processData:false,
contentType:false,
cache:false,
success:function(response)
{
alert(response);
}
});
});
});
</script>
</body>
=>result.php
<?php
echo $_POST['data-1'];
echo $_POST['data-2'];
print_r($_FILES['file-input']);
?>

2.<body>
<input type="text" id="user">
<button>check</button>
<script>
$(document).ready(function(){
$("button").click(function(e){
e.preventDefault();
var formdata=new FormData();
formdata.append("data",$("#user").val());
$.ajax({
type:"POST",
url:"result.php",
data:formdata,
processData:false,
contentType:false,
cache:false,
success:function(response)
{
alert(response);
}
});
});
});
</script>
</body>
=>result.php
<?php
echo $_POST['data'];
?>

3.<body>
<form method="post" action="result.php">
<input type="text" name="name">
<input type="email" name="email">
<input type="text" name="message">
<button type="submit">submit</button>
</form>
</body>
=>result.php
<?php
$name="name : ".$_POST['name'];
$email="email : ".$_POST['email'];
$message="message : ".$_POST['message'];
if(mail("wap@gmail.com","message from website",$name." \n".$email." \n".$message,"From:".$email))
{
echo "Thank you we will contact you shortly";
}
else{
echo "Please try again letter";
}
?>

4.<?php
print_r(scandir("images"));
?>

5.<?php
$all_files_name=scandir("images");
unset($all_files_name[0]);
unset($all_files_name[1]);
print_r($all_files_name);
?>

6.<?php
$all_files_name=scandir("images");
unset($all_files_name[0]);
unset($all_files_name[1]);
$indexing_number=rand(2,12);
$image_name=$all_files_name[$indexing_number];
?>
<body style="background-image:url(images/<?php echo $image_name;?>)">
</body>

CH-14 PHP 7 CUSTOM EMAIL AND FPDF API

1.<?php
$x=imagecreatefromjpeg("demo.jpg");
imagejpeg($x);
header("Content-Type:images/jpeg");
?>

2.<?php
mail("wap@gmail.com","testing","<h1>welcome</h1>");
?>

3.<?php
$header_information="From:wapinstitute@gmail.com \r\nMIME-Version:1.0 \r\nContent-Type:text/html;charset=ISO-8859-1 \r\n";
$message="<html>
<body style='background-color:red;padding:50px'>
<h1 style='color:white;text-align:center'>Thank you for purchasing our product</h1>
</body>
</html>";
mail("wap@gmail.com","testing",$message,$header_information);
?>

4.<?php
require("fpdf.php");
$x=new FPDF();
$x->AddPage();
$x->SetFont("Arial","B",14);
$x->Cell(190,10,"welcome to wap institute",1,1,'C');
$x->Cell(80,5,"hello wap",1,0,'R');
$x->output();
?>

5.<?php
require("fpdf.php");
$x=new FPDF();
$x->AddPage();
$x->SetFont("Arial","B",14);
$x->Cell(190,10,"welcome to wap institute",1,1,'C');
$x->Cell(80,5,"hello wap",1,0,'R');
$x->output("sample.pdf","F");
?>


CH-15 PHP 7 FPDF CUSTOMIZATION

1.<?php
require("fpdf.php");
$x=new FPDF();
$x->AddPage();
$x->SetFont("Arial","",10);
$x->Image('logo.png',95,10,22,20);
$x->Cell(190,10,"",0,1);
$x->Cell(190,10,"",0,1);
$x->Cell(190,2,"",0,1);
$x->SetFillColor(255,0,0);
$x->SetTextColor(255,255,255);
$x->Cell(190,5,"A test table with merged cell",0,1,"C",'TRUE');
$x->SetFillColor(0,0,255);
$x->SetTextColor(255,0,0);
$x->SetFont("Arial","B",10);
$x->Cell(20,10,"",1,0);
$x->Cell(150,5,"Average",1,0,"C");
$x->Cell(20,10,"Red eyes",1,0);
$x->Cell(0,5,"",0,1);
$x->Cell(20,5,"",0,0);
$x->Cell(75,5,"height",1,0,"C");
$x->Cell(75,5,"width",1,0,"C");
$x->Cell(20,5,"",0,1);
$x->Cell(47.5,5,"Males",1,0,"C",'TRUE');
$x->SetFont("Arial","",10);
$x->Cell(47.5,5,"1.9",1,0,"C");
$x->Cell(47.5,5,"0.03",1,0,"C");
$x->Cell(47.5,5,"48%",1,1,"C");
$x->SetFont("Arial","B",10);
$x->ln();
$x->ln();
$x->ln();
$x->Cell(47.5,5,"Female",1,0,"C");
$x->SetFont("Arial","",10);
$x->Cell(47.5,5,"1.9",1,0,"C");
$x->Cell(47.5,5,"0.03",1,0,"C");
$x->Cell(47.5,5,"48%",1,1,"C");
$x->AddPage();
$x->SetFont('Arial','B',14);
$x->Cell(190,10,"welcom to second page",1,0);
$x->AddPage();
$x->SetFont('Arial','B',14);
$x->Cell(190,10,"welcom to third page",1,0);
$x->output("welcom.pdf","F");
?>


CH-16 PHP 7 DOMPDF AND ZIP
1.<?php
require("dempdf/autoload.inc.php");
use Dompdf\Dompdf;
$x=new Dompdf();
$design="<html>
<body>
<table width='100%' height='50' style='border:2px groove red'>
<tr>
<td>username</td>
<td>password</td>
<td>email</td>
</tr>
</table>
</body>
</html>";
$x->loadHtml($design);
$x->setPaper("A4","potrait");
$x->rander();
$x->stream();
?>

2.<?php
require("dempdf/autoload.inc.php");
use Dompdf\Dompdf;
$x=new Dompdf();
$design="<html>
<body>
<table width='100%' height='50' style='border:2px groove red'>
<tr>
<td>username</td>
<td>password</td>
<td>email</td>
</tr>
</table>
</body>
</html>";
$x->loadHtml($design);
$x->setPaper("A4","potrait");
$x->rander();
$temp_pdf=$x->output();
file_put_contents("demo.pdf",$temp_pdf);
?>

3.<?php
$db=new mysqli("localhost","roor","","final");
if($db->connect_error)
{
echo "connection failed";
}
else{
$get_data="SELECT * FROM admission LIMIT 20";
$response=$db->query($get_data);
echo "<table width='500' border='2'>";
while($data=$response->fetch_assoc())
{
echo "<tr>";
echo "<td>";
echo $data['email'];
echo "</td>";
echo "<td>";
echo $data['mobile'];
echo "</td>";
echo "</tr>";
}
echo "</table>";
}
?>

4.<?php
header("Content-Type:application/xls");
header("Content-Disposition:attachment;filename=sample.xls");
$db=new mysqli("localhost","roor","","final");
if($db->connect_error)
{
echo "connection failed";
}
else{
$get_data="SELECT * FROM admission LIMIT 20";
$response=$db->query($get_data);
echo "<table width='500' border='2'>";
while($data=$response->fetch_assoc())
{
echo "<tr>";
echo "<td>";
echo $data['email'];
echo "</td>";
echo "<td>";
echo $data['mobile'];
echo "</td>";
echo "</tr>";
}
echo "</table>";
}
?>

5.<?php
header("Content-Type:text/html");
header("Content-Disposition:attachment;filename=sample.html");
$db=new mysqli("localhost","roor","","final");
if($db->connect_error)
{
echo "connection failed";
}
else{
$get_data="SELECT * FROM admission LIMIT 20";
$response=$db->query($get_data);
echo "<table width='500' border='2'>";
while($data=$response->fetch_assoc())
{
echo "<tr>";
echo "<td>";
echo $data['email'];
echo "</td>";
echo "<td>";
echo $data['mobile'];
echo "</td>";
echo "</tr>";
}
echo "</table>";
}
?>

6.<?php
header("Content-Type:text/plain");
header("Content-Disposition:attachment;filename=sample.txt");
$db=new mysqli("localhost","roor","","final");
if($db->connect_error)
{
echo "connection failed";
}
else{
$get_data="SELECT * FROM admission LIMIT 20";
$response=$db->query($get_data);
echo "<table width='500' border='2'>";
while($data=$response->fetch_assoc())
{
echo "<tr>";
echo "<td>";
echo $data['email'];
echo "</td>";
echo "<td>";
echo $data['mobile'];
echo "</td>";
echo "</tr>";
}
echo "</table>";
}
?>

7.<?php
header("Content-Type:application/zip");
header("Content-Disposition:attachment;filename=test.zip");
readfile("test.zip");
$zip_obj=new ZipArchive();
$zip_obj->open("test.zip",ZipArchive::CREATE);
$zip_obj->addFile("demo.pdf");
$zip_obj->close();
?>

8.<?php
$zip_obj=new ZipArchive();
$zip_obj->open("test.zip",ZipArchive::CREATE);
$zip_obj->addFile("demo.pdf");
$zip_obj->close();
?>

9.<?php
$files=['demo.pdf','result.pdf'];
$length=count($files);
$zip_obj=new ZipArchive();
$zip_obj->open("test.zip",ZipArchive::CREATE);
for($i=0;$i<$length;$i++)
{
$zip_obj->addFile($files[$i]);
}
$zip_obj->close();
?>


CH-17 PHP 7 ZIP EXTRACTOR APP
1.<?php
$x=new ZipArchive();
$temp_zip=$x->open("test.zip");
if($temp_zip==true)
{
$result=$x->extractTo("result");
if($result)
{
echo "success";
$x->close();
}
else{
echo "unable to extract zip file";
}
}
else{
echo "unable to open zip file";
}
?>

2.<body>
<form method="post" enctype="multipart/form-data" action="test.php">
<input type="file" name="upload-file" accept=".zip">
<input type="submit">
</form>
</body>
<?php
if($_SERVER['REQUEST_METHOD']=="POST")
{
$file=$_FILES['upload-file'];
print_r($file);
}
?>

3.<body>
<form method="post" enctype="multipart/form-data" action="test.php">
<input type="file" name="upload-file" accept=".zip">
<input type="submit">
</form>
</body>
<?php
if($_SERVER['REQUEST_METHOD']=="POST")
{
$file=$_FILES['upload-file'];
$location=$file['tmp_name'];
$file_name=rand(1,841888);
$x=new ZipArchive();
$temp=$x->open($location);
if($temp)
{
$result=$x->extractTo("user_file/".$file_name");
if($result)
{
echo "success";
}
else{
echo "unable to extract zip file";
}
}
else{
echo "unable to open zip file";
}
}
?>

4.<body>
<form method="post" enctype="multipart/form-data" action="test.php">
<input type="file" name="upload-file" accept=".zip">
<input type="submit">
</form>
</body>
<?php
if($_SERVER['REQUEST_METHOD']=="POST")
{
$file=$_FILES['upload-file'];
$location=$file['tmp_name'];
$file_name=rand(1,841888);
$x=new ZipArchive();
$temp=$x->open($location);
if($temp)
{
$result=$x->extractTo("user_file/".$file_name");
if($result)
{
echo "success";
$close_success=$x->close();
if($close_success")
{
print_r(scandir("user_file/".$file_name));
}
}
else{
echo "unable to extract zip file";
}
}
else{
echo "unable to open zip file";
}
}
?>

5.<body>
<form method="post" enctype="multipart/form-data" action="test.php">
<input type="file" name="upload-file" accept=".zip">
<input type="submit">
</form>
</body>
<?php
if($_SERVER['REQUEST_METHOD']=="POST")
{
$file=$_FILES['upload-file'];
$location=$file['tmp_name'];
$file_name=rand(1,841888);
$x=new ZipArchive();
$temp=$x->open($location);
if($temp)
{
$result=$x->extractTo("user_file/".$file_name");
if($result)
{
$close_success=$x->close();
if($close_success")
{
$array=scandir("user_file/".$file_name);
$length=count($array);
for($i=2;$i<$length;$i++)
{
$link="user_file/".$file_name."/".$array[$i];
echo $link."<br>";
echo $array[$i]."<br>";
}
}
}
else{
echo "unable to extract zip file";
}
}
else{
echo "unable to open zip file";
}
}
?>

6.<body>
<form method="post" enctype="multipart/form-data" action="test.php">
<input type="file" name="upload-file" accept=".zip">
<input type="submit">
</form>
</body>
<?php
if($_SERVER['REQUEST_METHOD']=="POST")
{
$file=$_FILES['upload-file'];
$location=$file['tmp_name'];
$file_name=rand(1,841888);
$x=new ZipArchive();
$temp=$x->open($location);
if($temp)
{
$result=$x->extractTo("user_file/".$file_name");
if($result)
{
$close_success=$x->close();
if($close_success")
{
$array=scandir("user_file/".$file_name);
$length=count($array);
for($i=2;$i<$length;$i++)
{
$link="user_file/".$file_name."/".$array[$i];
echo "<a href='".$link."' download='".$array[$i]."'>".$array[$i]."</a><br>";
}
}
}
else{
echo "unable to extract zip file";
}
}
else{
echo "unable to open zip file";
}
}
?>


CH-18 PHP 7 JSON,FOREACH,INCLUDE_ONCE,REQUIRE_ONCE
1.<?php
$json='{
"name":"saurav",
"class":10
}';
$x=json_decode($json);
echo $x->name;
?>

2.<?php
$json=array("name"=>"saurav");
echo $json['name'];
?>

3.<?php
$json=array("name"=>"saurav");
echo json_encode($json);
?>

4.<?php
$json=array("name"=>"saurav","class"=>10,"roll"=>12);
print_r(array_keys($json));
?>

5.<?php
$json=array("name"=>"saurav","class"=>10,"roll"=>12);
$length=count($json);
$keys_name=array_keys($json);
for($i=0;$i<$length;$i++)
{
echo $keys_name[$i]."<br>";
}
?>

6.<?php
$json=array("name"=>"saurav","class"=>10,"roll"=>12);
$length=count($json);
$keys_name=array_keys($json);
for($i=0;$i<$length;$i++)
{
$assoc_key=$keys_name[$i];
echo $json[$assoc_key]."<br>";
}
?>

7.<?php
$x=["saurav","gautam"];
foreach($x as $y)
{
echo $y."<br>";
}
?>

8.<?php
$x=array("name"=>"saurav","class"=>10);
foreach($x as $key_name=>$data)
{
echo $key_name."<br>";
}
?>

9.<?php
$x=array("name"=>"saurav","class"=>10);
foreach($x as $key_name=>$data)
{
echo $data."<br>";
}
?>

10.<?php
readfile("test.txt");

?>

11.<?php
readfile("demo.mp4");
?>

12.<?php
header("Content-Type:video/mp4");
readfile("demo.mp4");
?>

13.<?php
header("Content-Type:audio/mpeg");
readfile("demo.mp3");
?>

14.<?php
header("Content-Type:image/jpeg");
readfile("demo.jpg");
?>

15.<?php
header("Content-Type:application/pdf");
readfile("demo.pdf");
?>

16.<?php
require("demo.php");
?>
=>demo.php
<?php
echo "testing";
?>

17.<?php
require("demo.php");
require("demo.php");
require("demo.php");
require("demo.php");
?>
=>demo.php
<?php
echo "testing";
?>

18.<?php
include("demo.php");
include("demo.php");
include("demo.php");
include("demo.php");
?>
=>demo.php
<?php
echo "testing";
?>

19.<?php
include_once("demo.php");
?>
=>demo.php
<?php
echo "testing";
?>

20.<?php
require_once("demo.php");
?>
=>demo.php
<?php
echo "testing";
?>


CH-19 PHP 7 ECOMMERCE PROJECT PART 20
1.<body>
<div class="container">
</div>
<form>
<input type="number" name="mobile">
<textarea name="message"></textarea>
<button type="submit">send</button>
</form>
<script>
$(document).ready(function(){
$("form").submit(function(e){
e.preventDefault();
$.ajax({
type:"POST",
url:"sendsms.php",
data:new FormData(this),
processData:false,
contentType:false,
success:function(response)
{
alert(response);
}
});
});
});
</script>
</body>
=>sendsms.php
<?php
require('textlocal.class.php');
$mobile=$_POST['mobile'];
$message=$_POST['message'];
$textlocal = new Textlocal('false', 'false','6lMknj8DNss-yspUbR6iVgztorkpUMGDSrP75FxEjR');
$numbers = array($mobile);
$sender = 'TXTLCL';
$message = $message;
try {
    $result = $textlocal->sendSms($numbers, $message, $sender);
    echo "success";
} catch (Exception $e) {
    die('Error: ' . $e->getMessage());
}
?>


CH-21 PHP 7 APACHE CONFIG PART 1
1.RewriteEngine On
RewriteRule ^welcome$ https://wapinstitute.com

2.RewriteEngine On
RewriteRule ^welcome/wap$ https://wapinstitute.com

3.RewriteEngine On
RewriteRule ^([0-9])$ https://wapinstitute.com

4.RewriteEngine On
RewriteRule ^welcome/([0-9])$ https://wapinstitute.com

5.RewriteEngine On
RewriteRule ^welcome/([0-9a-zA-Z]+)$ https://wapinstitute.com

6.RewriteEngine On
RewriteRule ^emp$ employee_panel/index.php

7.RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ https://wapinstitute.com

8.RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ https://wapinstitute.com

9.RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ https://wapinstitute.com

10.RewriteEngine On
RewriteRule ^([0-9a-zA-Z]+)/([0-9a-zA-Z]+)$ https://wapinstitute.com?amount=$1$status=$2

11.RewriteEngine On
RewriteRule ^([0-9a-zA-Z]+)$ https://wapinstitute.com?amount=$1

12.RewriteEngine On
RewriteRule ^([0-9a-zA-Z]+)$ pages/php/products.php?cat_name=$1

13.RewriteEngine On
RewriteRule ^products/([0-9a-zA-Z]+)$ pages/php/products.php?cat_name=$1

14.RewriteEngine On
RewriteRule ^products/([0-9a-zA-Z]+)$ pages/php/products.php?cat_name=$1
RewriteRule ^([a-z])$ https://wapinstitute.com

15.RewriteEngine On
RewriteRule ^products/([0-9a-zA-Z]+)$ pages/php/products.php?cat_name=$1
RewriteRule ^([a-z]+)$ $1.php

16.RewriteEngine On
RewriteRule ^products/([0-9a-zA-Z]+)$ pages/php/products.php?cat_name=$1
RewriteRule ^([a-z]+)$ $1.php
ErrorDocument 404 http://localhost/shopwap/404.php

17.RewriteEngine On
RewriteRule ^products/([0-9a-zA-Z]+)$ pages/php/products.php?cat_name=$1
RewriteRule ^([a-zA-Z0-9]+)$ $1.php
ErrorDocument 404 http://localhost/shopwap/404.php


ch-22 php 7 date and time queries part 1
1.<?php
$date=date_create('10-12-2015');
$result=$date->format('d-m-y');
echo $result;
?>

2.<?php
$date=date_create('10-12-2015');
$result=$date->format('d-m-y');
echo $date->format('d');
?>

3.<?php
$date=date_create('10-12-2015');
$result=$date->format('d-m-Y');
echo $date->format('y');
?>

4.<?php
$date=date_create('10-12-2015');
$result=$date->format('d-m-Y');
echo $date->format('Y');
?>

5.<?php
date_default_timezone_set("Asia/Calcutta");
$date=date_create('01-10-2015');
$date->format('d-m-y');
echo $date->format('l'); 
?>

6.<?php
date_default_timezone_set("Asia/Calcutta");
$date=date_create('01-10-2015');
$date->format('d-m-y');
echo $date->format('D'); 
?>

7.<?php
date_default_timezone_set("Asia/Calcutta");
$date=date_create('01-10-2015');
echo $date->format('D-m-y');
?>

8.<?php
date_default_timezone_set("Asia/Calcutta");
$date=date_create('01-10-2015');
echo $date->format('l-m-y');
?>

9.<?php
date_default_timezone_set("Asia/Calcutta");
$first=date_create('01-10-2015');
$second=date_create('01-10-2020');
$result=$first->diff($second);
echo $result->format('%y');
?>

10.<?php
date_default_timezone_set("Asia/Calcutta");
$first=date_create('01-10-2020');
$second=date_create('01-12-2020');
$result=$first->diff($second);
echo $result->format('%m');
?>

11.<?php
date_default_timezone_set("Asia/Calcutta");
$first=date_create('01-10-2020');
$second=date_create('01-12-2021');
$result=$first->diff($second);
echo $result->format('%y')*12+$result->format('%m');
?>

12.<?php
date_default_timezone_set("Asia/Calcutta");
$first=date_create('01-10-2020');
$second=date_create('01-10-2021');
$result=$first->diff($second);
echo $result->format('%a');
?>

13.<?php
date_default_timezone_set("Asia/Calcutta");
$date=date_create('01-10-2015');
echo $date->format('d-M-Y');
?>

14.<?php
date_default_timezone_set("Asia/Calcutta");
$date=date_create('01-10-2015');
echo $date->format('d-F-Y');
?>

15.<?php
date_default_timezone_set("Asia/Calcutta");
for($i=1;$i<=12;$i++)
{
$date=date_create('01-'.$i.'-2015');
echo $date->format('m-F-Y')."<br>";
}
?>

16.<?php
date_default_timezone_set("Asia/Calcutta");
for($i=1;$i<=12;$i++)
{
$date=date_create('01-'.$i.'-2015');
echo $date->format('F')."<br>";
}
?>

17.<?php
date_default_timezone_set("Asia/Calcutta");
echo cal_days_in_month(CAL_GREGORIAN,4,2020);
?>

18.<?php
date_default_timezone_set("Asia/Calcutta");
$count=0;
for($i=1;$i<=12;$i++)
{
$count+=cal_days_in_month(CAL_GREGORIAN,$i,2020);
}
echo $count;
?>
=>
1. CURRENT DATE
 date(‘d-m-Y’) : 12-10-2020
 date(‘d-m-y’) : 12-10-20

2. TIME
 date(‘h:i:s’) : 8:10:15
 date(‘H:i:s’) : 20:10:15
 date(‘h:i:s A’) : 8:10:15 PM

3. CHANGE TIMEZONE
 date_default_timezone_set("Asia/Calcutta");

4. CUSTOM DATE
 $date = date_create(’12-10-2015’);
$result = $date->format(‘d-m-Y’);

5. GET DAY FROM CUSTOM DATE
 $date = date_create(’12-10-2015’);
$result = $date->format(‘d-m-Y’);
$get_date = $date->format(‘d’);
echo $get_date;

6. GET MONTH FROM CUSTOM DATE
 $date = date_create(’12-10-2015’);
$result = $date->format(‘d-m-Y’);
$get_month = $date->format(‘m’);
echo $get_month;

7. GET YEAR FROM CUSTOM DATE
 $date = date_create(’12-10-2015’);
$result = $date->format(‘d-m-Y’);
$get_year $date->format(‘Y’);
echo $get_year

8. GET DAY NAME FROM CUSTOM DATE EXAMPLE : Sun, Mon
 $date = date_create(’12-10-2015’);
$result = $date->format(‘d-m-Y’);
$get_name $date->format(‘D’);
echo $get_name

9. GET DAY NAME FROM CUSTOM DATE EXAMPLE : Sunday, Monday
 $date = date_create(’12-10-2015’);
$result = $date->format(‘d-m-Y’);
$get_name $date->format(‘l’);
echo $get_name

10. GET DIFFERENCES BETWEEN YEAR
 $first = date_create(’12-10-2015’);
$second = date_create(’12-10-2016’);
$result = $first->diff($second);
echo $result->format(‘%y’);

11. GET DIFFERENCES BETWEEN MONTH NOT IN ROUND FIGURE
 $first = date_create(’12-10-2015’);
$second = date_create(’12-12-2016’);
$result = $first->diff($second);
echo $result->format(‘%m’);

12. GET DIFFERENCES BETWEEN MONTH IN ROUND FIGURE
 $first = date_create(’12-10-2015’);
$second = date_create(’12-12-2016’);
$result = $first->diff($second);
echo $result->format(‘%y’)*12+$result->format(‘%m’);

13. GET DIFFERENCES BETWEEN DAYS IN ROUND FIGURE
 $first = date_create(’12-10-2015’);
$second = date_create(’12-12-2016’);
$result = $first->diff($second);
echo $result->format(‘%a’);

14. GET SHORT NAME OF MONTH
 $result = date_create(’12-10-2015’);
echo $result->format(‘M’);

15. GET FULLNAME OF MONTH
 $result = date_create(’12-10-2015’);
echo $result->format(‘F’);

16. GET ALL MONTH NAME
for($i=1;$i<=12;$i++)
{
$result = date_create(’12-‘.$i.’-2015’);
echo $result->format(‘F’).’<br>’;
}

17. GET HOW MANY DAYS IN A MONTH ?
 cal_days_in_month(CAL_GREGORIAN,4,2020);

18. GET HOW MANY DAYS IN A YEAR ?
$count = 0;
for($i=1;$i<=12;$i++)
{
$count += cal_days_in_month(CAL_GREGORIAN,$i,2020);
}
echo $count;


ch-22 php 7 date and time queries part 2
1.<?php
date_default_timezone_set("Asia/Calcutta");
$date=date_create('31-12-2020');
$result=date_add($date,date_interval_create_from_date_string("1 days"));
echo $result->format('d-m-Y');
?>

2.<?php
date_default_timezone_set("Asia/Calcutta");
$date=date_create('31-12-2020');
$result=date_add($date,date_interval_create_from_date_string("1 months"));
echo $result->format('d-m-Y');
?>

3.<?php
date_default_timezone_set("Asia/Calcutta");
$date=date_create('31-12-2020');
$result=date_add($date,date_interval_create_from_date_string("1 years"));
echo $result->format('d-m-Y');
?>

4.<?php
date_default_timezone_set("Asia/Calcutta");
echo strtotime("now");
?>

5.<?php
date_default_timezone_set("Asia/Calcutta");
$time= strtotime("now");
echo date("d-m-Y h:i",$time)
?>

6.<?php
date_default_timezone_set("Asia/Calcutta");
$time= strtotime("+1 week");
echo date("d-m-Y h:i",$time)
?>

7.<?php
date_default_timezone_set("Asia/Calcutta");
$time= strtotime("+1 hour");
echo date("d-m-Y h:i",$time)
?>

8.<?php
date_default_timezone_set("Asia/Calcutta");
$time= strtotime("+4 week 2 days 1 hours 1 seconds");
echo date("d-m-Y h:i:s",$time)
?>

9.<?php
date_default_timezone_set("Asia/Calcutta");
$time= strtotime("next tuesday");
echo date("d-m-Y h:i:s",$time)
?>

10.<?php
date_default_timezone_set("Asia/Calcutta");
$time= strtotime("last tuesday");
echo date("d-m-Y h:i:s",$time)
?>

11.<?php
date_default_timezone_set("Asia/Calcutta");
$time= strtotime("-1 days");
echo date("d-m-Y h:i:s",$time)
?>

12.<?php
date_default_timezone_set("Asia/Calcutta");
$time= strtotime("10:05:10");
echo date('h:i:s',$time);
?>

13.<?php
date_default_timezone_set("Asia/Calcutta");
$time= strtotime("10:05:10");
echo date('h:i:s A',$time);
?>

14.<?php
date_default_timezone_set("Asia/Calcutta");
$time= strtotime("20:05:10");
echo date('h:i:s A',$time);
?>

15.<?php
date_default_timezone_set("Asia/Calcutta");
$time= strtotime("20:05:10");
echo date('H:i:s A',$time);
?>

16.<?php
date_default_timezone_set("Asia/Calcutta");
$time= strtotime("20:05:10");
echo date('h:i:s A',strtotime("+1 hours",$time));
?>

17.<?php
date_default_timezone_set("Asia/Calcutta");
$time= strtotime("20:05:10");
echo date('h:i:s A',strtotime("+10 minutes",$time));
?>

18.<?php
date_default_timezone_set("Asia/Calcutta");
$time= strtotime("20:05:10");
echo date('h:i:s A',strtotime("+10 seconds",$time));
?>

19.<?php
date_default_timezone_set("Asia/Calcutta");
echo date('h:i:s A',strtotime("+10 seconds"));
?>

20.<?php
print_r(timezone_identifiers_list());
?>

21.<?php
$data=timezone_identifiers_list();
foreach($data as $result)
{
echo $result."<br>";
}
?>

22.<?php
echo date('d-m-Y h:i:s');
?>

23.<?php
$data= date('d-m-Y h:i:s');
print_r(date_parse($data));
?>

24.<?php
$data= date('d-m-Y h:i:s');
$parse=date_parse($data);
foreach($parse as $result)
{
echo $result."<br>";
}
?>

25.<?php
$data= date('d-m-Y h:i:s');
$parse=date_parse($data);
foreach($parse as $result)
{
if(!is_array($result))
{
echo $result."<br>";
}
}
?>

26.<?php
$data= date('d-m-Y h:i:s');
$parse=date_parse($data);
foreach($parse as $result)
{
if(!is_array($result))
{
echo $result."<br>";
}
else
{
print_r($result);
}
}
?>

=>
19. ADD DAYS IN DATE ?
$date=date_create("31-12-2019");
date_add($date,date_interval_create_from_date_string("1 days"));
echo $date->format(‘d-m-Y’);

20. ADD MONTHS IN DATE ?
$date=date_create("31-12-2019");
date_add($date,date_interval_create_from_date_string("1 months"));
echo $date->format(‘d-m-Y’);

21. ADD YEARS IN DATE ?
$date=date_create("31-12-2019");
date_add($date,date_interval_create_from_date_string("1 years"));
echo $date->format(‘d-m-Y’);

22. strtotime() all string parameters
$time = strtotime('now’); // example : ‘now’,’+4 days’,’+2 months’,’-1 week’,’next Monday’
$result = date("d-m-Y h:i:s A",$time);
echo $result;

23. CREATE CUSTOM TIME ?
$time = strtotime('10:00:00');
$result = date("h:i:s A",$time);
echo $result;

24. Adding or substracting minutes ?
$time = strtotime('10:00:00');
$result = date("h:i:s A", strtotime(‘-10 minutes’,$time));
echo $result;

25. Adding or substracting seconds ?
$time = strtotime('10:00:00');
$result = date("h:i:s A", strtotime(‘-10 seconds’,$time));
echo $result;

26. Adding or substracting hours ?
$time = strtotime('10:00:00');
$result = date("h:i:s A", strtotime(‘-10 hours’,$time));
echo $result;


CH-23 PHP 7 INTRO TO OOPS
1.<?php
class test{
public $x="saurav";
}
$result=new test();
echo $result->x;
?>

2.<?php
class add{
public $x=10;
public $y=12;
}
$object=new add();
$result=$object->x+$object->y;
echo $result;
?>

3.<?php
class add{
function demo()
{
echo "success";
}
}
$object=new add();
$object->demo();
?>

4.<?php
class add{
public $x;
function demo()
{
$this->x="success";
}
}
$object=new add();
$object->demo();
echo $object->x;
?>

5.<?php
class add{
function demo($x)
{
echo $x;
}
}
$object=new add();
$object->demo("saurav");
?>

6.<?php
class add{
public $x;
function demo($data)
{
echo $this->x=$data;
}
}
$object=new add();
$object->demo("saurav");
?>

7.<?php
class add{
function demo()
{
echo "success";
}
}
$first=new add();
$first->demo();
$second=new add();
$second->demo();
?>

8.<body>
<form method="post" action="p.php">
<input type="text" name="user">
<input type="submit">
</form>
</body>
<?php
if($_SERVER['REQUEST_METHOD']=="POST")
{
echo "success";
}
?>

9.<body>
<form method="post" action="p.php">
<input type="text" name="user">
<input type="submit">
</form>
</body>
<?php
if($_SERVER['REQUEST_METHOD']=="POST")
{
class wap{
public $data;
function demo(){
echo $this->data=$_POST['user'];
}
}
$object=new wap();
$object->demo();
}
?>


CH-24 PHP 7 OOPS CONSTRUCTOR VS DESTRUCTOR
1.<?php
class wap{
public $x;
}
$object=new wap();
$object->x="saurav";
echo $object->x;
?>

2.<?php
class wap{
private $x;
function demo(){
echo $this->x="sumit";
}
}
$object=new wap();
$object->demo();
?>

3.<?php
class wap{
function wap(){
echo "hello wap";
}
}
new wap();
?>

5.<?php
class wap{
function wap(){
echo "hello wap";
}
}
$object=new wap();
$object->demo();
?>

6.<?php
class wap{
function __construct(){
echo "hello wap";
}
}
$object=new wap();
?>

7.<?php
class wap{
function __construct($data){
echo $data;
}
}
$object=new wap("saurav");
?>

8.<?php
class wap{
public $x;
function __construct($data){
echo $this->x=$data;
}
}
$object=new wap("saurav");
?>

9.<?php
class wap{
public $x;
function __construct($data){
echo $this->x=$data;
}
function __destruct(){
echo "testing";
}
}
$object=new wap("saurav");
?>

10.<?php
class wap{
public $x;
function __destruct(){
echo "testing";
}
function __construct($data){
echo $this->x=$data;
}
}
$object=new wap("saurav");
?>

11.<?php
$db=new mysqli("localhost","root","","oops");
if(!$db->connect_error)
{
class create_table{
public $sql;
public $response;
function __construct(){
$this->sql="CREATE TABLE demo(
id INT(11) NOT NULL AUTO_INCREMENT,
name VARCHAR(50),
PRIMARY KEY(id)
)";
$this->response=$GLOBALS['db']->query($this->sql);
if(!$this->response)
{
die("failed");
}
}
function __destruct(){
header("Location:https://google.com");     
}
}
new create_table();
}
?>

12.<?php
$db=new mysqli("localhost","root","","oops");
if(!$db->connect_error)
{
class create_table{
private $sql;
private $response;
function __construct(){
$this->sql="CREATE TABLE demo(
id INT(11) NOT NULL AUTO_INCREMENT,
name VARCHAR(50),
PRIMARY KEY(id)
)";
$this->response=$GLOBALS['db']->query($this->sql);
if(!$this->response)
{
die("failed");
}
}
function __destruct(){
header("Location:https://google.com");     
}
}
new create_table();
}
?>


CH-25 PHP 7 OOPS CONST, TRAITS AND INHERITANCE
1.<?php
$x="saurav";
$x="kumar";
echo $x;
?>

2.<?php
const x="saurav";
echo x;
?>

3.<?php
class test{
const x="saurav";
}
echo test::x;
?>

4.<?php
class test{
public $x="saurav";
}
$object = new test();
echo $object->x;
?>

5.<?php
class test{
const x="saurav";
function demo(){
echo self::x;
}
}
$x=new test();
$x->demo();
?>

6.<?php
class test{
public static $x="saurav";
}
echo test::$x;
?>

7.<?php
class test{
public static $x="saurav";
static function demo(){
echo "success";
}
}
echo test::demo();
?>

8.<?php
class test{
public static $x="saurav";
static function demo(){
echo self::$x;
}
}
test::demo();
?>

9.<?php
class a{
public $x="saurav";
}
class b{
public $x="gautam";
}
$a=new a();
$b=new b();
echo $a->x;
echo $b->x;
?>

10.<?php
trait common_codes{
function demo(){
echo "success";
}
}
class a{
use common_codes;
}
class b{
use common_codes;
}
$a=new a();
$b=new b();
$a->demo();
$b->demo();
?>

11.<?php
trait common_codes{
static function demo(){
echo "success";
}
}
class a{
use common_codes;
}
class b{
use common_codes;
}
a::demo();
?>

12.<?php
class common_code{
public $name="saurav";
public $dob="12-10-2020";
public $age="7";
}
class students extends common_code{

}
class faculty extends common_code{
public $subjects="maths";
public $salary="10000";
}
$st=new students();
echo $st->name;
?>

13.<?php
class common_code{
public $name="saurav";
public $dob="12-10-2020";
public $age="7";
}
class students extends common_code{

}
class faculty extends common_code{
public $subjects="maths";
public $salary="10000";
}
$st=new students();
echo $st->name;
$fc=new faculty();
echo $fc->name;
?>


CH-26 PHP 7 OOPS PRINCIPALS
1.<?php
abstract class test{
public $x="saurav";
}
class duplicate extends test{
}
$o=new duplicate();
echo $o->x;
?>

2.<?php
abstract class test{
public $x="saurav";
abstract function demo();
}
class duplicate extends test{
function demo(){
echo $this->x;
}
}
$o=new duplicate();
$o->demo();
?>

3.<?php
abstract class test{
public $x="saurav";
abstract function demo();
}
class duplicate extends test{
function demo(){
echo $this->x="ravi";
}
}
$o=new duplicate();
$o->demo();
?>

4.<?php
class main{
public $x;
}
class a extends main{
public $x="saurav";
}
class b extends main{
public $x="gaurav";
}
$a=new a();
echo $a->x;
$b=new b();
echo $b->x;
?>

5.<?php
class main{
function demo(){
echo "1";
}
}
class a extends main{
function demo(){
echo "2";
}
}
class b extends main{
function demo(){
echo "3";
}
}
$a=new a();
echo $a->demo();
$b=new b();
echo $b->demo();
?>


CH-27 PHP 7 OOPS PRACTICE FOR PROJECTS
1.<?php
class main{
private $x;
function demo($data)
{
echo $this->x=$data;
}
}
$o=new main();
$o->demo("saurav");
?>

2.<?php
class main{
private $x;
function demo($data)
{
$this->x=$data;
}
}
$o=new main();
echo $o->demo("saurav");
?>

3.<?php
class main{
private $x;
function demo($data)
{
return "ravi";
}
}
$o=new main();
echo $o->demo("saurav");
?>

4.<?php
class main{
private $all_data=[];
function demo($x,$y,$z)
{
$this->all_data[0]=$x;
$this->all_data[1]=$y;
$this->all_data[2]=$z;
return $this->all_data;
}
}
$o=new main();
$result=$o->demo("saurav","20","21");
print_r($result);
?>

5.<?php
class main{
private $all_data=[];
function demo($x)
{
$this->all_data=$x;
return $this->all_data;
}
}
$array=["saurav","20","21"];
$o=new main();
$result=$o->demo($array);
print_r($result);
?>

6.<?php
class main{
private $all_data=[];
function set($x)
{
$this->all_data=$x;
}
function get(){
return $this->all_data;
}
}
$array=["saurav","20","21"];
$o=new main();
$o->set($array);
$result=$o->get();
print_r($result);
?>

7.<?php
class main{
private $all_data=[];
function set($x)
{
$this->all_data=$x;
}
function get(){
print_r($this->all_data);
}
}
$array=["saurav","20","21"];
$o=new main();
$o->set($array);
$o->get();
?>

8.<body class="container py-5">
<div class="row">
<div class="col-md-6">
<div class="jumbotron py-3">
<form action="p.php" method="post">
<input type="text" name="name" placeholder="Student's name" class="form-control mb-3">
<input type="date" name="dob" class="form-control mb-3">
<input type="number" name="age" placeholder="Age" class="form-control mb-3">
<button type="submit" class="btn btn-primary" name="st-submit">SUBMIT</button>
</form>
</div>
</div>
<div class="col-md-6">
<div class="jumbotron py-3">
<form action="p.php" method="post">
<input type="text" name="name" placeholder="Faculty's name" class="form-control mb-3">
<input type="date" name="dob" class="form-control mb-3">
<input type="number" name="age" placeholder="Age" class="form-control mb-3">
<input type="text" name="f-subject" placeholder="Subject" class="form-control mb-3">
<input type="number" name="f-salary" placeholder="Salary" class="form-control mb-3">
<button type="submit" class="btn btn-primary" name="fc-submit">SUBMIT</button>
</form>
</div>
</div>
</div>
</body>
=>p.php
<?php
class db{
private $db;
private $response;
private $name;
private $dob;
private $age;
private $subject;
private $salary;
private $query;
function database(){
$this->db = new mysqli("localhost","root","","test");
if($this->db->connect_error)
{
die("Failed");
}
}

function insert_student($name,$dob,$age)
{
$this->database();
$this->name = $name;
$this->dob = $dob;
$this->age = $age;
$this->query = "INSERT INTO student(name,dob,age)
VALUES('$this->name','$this->dob','$this->age')";
$this->response = $this->db->query($this->query);

if($this->response)
{
echo "student success";
}

else{
echo "student failed";
}
}

function insert_faculty($name,$dob,$age,$subject,$salary)
{
$this->database();
$this->name = $name;
$this->dob = $dob;
$this->age = $age;
$this->subject = $subject;
$this->salary = $salary;
$this->query = "INSERT INTO faculty(name,dob,age,subject,salary)
VALUES('$this->name','$this->dob','$this->age','$this->subject','$this->salary')";
$this->response = $this->db->query($this->query);

if($this->response)
{
echo "faculty success";
}

else{
echo "faculty failed";
}
}
}


class common_codes{
private $common_data = [];
function set(){
$this->common_data[0] = $_POST['name'];
$this->common_data[1] = $_POST['dob'];
$this->common_data[2] = $_POST['age'];
return $this->common_data;
}
}

class students extends common_codes{

}

class faculty extends common_codes{
private $other_data = [];
function setdata(){
$this->other_data[0] = $_POST['subject'];
$this->other_data[1] = $_POST['salary'];
return $this->other_data;

}
}

class main{
function result()
{
if(isset($_POST['st-submit']))
{
$students = new students();
$result = $students->set();
$db = new db();
$db->insert_student($result[0],$result[1],$result[2]);
}

else if(isset($_POST['fc-submit']))
{
$faculty = new faculty();
$common_data = $faculty->set();
$other_data = $faculty->setdata();
$db = new db();
$db->insert_faculty($common_data[0],$common_data[1],$common_data[2],$other_data[0],$other_data[1]);
}
}
}
$main = new main();
$main->result();
?>


CH-28 PHP 7 OOPS WITH SQL INJECTION
1.<body class="container py-5">
<form method="post" action="p.php">
<input type="text" name="username" placeholder="username" class="w-25 mb-3">
<input type="password" name="password" placeholder="password" class="w-25 mb-3">
<button type="submit">LOGIN</button>
</form>
</body>
</html>
=>p.php
<?php
class db{
private $db;
function database()
{
$this->db=new mysqli("localhost","root","","test");
if(!$this->db->connect_error)
{
return $this->db;
}
}  
}
class check_user{
private $username;
private $password;
private $db;
private $query;
private $tmp_pwd;
private $response;
private $data;
function __construct($username,$password){
$this->username=$username;
$this->password=$password;
$this->db=new db();
$this->db=$this->db->database();
$this->query="SELECT * FROM user WHERE username='$username'";
$this->response=$this->db->query($this->query);
if($this->response->num_rows != 0)
{
$this->data=$this->response->fetch_assoc();
$this->tmp_pwd=$this->data['password'];
if($this->tmp_pwd == $this->password)
{
echo "success";
}
else{
echo "wrong password";
}
}

else{
echo "user not found";
}
}
}
class main{
private $username;
private $password;
function __construct(){
$this->username=$_POST['username'];
$this->password=$_POST['password'];
new check_user($this->username,$this->password);
}
}
new main();

?>

2.SELECT * FROM `user` WHERE username='saurav';

3.SELECT * FROM `user` WHERE username='saurav' OR true;

4.SELECT * FROM `user` WHERE username='aadd' OR true;

5.<body class="container py-5">
<form method="post" action="p.php">
<input type="text" name="username" placeholder="username" class="w-25 mb-3">
<input type="password" name="password" placeholder="password" class="w-25 mb-3">
<button type="submit">LOGIN</button>
</form>
</body>
</html>
=>p.php
<?php
class db{
private $db;
function database()
{
$this->db=new mysqli("localhost","root","","test");
if(!$this->db->connect_error)
{
return $this->db;
}
}  
}
class check_user{
private $username;
private $password;
private $db;
private $query;
private $tmp_pwd;
private $response;
private $data;
function __construct($username,$password){
$this->username=$username;
$this->password=$password;
$this->db=new db();
$this->db=$this->db->database();
$this->query="SELECT * FROM user WHERE username='$username' AND password='$password'";
$this->response=$this->db->query($this->query);
if($this->response->num_rows != 0)
{
echo "success";

}

else{
echo "failed";
}
}
}
class main{
private $username;
private $password;
function __construct(){
$this->username=$_POST['username'];
$this->password=$_POST['password'];
new check_user($this->username,$this->password);
}
}
new main();

?>


CH-29 PHP 7 OOPS SQL SECURITY
1.<body class="container py-5">
<form method="post" action="p.php">
<input type="text" name="username" placeholder="username" class="w-25 mb-3">
<input type="password" name="password" placeholder="password" class="w-25 mb-3">
<button type="submit">LOGIN</button>
</form>
</body>
</html>
=>p.php
<?php
$db=new mysqli("localhost","root","","test");
$username=$_POST['username'];
$password=$_POST['password'];
$query="UPDATE user SET password='$password' WHERE username='$username'";
$response=$db->query($query);
if($response)
{
echo "success";
}
else{
echo "failed";
}

?>

2.<body class="container py-5">
<form method="post" action="p.php">
<input type="text" name="username" placeholder="username" class="w-25 mb-3">
<input type="password" name="password" placeholder="password" class="w-25 mb-3">
<button type="submit">LOGIN</button>
</form>
</body>
</html>
=>p.php
<?php
$db=new mysqli("localhost","root","","test");
$username=mysqli_real_escape_string($db,$_POST['username']);
$password=mysqli_real_escape_string($db,$_POST['password']);
$query="UPDATE user SET password='$password' WHERE username='$username'";
$response=$db->query($query);
if($response)
{
echo "success";
}
else{
echo "failed";
}

?>

3.<body class="container py-5">
<form method="post" action="p.php">
<input type="text" name="username" placeholder="username" class="w-25 mb-3">
<input type="password" name="password" placeholder="password" class="w-25 mb-3">
<button type="submit">LOGIN</button>
</form>
</body>
</html>
=>p.php
<?php
$db=new mysqli("localhost","root","","test");
$username=mysqli_real_escape_string($db,$_POST['username']);
$password=mysqli_real_escape_string($db,$_POST['password']);
$query=$db->prepare("UPDATE user SET password=? WHERE username=?");
$query->bind_param('ss',$password,$username);
$response=$query->execute();
if($response)
{
echo "success";
}
else{
echo "failed";
}

?>

4.<body class="container py-5">
<form method="post" action="p.php">
<input type="text" name="username" placeholder="username" class="w-25 mb-3">
<input type="password" name="password" placeholder="password" class="w-25 mb-3">
<button type="submit">LOGIN</button>
</form>
</body>
</html>
=>p.php
<?php
$db=new mysqli("localhost","root","","test");
$username=mysqli_real_escape_string($db,$_POST['username']);
$password=mysqli_real_escape_string($db,$_POST['password']);
$query=$db->prepare("UPDATE user SET password=? WHERE username=?");
$query->bind_param('ss',$password,$username);
$query->execute();
if($query->affected_rows !=0)
{
echo "success";
}
else{
echo "password not changed please use other password";
}

?>

5.<body class="container py-5">
<form method="post" action="p.php">
<input type="text" name="username" placeholder="username" class="w-25 mb-3">
<input type="password" name="password" placeholder="password" class="w-25 mb-3">
<button type="submit">LOGIN</button>
</form>
</body>
</html>
=>p.php
<?php
$db=new mysqli("localhost","root","","test");
$username=mysqli_real_escape_string($db,$_POST['username']);
$password=mysqli_real_escape_string($db,$_POST['password']);
$query=$db->prepare("SELECT password FROM user WHERE username=?");
$query->bind_param('s',$username);
$query->execute();
$query->store_result();
if($query->num_rows !=0)
{
$query->bind_result($pwd_result);
$query->fetch();
echo $pwd_result;
}
else{
echo "failed";
}

?>


CH-30 PHP 7 OOPS CROSS SITE SCRIPTING
1.<body class="container py-5">
<form method="post" action="p.php">
<input type="text" name="username" placeholder="username" class="w-25 mb-3">
<input type="password" name="password" placeholder="password" class="w-25 mb-3">
<button type="submit">LOGIN</button>
</form>
</body>
</html>
=>p.php
<?php
class db{
private $db;
function database()
{
$this->db=new mysqli("localhost","root","","test");
if(!$this->db->connect_error)
{
return $this->db;
}
}  
}
class check_user{
private $username;
private $password;
private $db;
private $query;
private $tmp_pwd;
private $response;
private $data;
function __construct($username,$password){
$this->username=$username;
$this->password=$password;
$this->db=new db();
$this->db=$this->db->database();
$this->query=$this->db->prepare("SELECT * FROM user WHERE username=?");
$this->query->bind_param('s',$username);
$this->query->execute();
$this->response=$this->query->get_result();
if($this->response->num_rows != 0)
{
$this->data=$this->response->fetch_assoc();
$this->tmp_pwd=$this->data['password'];
if($this->tmp_pwd == $this->password)
{
echo "success";
}

else{
echo "wrong password";
}
}
else{
echo "user not found";
}

}
}
class main{
private $username;
private $password;
private $db;
function __construct(){
$this->db=new db();
$this->db=$this->db->database();
$this->username=mysqli_real_escape_string($this->db,$_POST['username']);
$this->password=mysqli_real_escape_string($this->db,$_POST['password']);
new check_user($this->username,$this->password);
}
}
new main();

?>

2.<body class="container py-5">
<form method="post" action="p.php" autocomplete="off">
<input type="text" name="fullname" placeholder="Your name" class="w-25 mb-3">
<input type="text" name="username" placeholder="username" class="w-25 mb-3">
<input type="password" name="password" placeholder="password" class="w-25 mb-3">
<button type="submit">SIGN UP</button>
</form>
<br><br>
<form method="post" action="l.php" autocomplete="off">
<input type="text" name="username" placeholder="username" class="w-25 mb-3">
<input type="password" name="password" placeholder="password" class="w-25 mb-3">
<button type="submit">LOGIN</button>
</form>
</body>
</html>
=>p.php
<?php
$f=$_POST['fullname'];
$u=$_POST['username'];
$p=$_POST['password'];
$db=new mysqli("localhost","root","","test");
$q="INSERT INTO user(full_name,username,password)VALUES('$f','$u','$p')";
$db->query($q);

?>
=>l.php
<?php
$db=new mysqli("localhost","root","","test");
$u=$_POST['username'];
$p=$_POST['password'];
$q="SELECT * FROM user WHERE username='$u' AND password='$p'";
$response=$db->query($q);
if($response->num_rows !=0)
{
$data=$response->fetch_assoc();
echo $data['full_name'];
}
else{
echo "failed";
}

?>

3.<body class="container py-5">
<form method="post" action="p.php" autocomplete="off">
<input type="text" name="fullname" placeholder="Your name" class="w-25 mb-3">
<input type="text" name="username" placeholder="username" class="w-25 mb-3">
<input type="password" name="password" placeholder="password" class="w-25 mb-3">
<button type="submit">SIGN UP</button>
</form>
<br><br>
<form method="post" action="l.php" autocomplete="off">
<input type="text" name="username" placeholder="username" class="w-25 mb-3">
<input type="password" name="password" placeholder="password" class="w-25 mb-3">
<button type="submit">LOGIN</button>
</form>
</body>
</html>
=>p.php
<?php
$f=htmlspecialchars($_POST['fullname']);
$u=htmlspecialchars($_POST['username']);
$p=md5($_POST['password']);
$db=new mysqli("localhost","root","","test");
$q="INSERT INTO user(full_name,username,password)VALUES('$f','$u','$p')";
$db->query($q);

?>
=>l.php
<?php
$db=new mysqli("localhost","root","","test");
$u=$_POST['username'];
$p=md5($_POST['password']);
$q="SELECT * FROM user WHERE username='$u' AND password='$p'";
$response=$db->query($q);
if($response->num_rows !=0)
{
$data=$response->fetch_assoc();
echo $data['full_name'];
}
else{
echo "failed";
}

?>

4.<body class="container py-5">
<form method="post" action="p.php" autocomplete="off">
<input type="text" name="fullname" placeholder="Your name" class="w-25 mb-3">
<input type="text" name="username" placeholder="username" class="w-25 mb-3">
<input type="password" name="password" placeholder="password" class="w-25 mb-3">
<button type="submit">SIGN UP</button>
</form>
<br><br>
<form method="post" action="l.php" autocomplete="off">
<input type="text" name="username" placeholder="username" class="w-25 mb-3">
<input type="password" name="password" placeholder="password" class="w-25 mb-3">
<button type="submit">LOGIN</button>
</form>
</body>
</html>
=>p.php
<?php
$db=new mysqli("localhost","root","","test");
$f=$_POST['fullname'];
$f=trim($f);
$f=htmlspecialchars($f,ENT_QUOTES);
$f=mysqli_real_escape_string($db,$f);
$u=$_POST['username'];
$u=trim($u);
$u=htmlspecialchars($u,ENT_QUOTES);
$f=mysqli_real_escape_string($db,$u);
$p=$_POST['password'];
$p=trim($p);
$p=md5($p);

$q=$db->prepare("INSERT INTO user(full_name,username,password)VALUES(?,?,?)");
$q->bind_param('sss',$f,$u,$p);
$q->execute();
if($q->affected_rows !=0)
{
echo "success";
}
else{
echo "failed";
}

?>
=>l.php
<?php
$db=new mysqli("localhost","root","","test");
$u=$_POST['username'];
$p=md5($_POST['password']);
$q="SELECT * FROM user WHERE username='$u' AND password='$p'";
$response=$db->query($q);
if($response->num_rows !=0)
{
$data=$response->fetch_assoc();
echo $data['full_name'];
}
else{
echo "failed";
}
?>


CH-31 PHP 7 MULTI UPLOADS AND ENCRYPTIONS
1.<body class="container py-5">
<form>
<input type="file" id="input" accept="image/*" multiple="multiple">
</form>
<script>
$(document).ready(function(){
$("#input").on("change",function(){
alert(this.files.length);
});
});
</script>
</body>
</html>


2.<body class="container py-5">
<form>
<input type="file" id="input" accept="image/*" multiple="multiple">
</form>
<script>
$(document).ready(function(){
$("#input").on("change",function(){
var formdata=new FormData();
var i;
for(i=0;i<this.files.length;i++)
{
formdata.append("data[]",this.files[i]);
}
$.ajax({
type:"POST",
url:"p.php",
data:formdata,
processData:false,
contentType:false,
cache:false,
success:function(response)
{
document.write(response);
}
});
});
});
</script>
</body>
</html>
=>p.php

<?php

print_r($_FILES['data']);

?>

3.<body class="container py-5">

<form>
<input type="file" id="input" accept="image/*" multiple="multiple">
</form>
<script>
$(document).ready(function(){
$("#input").on("change",function(){
var formdata=new FormData();
var i;
for(i=0;i<this.files.length;i++)
{
formdata.append("data[]",this.files[i]);
}
$.ajax({
type:"POST",
url:"p.php",
data:formdata,
processData:false,
contentType:false,
cache:false,
success:function(response)
{
document.write("<pre>"+response+"</pre>");
}
});
});
});
</script>
</body>
</html>
=>p.php

<?php

print_r($_FILES['data']);

?>

4.<body class="container py-5">

<form>
<input type="file" id="input" accept="image/*" multiple="multiple">
</form>
<script>
$(document).ready(function(){
$("#input").on("change",function(){
var formdata=new FormData();
var i;
for(i=0;i<this.files.length;i++)
{
formdata.append("data[]",this.files[i]);
}
$.ajax({
type:"POST",
url:"p.php",
data:formdata,
processData:false,
contentType:false,
cache:false,
success:function(response)
{
document.write("<pre>"+response+"</pre>");
}
});
});
});
</script>
</body>
</html>
=>p.php

<?php

$file=$_FILES['data'];

echo $file['name'][0];
?>
=>p.php
<?php
$file=$_FILES['data'];
for($i=0;$i<count($file['name']);$i++)
{
echo $file['name'][$i];
}
?>
=>p.php
<?php
$file=$_FILES['data'];
for($i=0;$i<count($file['name']);$i++)
{
$filename=$file['name'][$i];
$tmp=$file['tmp_name'][$i];
move_uploaded_file($tmp,"result/".$filename);
}
?>

6.<body class="container py-5">

<form>
<input type="file" id="input" accept="image/*" multiple="multiple">
</form>
<script>
$(document).ready(function(){
$("#input").on("change",function(){
var formdata=new FormData();
var i;
for(i=0;i<this.files.length;i++)
{
formdata.append("data[]",this.files[i]);
}
$.ajax({
type:"POST",
url:"p.php",
data:formdata,
processData:false,
contentType:false,
cache:false,
success:function(response)
{
var r=JSON.parse(response);
var i;
for(i=0;i<r.length;i++)
{
document.write(r[i]+"<br>");
}
}
});
});
});
</script>
</body>
</html>
=>p.php

<?php

$response=[];

$file=$_FILES['data'];
for($i=0;$i<count($file['name']);$i++)
{
$filename=$file['name'][$i];
$tmp=$file['tmp_name'][$i];
$file_details=pathinfo($filename);
if($file_details['extension'] == "jpg" || $file_details['extension'] == "gif" || $file_details['extension'] == "png" || $file_details['extension'] == "webp")
{
if(move_uploaded_file($tmp,"result/".$filename))
{
array_push($response,$filename." uploaded");
}
}
else{
array_push($response,"<font color='red'>".$filename." not uploaded</font>");
}
}
echo json_encode($response);
?>

7.<body class="container py-5">
<form>
<input type="file" id="input" accept="image/*" multiple="multiple">
<p></p>
</form>
<script>
$(document).ready(function(){
$("#input").on("change",function(){
var formdata=new FormData();
var i;
for(i=0;i<this.files.length;i++)
{
formdata.append("data[]",this.files[i]);
}
$.ajax({
type:"POST",
url:"p.php",
data:formdata,
processData:false,
contentType:false,
cache:false,
xhr:function(){
var request=new XMLHttpRequest();
request.upload.onprogress=function(e)
{
var loaded=Math.floor(e.loaded);
var total=Math.floor(e.total);
var p=Math.floor((loaded*100)/total);
$("p").html(p+"%");
}
return request;
},
success:function(response)
{
var r=JSON.parse(response);
var i;
for(i=0;i<r.length;i++)
{
document.write(r[i]+"<br>");
}
}
});
});
});
</script>
</body>
</html>
=>p.php
<?php
$response=[];
$file=$_FILES['data'];
for($i=0;$i<count($file['name']);$i++)
{
$filename=$file['name'][$i];
$tmp=$file['tmp_name'][$i];
$file_details=pathinfo($filename);
if($file_details['extension'] == "jpg" || $file_details['extension'] == "gif" || $file_details['extension'] == "png" || $file_details['extension'] == "webp")
{
if(move_uploaded_file($tmp,"result/".$filename))
{
array_push($response,$filename." uploaded");
}
}
else{
array_push($response,"<font color='red'>".$filename." not uploaded</font>");
}
}
echo json_encode($response);

?>

8.<?php
$pwd="saurav";
echo md5($pwd);
?>

9.<?php
$pwd="s";
echo md5($pwd);
?>

10.<?php
$pwd="sauravfsdsdgsdgdsgdgfd";
echo md5($pwd);
?>

11.<?php
$pwd="sauravdgsdgsdggdgsd";
echo strlen(md5($pwd));
?>

12.<?php
$pwd="s";
echo strlen(md5($pwd));
?>

13.<?php
$pwd="s";
echo md5($pwd,true);
?>

14.<?php
$pwd="s";
echo sha1($pwd);
?>

15.<?php
$pwd="s";
echo sha1($pwd,true);
?>


CH-32 PHP 7 FILE HANDLING PART 1
1.<?php
echo disk_total_space("C:");
?>

2.<?php
echo disk_total_space("C:")/1024;
?>

3.<?php
echo disk_total_space("C:")/1024/1024;
?>

4.<?php
echo disk_total_space("C:")/1024/1024/1024;
?>

5.<?php
echo round(disk_total_space("C:")/1024/1024/1024,2);
?>

6.<?php
echo "total size= ".round(disk_total_space("C:")/1024/1024/1024,2);
echo "<br>";
echo "free size= ".round(disk_free_space("C:")/1024/1024/1024,2);
?>

7.<?php
echo "total size= ".round(disk_total_space("C:")/1024/1024/1024,2);
echo "<br>";
echo "free size= ".round(disk_free_space("C:")/1024/1024/1024,2);
echo "<br>";
echo "used memory= ".round(disk_total_space("C:")/1024/1024/1024-disk_free_space("C:")/1024/1024/1024,2);
?>

8.<?php
if(copy("test.mp4","E:/demo.mp4"))
{
echo "success";
}
?>

9.<?php
echo round(filesize("test.mp4")/1024/1024,2)." MB";
?>

10.<?php
echo filetype("test.mp4");
?>

11.<?php
echo getcwd();
?>

12.<?php
print_r(scandir(getcwd()));
?>

13.<?php
foreach(scandir(getcwd()) as $data)
{
echo $data."<br>";
}
?>

14.<?php
$file=0;
$folder=0;
foreach(scandir(getcwd()) as $data)
{
if(filetype($data) == "file")
{
$file=$file+1;
}
else if(filetype($data) == "dir")
{
$folder=$folder+1;
}
}
echo $file." files<br>";
echo $folder." folders<br>";
?>

15.<?php
print_r(file("file.txt"));
?>

16.<body class="p-5">
<div class="container">
<h3 class="text-center">www.wapinstitute.com</h3>
<div class="row">
<div class="col-md-2 p-3 border">
<button class="w-100 btn btn-dark py-2 mb-3 tab">HOME</button>
<button class="w-100 btn btn-dark py-2 mb-3 tab">COURSE</button>
<button class="w-100 btn btn-dark py-2 mb-3 tab">ABOUT US</button>
<button class="w-100 btn btn-dark py-2 mb-3 tab">CONTACT US</button>
<button class="w-100 btn btn-dark py-2 mb-3 tab">TERM & CONDITION</button>
</div>
<div class="col-md-10 p-3 border result">
<h4>wap institute homepage</h4>
<p>xyz</p>
</div>
</div>
</div>
<?php
print_r(file("file.txt"));
?>
</body>
</html>
=>file.txt
<h4>wap institute homepage</h4>
<p>xyz</p>

<h4>course</h4>
<p>xyz</p>

<h4>about</h4>
<p>xyz</p>

<h4>contact</h4>
<p>xyz</p>

<h4>terms</h4>

<p>xyz</p>

17.<body class="p-5">
<div class="container">
<h3 class="text-center">www.wapinstitute.com</h3>
<div class="row">
<div class="col-md-2 p-3 border">
<button class="w-100 btn btn-dark py-2 mb-3 tab" start="0" end="1">HOME</button>
<button class="w-100 btn btn-dark py-2 mb-3 tab" start="3" end="4">COURSE</button>
<button class="w-100 btn btn-dark py-2 mb-3 tab" start="6" end="7">ABOUT US</button>
<button class="w-100 btn btn-dark py-2 mb-3 tab" start="9" end="10">CONTACT US</button>
<button class="w-100 btn btn-dark py-2 mb-3 tab" start="12" end="13">TERM & CONDITION</button>
</div>
<div class="col-md-10 p-3 border result">
<h4>wap institute homepage</h4>
<p>xyz</p>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$(".tab").each(function(){
$(this).click(function(){
var start=$(this).attr("start");
var end=$(this).attr("end");
$.ajax({
type:"POST",
url:"p.php",
data:{
start:start,
end:end
},
beforeSend:function(){
$(".result").html("PLEASE WAIT...");
},
success:function(response)
{
$(".result").html(response);
}
});
});
});
});
</script>
</body>
=>file.txt
<h4>wap institute homepage</h4>
<p>xyz</p>

<h4>course</h4>
<p>xyz</p>

<h4>about</h4>
<p>xyz</p>

<h4>contact</h4>
<p>xyz</p>

<h4>terms</h4>

<p>xyz</p>
=>p.php
<?php
$start=$_POST['start'];
$end=$_POST['end'];
$file=file("file.txt");
echo $file[$start].$file[$end];

?>

18.<?php
$binary=file_get_contents("a.mp4");
file_put_contents("sample.mp3",$binary);
?>

19.<?php
$binary=file_get_contents("a.png");
file_put_contents("sample.jpeg",$binary);
?>


CH-32 PHP 7 FILE HANDLING PART 2
1.<?php
readfile("file.txt");
?>

2.<?php
header("Content-Type:image/jpeg");
readfile("file.jpg");
?>

3.<?php
header("Content-Type:application/pdf");
readfile("file.pdf");
?>

4.<?php
$file=fopen("sample.html","w");
fwrite($file,"hello wap");
?>

5.<?php
$file=fopen("sample.html","a");
fwrite($file,"hello wap");
?>

6.<?php
$file=fopen("sample.html","a");
fwrite($file,"hello wap");
fclose($file);
?>

7.<?php
if(unlink("sample"))
{
echo "success";
}
?>

8.<?php
if(rename("file.txt","sample.txt"))
{
echo "success";
}
?>

9.<?php
if(file_exists("sample.txt"))
{
echo "success";
}
else{
echo "file not found";
}
?>

10.<?php
$data=["saurav","wap"];
$f='/saurav/';
$r=preg_grep($f,$data);
print_r($r);
?>

11.<?php
$data=file("sample.txt");
$f='/COURSES/';
print_r(preg_grep($f,$data));
?>

12.<?php
$data=file("sample.txt");
$f='/hello wap/';
print_r(preg_grep($f,$data));
?>

13.<body class="p-3">
<div class="container-fluid">
<div class="jumbotron">
<h1>
welcome to website
</h1>
</div>
<div class="jumbotron">
<?php
readfile("file.txt");
?>
</div>
<div class="jumbotron">
<h1>
welcome to footer</h1>
</div>
</div>
</body>

14.<body class="p-3">
<div class="container-fluid">
<h1>updater app</h1>
<div class="row">
<div class="col-md-4">
<form>
<div class="form-group">
<label>input line number</label>
<input type="number" name="line-number" class="form-control" placeholder="5">
</div>
<div class="form-group">
<label>textarea</label>
<textarea name="content" rows="10" class="form-control"></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">update content</button>
</div>
</form>
</div>
<div class="col-md-8">
<?php
$file=file("file.txt");
print_r($file);
?>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$("form").submit(function(e){
e.preventDefault();
$.ajax({
type:"POST",
url:"update.php",
data:new FormData(this),
processData:false,
contentType:false,
cache:false,
success:function(response)
{
document.write(response);
}
});
});
});
</script>
</body>
=>update.php
<?php
$no=trim($_POST['line-number']);
$content=trim($_POST['content']);
$file=file("file.txt");
array_splice($file,$no,0,$content);
$all_data="";
foreach($file as $data)
{
$all_data .= $data;
}
$tmp_file=fopen("file.txt","w");
if(fwrite($tmp_file,$all_data))
{
echo "success";
}
else{
echo "failed";
}

?>

15.<body class="p-3">
<div class="container-fluid">
<h1>updater app</h1>
<div class="row">
<div class="col-md-4">
<form class="update-form">
<div class="form-group">
<label>input line number</label>
<input type="number" name="line-number" class="form-control" placeholder="5">
</div>
<div class="form-group">
<label>textarea</label>
<textarea name="content" rows="10" class="form-control"></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">update content</button>
</div>
</form>
<br>
<h1>remove content</h1>
<form class="remove-form">
<div class="form-group">
<label>from line number</label>
<input type="number" name="from-line-number" 
class="form-control" placeholder="5" required="required">
</div>
<div class="form-group">
<label>to line number</label>
<input type="number" name="to-line-number" class="form-control" placeholder="5">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">update content</button>
</div>
</form>
</div>
<div class="col-md-8">
<?php
$file=file("file.txt");
print_r($file);
?>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$(".update-form").submit(function(e){
e.preventDefault();
$.ajax({
type:"POST",
url:"update.php",
data:new FormData(this),
processData:false,
contentType:false,
cache:false,
success:function(response)
{
document.write(response);
}
});
});
});

$(document).ready(function(){
$(".remove-form").submit(function(e){
e.preventDefault();
$.ajax({
type:"POST",
url:"remove.php",
data:new FormData(this),
processData:false,
contentType:false,
cache:false,
success:function(response)
{
document.write(response);
}
});
});
});
</script>
</body>
=>update.php
<?php
$no=trim($_POST['line-number']);
$content=trim($_POST['content']);
$file=file("file.txt");
array_splice($file,$no,0,$content);
$all_data="";
foreach($file as $data)
{
$all_data .= $data;
}
$tmp_file=fopen("file.txt","w");
if(fwrite($tmp_file,$all_data))
{
echo "success";
}
else{
echo "failed";
}

?>
=>remove.php
<?php
$file=file("file.txt");
$from=$_POST['from-line-number'];
$to=$_POST['to-line-number'];
if(!empty($to))
{
$all_number=range($from,$to);
foreach($all_number as $data)
{
unset($file[$data]);
}

$all_data="";
foreach($file as $data)
{
$all_data .= $data;
}
$tmp_file=fopen("file.txt","w");
if(fwrite($tmp_file,$all_data))
{
echo "success";
}
else{
echo "failed";
}
}
else{
unset($file[$from]);
$all_data="";
foreach($file as $data)
{
$all_data .= $data;
}
$tmp_file=fopen("file.txt","w");
if(fwrite($tmp_file,$all_data))
{
echo "success";
}
else{
echo "failed";
}
}

?>

CH-34 PHP 7 INTRO TO CURL
1.<body>
<script>
(document).ready(function(){
$.ajax({
type:"POST",
url:"https://wapinstitute.com",
});
});
</script>
</body>

2.<body>
<div style="width:720px;height:720px;border:5px solid red">
</div>
<script>
$(document).ready(function(){
$.ajax({
type:"POST",
url:"curl.php",
success:function(response)
{
$("div").html(response);
}
});
});
</script>
</body>
=>curl.php
<?php
$h=curl_init();
curl_setopt($h,CURLOPT_URL,"https://wapinstitute.com");
curl_setopt($h,CURLOPT_SSL_VERIFYPEER,false);
curl_exec($h);
?>

CH-35 PHP 7 WEB SCRAPING IN CURL
1.<body>
<div class="container py-5">
<h4>WEB SCRAPING</h4>
<form class="search-form mb-4" autocomplete="off">
<div class="input-group mb-3">
<input type="search" class="form-control" name="search">
<div class="input-group-append">
<button class="input-group-text" type="submit">Search</button>
</div>
</div>
</form>
<div class="jumbotron response p-3 bg-white border shadow-sm d-flex flex-wrap justify-content-around">
</div>
</div>
<script>
$(document).ready(function(){
$(".search-form").submit(function(e){
e.preventDefault();
$.ajax({
type:"POST",
url:"curl.php",
data:new FormData(this),
processData:false,
contentType:false,
cache:false,
beforeSend:function(){
$(".response").html("Please wait...");
},
success:function(response){
$(".response").html(response);
}
});
});
});
</script>
</body>
=>curl.php
<?php
$h=curl_init();
curl_setopt($h, CURLOPT_URL,"https://wapinstitute.com");
curl_setopt($h,CURLOPT_SSL_VERIFYPEER,false);
curl_exec($h);
curl_close($h);
?>

2.<body>
<div class="container py-5">
<h4>WEB SCRAPING</h4>
<form class="search-form mb-4" autocomplete="off">
<div class="input-group mb-3">
<input type="search" class="form-control" name="search">
<div class="input-group-append">
<button class="input-group-text" type="submit">Search</button>
</div>
</div>
</form>
<div class="jumbotron response p-3 bg-white border shadow-sm d-flex flex-wrap justify-content-around">
</div>
</div>
<script>
$(document).ready(function(){
$(".search-form").submit(function(e){
e.preventDefault();
$.ajax({
type:"POST",
url:"curl.php",
data:new FormData(this),
processData:false,
contentType:false,
cache:false,
beforeSend:function(){
$(".response").html("Please wait...");
},
success:function(response){
$(".response").html(response);
}
});
});
});
</script>
</body>
=>curl.php
<?php
$h=curl_init();
curl_setopt_array($h,array(
CURLOPT_URL=>"http://www.google.com",CURLOPT_SSL_VERIFYPEER=>false));
curl_exec($h);
curl_close($h);
?>

3.<body>
<div class="container py-5">
<h4>WEB SCRAPING</h4>
<form class="search-form mb-4" autocomplete="off">
<div class="input-group mb-3">
<input type="search" class="form-control" name="search">
<div class="input-group-append">
<button class="input-group-text" type="submit">Search</button>
</div>
</div>
</form>
<div class="jumbotron response p-3 bg-white border shadow-sm d-flex flex-wrap justify-content-around">
</div>
</div>
<script>
$(document).ready(function(){
$(".search-form").submit(function(e){
e.preventDefault();
$.ajax({
type:"POST",
url:"curl.php",
data:new FormData(this),
processData:false,
contentType:false,
cache:false,
beforeSend:function(){
$(".response").html("Please wait...");
},
success:function(response){
$(".response").html(response);
}
});
});
});
</script>
</body>
=>curl.php
<?php
function demo()
{
echo "saurav";
}
demo();
?>
=>curl.php
<?php
function demo()
{
$x= "saurav";
return $x;
}
echo demo();
?>
=>curl.php
<?php
$h=curl_init();
curl_setopt_array($h,array(
CURLOPT_URL=>"http://www.google.com",CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_RETURNTRANSFER=>true
));
echo curl_exec($h);
curl_close($h);
?>
=>curl.php
<?php
$h=curl_init();
curl_setopt_array($h,array(
CURLOPT_URL=>"http://www.google.com",CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_RETURNTRANSFER=>true
));
$result=curl_exec($h);
echo $result;
curl_close($h);
?>
=>curl.php
<?php
$h=curl_init();
$url=$_POST['search'];
curl_setopt_array($h,array(
CURLOPT_URL=>$url,
CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_RETURNTRANSFER=>true
));
$result=curl_exec($h);
echo $result;
curl_close($h);
?>
=>curl.php
<?php
$h=curl_init();
$url=$_POST['search'];
curl_setopt_array($h,array(
CURLOPT_URL=>$url,
CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_RETURNTRANSFER=>true
));
$result=curl_exec($h);
if($result)
{
echo $result;
}
else{
echo "Unable to connect";
}
curl_close($h);
?>
=>curl.php
<?php
$h=curl_init();
$url=$_POST['search'];
curl_setopt_array($h,array(
CURLOPT_URL=>$url,
CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_RETURNTRANSFER=>true
));
$result=curl_exec($h);
if($result)
{
echo $result;
}
else{
echo curl_error($h);
}
curl_close($h);
?>

4.<body>
<div class="container py-5">
<h4>SEARCH THE CELEBRITY</h4>
<form class="search-form mb-4" autocomplete="off">
<div class="input-group mb-3">
<input type="search" class="form-control" name="search" placeholder="Virat_Kohli">
<div class="input-group-append">
<button class="input-group-text" type="submit">Search</button>
</div>
</div>
</form>
<div class="jumbotron response p-3 bg-white border shadow-sm" style="width:fit-content">
</div>
</div>
<script>
$(document).ready(function(){
$(".search-form").submit(function(e){
e.preventDefault();
$.ajax({
type:"POST",
url:"p.php",
data:new FormData(this),
processData:false,
contentType:false,
cache:false,
beforeSend:function(){
$(".response").html("Please wait...");
},
success:function(response){
$(".response").html(response);
if(response.indexOf('class="infobox vcard"') !=-1)
{
var result=$(".vcard").html();
$(".response").html(result);
}
else{
$(".response").html("Search not found !");
}
}
});
});
});
</script>
</body>
=><?php
$h=curl_init();
$search=$_POST['search'];
$search=strtolower($search);
$search=ucwords($search);
$search=str_replace(' ','_',$search);
$url="https://en.wikipedia.org/wiki/".$search;
curl_setopt_array($h,array(
CURLOPT_URL=>$url,
CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_RETURNTRANSFER=>true
));
$result=curl_exec($h);
if($result)
{
echo $result;
}
else{
echo curl_error($h);
}
curl_close($h);
?>

CH-36 PHP 7 POST AND ELEMENT SCRAPING IN CURL
1.<body>
<div class="container py-5">
<form class="search-form mb-4" autocomplete="off" method="POST">
<input type="text" class="mb-3 form-control w-50" name="username" placeholder="Username">
<br>
<input type="password" class="mb-3 form-control w-50" name="password" placeholder="password">
<br>
<button type="submit" class="btn btn-primary">SUBMIT</button>
</form>
</div>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$uname=$_POST['username'];
$pwd=$_POST['password'];
$data=array("username"=>$uname,"password"=>$pwd);
$h=curl_init();
curl_setopt_array($h,array(
CURLOPT_URL=>"http://www.adsewap.com/testing.php",CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_RETURNTRANSFER=>true,
CURLOPT_POST=>true,
CURLOPT_POSTFIELDS=>http_build_query($data)
));
$result=curl_exec($h);
if($result)
{
echo $result;
}
else{
echo curl_error($h);
}
curl_close($h);
}
?>
=>testing.php
<?php
$u=$_POST['username'];
$p=$_POST['password'];
echo $u." ".$p;
?>

2.<body>
<div class="container py-5">
<form class="search-form mb-4" autocomplete="off" method="POST" enctype="multipart/form-data">
<input type="file" name="upload">
<br>
<button type="submit" class="btn btn-primary">SUBMIT</button>
</form>
</div>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$file=$_FILES['upload'];
$c=new CURLFile($file['tmp_name'],$file['type'],$file['name']);

$data=array("file"=>$c);
$h=curl_init();
curl_setopt_array($h,array(
CURLOPT_URL=>"http://www.adsewap.com/testing.php",CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_RETURNTRANSFER=>true,
CURLOPT_POST=>true,
CURLOPT_POSTFIELDS=>$data
));
$result=curl_exec($h);
if($result)
{
echo $result;
}
else{
echo curl_error($h);
}
curl_close($h);
}
?>
=>testing.php
<?php
$file=$_FILES['file'];
$name=$file['name'];
$l=$file['tmp_name'];
if(move_uploaded_file($l,$name))
{
echo "success";
}
else{
echo "failed";
}
?>

3.<body>
<div class="container py-5">
<form class="search-form mb-4" autocomplete="off" method="POST">
<input type="search" name="search" class="form-control w-50 mb-3">
<br>
<button type="submit" class="btn btn-primary">SUBMIT</button>
</form>
</div>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$search=$_POST['search'];
$h=curl_init();
curl_setopt_array($h,array(
CURLOPT_URL=>"https://www.google.com/search?tbm=isch&q=".$search,CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_RETURNTRANSFER=>true,
));
$result=curl_exec($h);
if($result)
{
echo $result;
}
else{
echo curl_error($h);
}
curl_close($h);
}
?>

4.<body>
<div class="container py-5">
<form class="search-form mb-4" autocomplete="off" method="POST">
<input type="search" name="search" class="form-control w-50 mb-3">
<br>
<button type="submit" class="btn btn-primary">SUBMIT</button>
</form>
</div>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$search=$_POST['search'];
$h=curl_init();
curl_setopt_array($h,array(
CURLOPT_URL=>"https://www.google.com/search?tbm=isch&q=".$search,CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_RETURNTRANSFER=>true,
));
$result=curl_exec($h);
if($result)
{
$p='/src="(.*)"/';
$search_result='';
preg_match_all($p,$result,$search_result);
print_r($search_result);
}
else{
echo curl_error($h);
}
curl_close($h);
}
?>

5.<body>
<div class="container py-5">
<form class="search-form mb-4" autocomplete="off" method="POST">
<input type="search" name="search" class="form-control w-50 mb-3">
<br>
<button type="submit" class="btn btn-primary">SUBMIT</button>
</form>
</div>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$search=$_POST['search'];
$h=curl_init();
curl_setopt_array($h,array(
CURLOPT_URL=>"https://www.google.com/search?tbm=isch&q=".$search,CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_RETURNTRANSFER=>true,
));
$result=curl_exec($h);
if($result)
{
$p='/src="([^"]*)"/';
$search_result='';
preg_match_all($p,$result,$search_result);
foreach($search_result[0] as $final)
{
echo '<img '.$final."><br><br>";
}
}
else{
echo curl_error($h);
}
curl_close($h);
}
?>

6.<body>
<div class="container py-5">
<form class="search-form mb-4" autocomplete="off" method="POST">
<input type="search" name="search" class="form-control w-50 mb-3">
<br>
<button type="submit" class="btn btn-primary">SUBMIT</button>
</form>
</div>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$search=$_POST['search'];
$h=curl_init();
curl_setopt_array($h,array(
CURLOPT_URL=>"https://www.google.com/search?tbm=isch&q=".$search,CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_RETURNTRANSFER=>true,
));
$result=curl_exec($h);
if($result)
{
$p='/src="([^"]*)"/';
$search_result='';
preg_match_all($p,$result,$search_result);
foreach($search_result[0] as $final)
{
if(strpos($final,"http:"))
{
echo '<img '.$final.">";
}
else{
echo $final."<br><br>";
}
}
}
else{
echo curl_error($h);
}
curl_close($h);
}
?>

7.<body>
<div class="container py-5">
<form class="search-form mb-4" autocomplete="off" method="POST">
<input type="search" name="search" class="form-control w-50 mb-3">
<br>
<button type="submit" class="btn btn-primary">SUBMIT</button>
</form>
</div>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$search=$_POST['search'];
$h=curl_init();
curl_setopt_array($h,array(
CURLOPT_URL=>"https://www.google.com/search?tbm=isch&q=".$search,CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_RETURNTRANSFER=>true,
));
$result=curl_exec($h);
if($result)
{
$p='/src="([^"]*)"/';
$search_result='';
preg_match_all($p,$result,$search_result);
foreach($search_result[0] as $final)
{
if(strpos($final,"http:"))
{
echo '<img '.$final.">";
}
else{
$final=str_replace('src="',"",$final);
$final=str_replace('"',"",$final);
$final="http://images.google.com".$final;
echo "<img src='".$final."'>";
}
}
}
else{
echo curl_error($h);
}
curl_close($h);
}
?>

ch-37 php 7 the ending concept
1.<?php
namespace one{
class wap{
function __construct()
{
echo "one";
}
}
}

namespace two{
class wap{
function __construct()
{
echo "two";
}
}
}
?>

2.<?php
namespace one{
class wap{
function __construct()
{
echo "one";
}
}
}

namespace two{
class wap{
function __construct()
{
echo "two";
}
}
}
?>
=>result.php
<?php
require("test.php");
new one\wap();
?>

3.<?php
namespace one{
class wap{
function __construct()
{
echo "one";
}
}
}

namespace two{
class wap{
function __construct()
{
echo "two";
}
}
}
?>
=>result.php
<?php
require("test.php");
new one\wap();
new two\wap();
?>

4.<?php
echo $_SERVER['REQUEST_METHOD'];
?>

CH-33 PHP 7 FTP PROJECT PART 5
1.<?php
fopen("demo.txt","w");
?>

2.<?php
if(fopen("ftp://admin@adsewap.com:adse@1234@166.62.10.181/demo.txt","w"))
{
echo "success";
}
?>

3.<?php
print_r(scandir("."));
?>

4.<?php
print_r("ftp://admin@adsewap.com:adse@1234@166.62.10.181/."));
?>

5.<?php
rmdir("welcome");
?>

6.<?php
$folder="welcome";
$all_data=new RecursiveDirectoryIterator($folder);
foreach($all_data as $data)
{print_r("<pre>".$data."</pre>");}
?>

7.<?php
$folder="welcome";
$all_data=new RecursiveDirectoryIterator($folder,FilesystemIterator::SKIP_DOTS);
foreach($all_data as $data)
{print_r("<pre>".$data."</pre>");}
?>

8.<?php
$folder="welcome";
$all_data=new RecursiveDirectoryIterator($folder,FilesystemIterator::SKIP_DOTS);
$final_data=new RecursiveIteratorIterator($all_data,
RecursiveIteratorIterator::CHILD_FIRST);
foreach($final_data as $data)
{print_r("<pre>".$data."</pre>");}
?>

9.<?php
$folder="welcome";
$all_data=new RecursiveDirectoryIterator($folder,FilesystemIterator::SKIP_DOTS);
$final_data=new RecursiveIteratorIterator($all_data,
RecursiveIteratorIterator::CHILD_FIRST);

foreach($final_data as $data)
{
if($data->isDir())
{
rmdir($data);
}

else{
unlink($data);
}
}
?>

CH-33 PHP 7 FTP PROJECT PART 7
1.<?php
$folder="welcome";
$all_data=new RecursiveDirectoryIterator($folder,FilesystemIterator::SKIP_DOTS);
$final_data=new RecursiveIteratorIterator($all_data,
RecursiveIteratorIterator::CHILD_FIRST);

foreach($final_data as $data)
{
if($data->isDir())
{
rmdir($data);
}
else{
unlink($data);
}
}
rmdir($folder);
?>

2.<?php
$folder="welcome";
count(scandir($folder));
?>

3.<?php
$folder="welcome";
if(count(scandir($folder)<=2))
{
echo "empty";
}
else{
echo "not empty";
}
?>

4.<?php
class wap{
private $x;
function __construct()
{

}
function demo()
{
echo $this->x="saurav";
}
}
$x=new wap();
$x->demo();
?>

ch-33 php 7 ftp project part 10
1.<?php
function copy_folder()
{
$dir=opendir($ffc);
while(($data=readdir($dir)) !=false)
{
echo $data."<br>";
}
}
$folder_for_copy="ad";
$path="welcome";
copy_folder($folder_for_copy,$path);
?>

2.<?php
function copy_folder()
{
$dir=opendir($ffc);
while(($data=readdir($dir)) !=false)
{
if($data != "." && $data !="..")
{
echo $data."<br>";
}
}
}
$folder_for_copy="ad";
$path="welcome";
copy_folder($folder_for_copy,$path);
?>

3.<?php
function copy_folder($ffc,$path)
{
$dir=opendir($ffc);
if(!file_exists($path))
{
mkdir($path);
}
while(($data=readdir($dir)) !=false)
{
if($data != "." && $data !="..")
{
if(is_dir($ffc.'/'.$data))
{
copy_folder($ffc.'/'.$data,$path.'/'.$data);
}
else{
copy($ffc.'/'.$data,$path.'/'.$data);
}
}
}
}
$folder_for_copy="ad";
$path="welcome";
copy_folder($folder_for_copy,$path);
?>

4.<?php
function copy_folder($ffc,$path)
{
$dir=opendir($ffc);
if(!file_exists($path))
{
mkdir($path);
}
while(($data=readdir($dir)) !=false)
{
if($data != "." && $data !="..")
{
if(is_dir($ffc.'/'.$data))
{
copy_folder($ffc.'/'.$data,$path.'/'.$data);
}
else{
copy($ffc.'/'.$data,$path.'/'.$data);
}
}
}
}
$folder_for_copy="ad";
$path="welcome/ad";
copy_folder($folder_for_copy,$path);
?>

5.<?php
function copy_folder($ffc,$path)
{
$dir=opendir($ffc);
if(!file_exists($path))
{
mkdir($path);
}
while(($data=readdir($dir)) !=false)
{
if($data != "." && $data !="..")
{
if(is_dir($ffc.'/'.$data))
{
copy_folder($ffc.'/'.$data,$path.'/'.$data);
}
else{
copy($ffc.'/'.$data,$path.'/'.$data);
}
}
}
closedir($dir);
}
$folder_for_copy="ad";
$path="welcome/ad";
copy_folder($folder_for_copy,$path);
?>





































































1 comment: