Search This Blog

10 February 2018

CREATE CAPTCHA CODE IN PHP



CREATE CAPTCHA CODE IN PHP

What is Captcha?
CAPTCHA=Completely Automated Public Turing test to tell Computers    and Humans Apart.Captcha is one way to Secure Your Website But not Only

Advantages:-
      Protecting Your Registeration Form
    Preventing Spam Comments
)   Online Shopping More Secure
Protect Email Accounts

First You Create Image Using PHP

<?php

session_start();
$chars="ABCDEFGHIJAKLMNOPQabcdefghijklamnopq1234567890";
$cap=substr(str_shuffle($chars),0,6);
$_SESSION['captcha']=$cap;

$image = imagecreate(100, 20);
$background = imagecolorallocate($image, 128,128,128);
$foreground = imagecolorallocate($image, 255,255,255);
imagestring($image,5,5,1,$cap,$foreground);
header("content-type:image/jpeg");
imagejpeg($image);
imagedestroy($image);
$size=getimagesize($image);
?>
/** Number Captcha  */
<?php

session_start();
$a=rand(1,20);
$b=rand(1,22);
$total=$a+$b;
$math = "$a"." + "."$b"." =";

$_SESSION['captcha'] = $total;
$background = imagecolorallocate($image, 128,128,128);
$foreground = imagecolorallocate($image, 255,255,255);
imagestring($image,15,55,15,$math,$foreground);
header("content-type:image/jpeg");
imagejpeg($image);
imagedestroy($image);
$size=getimagesize($image);

$image = imagecreate(200, 50);




?>
Next Create Your Registeration Form With Captcha


<html>
<head> </head>
<title> Captcha </title>
<link rel="icon" href="/img/chennai.jpeg">
<style>
.col1{
    height:100%;
    width:100%;
    position:relative;
   
}
.col2{
    position:absolute;
    width:25%;
    height:35%;
    background-color:#e9e6e6;
    margin-top: 20%;
    margin-left: 35%;
   
}

font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
    font-size: 14px;
    line-height: 1.42857143;
    color: #333;
.fm{
margin-left:20%;   
}
.inpt{
    height: 28px;
    padding:6px 12px;
    width:80%;
    border: 1px solid #ccc;
    border-radius: 4px;
    color:#555;
}
.btn{
border: 1px solid transparent;
border-radius: 4px;
height: 11%;
width: 42%;
background-color: #ED6D62;
color:white;
    left: 81px;
    position: absolute;
}
img{
    padding-left: 32px;

margin-right: -15px;
    margin-left: -15px;
    margin-top: 0px;
    margin-bottom: 0px;
    padding-top: 0px;
    padding-bottom: 0px;
    padding-left: 0px;
    padding: 0px;
    }

</style>
<body>
<div class=" col1 ">
    <div class=" col2 ">
    <br>
        <form method=" post " action="" class="fm">
       
                <input type =" text " class =" inpt " name=" reg " placeholder = " Enter Your Regno" required> <br>
                <br>
                <input type=" text " class=" inpt " name=" name " placeholder=" Enter Your Name " required> <br>
                <br>
                <input type=" text " class=" inpt " placeholder=" Enter Your city " name=" cy ">    <br>
                <br>
                <input type=" text " class=" inpt " placeholder=" Enter Your Captcha " name=" cap " required>    <br>
                <br>
                <img src=" /img/captcha.php " alt=" php captcha image"><br>
                 <br>
                 <br>
            <input type=" submit " name=" sub " class=" btn " value="check">
        </form>
    </div>
</div>
</body>
</html>
<?php
session_start();
$captcha=$_SESSION['captcha'];
if(isset($_POST['sub'])){
    $regno =$_POST['reg'];
    $name =$_POST['name'];
    $city =$_POST['cy'];
    $cap =$_POST['cap'];
if($captcha == $cap){
echo "<script> alert (' All inputs are Valid '); </script>";
                }
else{
echo "<script> alert (' All inputs are NOT Valid '); </script>";   
    }   
   
}
?>


OutPuts:












08 February 2018

UPLOAD FILE USING PHP



UPLOAD FILE USING PHP

Php file  upload  single and multiple file supported  simple codes Php file upload features allows to upload text, binary files  full control over the file to be uploaded through php authentication & file operation functions

Steps :
Form tag add Enctype Attribute Enctype=”multipart/form-data”
Use File Uploaded Function

Move_uploaded_file



MY Directory
    



Upload The File



Coding

<html>
<head><style>.col {
    width: 100%;
    height: 80%;
    magin:0 auto;
}

#s1{
   
    padding: 10px;
border-radius: 6px;
background-color: #4683ea;
width:100px;
color:white;
}

.background-card h4 {

      padding-bottom: 0.5em;

      margin-bottom: 0.5em;

      margin-top: 1em !important;

    }

    h4 > .fa {

      display: none !important;

    }

    .card-nested {

      padding: .5rem 0 .5rem 0;

    }

    .labels {

      display: inline;

    }

    .skill-info {

      margin-left: 0;

    }

    blockquote {

      font-size: 100%;

    }

  }



#s{

  background: radial-gradient(royalblue,skyblue)

}


  #nam{

    background: transparent;

    font-size: 35px;

    font-weight: 800;

    border: none;

    color: #000000;

}

#nm::placeholder{

   color: #000000;

  font-size: 35px;

  font-weight: 700;

}

.form-control:focus {

 background-color: #fff;

 outline: 0;

box-shadow: none;

}

.form-control{

  padding: .375rem 0px;

}





.as::placeholder{

  opacity: 0.2; 

}

#skl{

background: transparent;

font-size: 17px;

border: none;

font-weight: 700;

color: #77b6e9;

}

#skl::placeholder{

color: #000000;

font-size: 17px;

font-weight: 700;

color: #77b6e9;

}

#eml{

  background: transparent;

  font-size: 13px;

  border: none;

  font-weight: 400;

  }

  #eml::placeholder{

  color: #000000;

  font-size: 13px;

  font-weight: 400;

  }

  #pno{

    background: transparent;

    font-size: 12px;

    border: none;

    font-weight: 400;

    }

    .ui-datepicker-calendar {

      display: none;

      }

    #pno::placeholder{

    color: #000000;

    font-size: 12px;

    font-weight: 400;

    }

    



</style></head>
<form method="post" action="" enctype="multipart/form-data">
File<input type="file" name="f1"><br>
<input id="s1" type="submit" name="s" value="upload">
</form><br>
<div class="col">
<ul type="none">
</html>
<?php
$con=mysqli_connect("localhost","root","","test");
if(isset($_POST['s'])){
$fname=$_FILES['f1']['name'];
$dir=$_FILES['f1']['tmp_name']; 

$ext=pathinfo($fname,PATHINFO_EXTENSION);

if($ext=="png" || $ext=="jpg" || $ext=="gif"){

move_uploaded_file($dir,"image/".$fname);
$sql="insert into image values('$fname')";
$con->query($sql);

} else{ 

echo "Your File Type is not Supported only allowed File Types gif,png,jpg";

 }


}
$sql="select * from image order by rand()";
$res=$con->query($sql);
while($row=mysqli_fetch_array($res)){
$img=$row['image'];
?>
<li style="float:left;padding:15px;">
<img height="200" width="300" src="<?php  echo "image/".$img; ?>" alt="img not"></li>&nbsp;
<?php
}
?>

</ul>
</div>

Output:

 



07 February 2018

PHP Using FaceBook Notification



PHP USING NOTIFICATION

What is Push Notification ?
A push notification is a message that pops up on a mobile device and Desktops  App publishers can send them at any time  using their devices to receive Your Mobile or Desktop

Ex:
 



<html>
<head>
</head>
<body>
<table cellpadding="4">
<form method="  post " action="">
<tr><td>regno</td><td><input id=" i1" type="text " placeholder=" Enter your regno " required name=" reg "> </td> </tr>
<tr><td>name</td><td><input id=" i2 " type=" text " placeholder=" Enter your name " required name=" nm "> <br>
<tr> <td> Notfication </td> <td> <textarea  id="i3" required name="t1" height="300" width="300"> </textarea> </td> </tr>
</table>
<input type=" submit " value=" send " onclick="return chk();" name="s">
</form>
</body>
</html>
<?php

// include the file
include('con1.php');
// check the submit button is clicked or not
if(isset($_POST['s'])){
$reg=$_POST['reg'];   
$nm=$_POST['nm'];
$res=$_POST['t1'];

// insert the data into mysql database
$sql="INSERT INTO `mark` (`regno`,`name`,`result`) VALUES ('$reg','$nm','$res')";
$con->query($sql);
}
?>
<?php include('con1.php'); ?>
<html>
<head>
<style>#i{background-color:red;} #in {
    border-top: none;
    border-left: none;
    border-right: none;
    border-bottom: 1px solid;

    box-shadow: 1px 1px;
   margin-top:0px;
margin-top: 0px;
    margin-left: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
    padding-top: 0px;
    padding-left: 0px;

    padding-right: 0px;

}#in:focus {
    padding: 15px;
    transition: padding 0.4s;
@media only screen and (max-width: 480px) {
    .contact-details .detail {
      display: block;
    }
  }
  .card-skills {
    position: relative;
  }
  .skill-info {
    margin-left: 20px;
  }
  @media only screen and (min-width: 768px) {
    .skill {
      border-left: 9px solid #555555;
    }
    .skill.beginner {
      height: 50%;
      border-color: #e74c3c;
    }
    .skill.intermediate {
      height: 70%;
      border-color: #f1c40f;
    }
    .skill.advanced {
      border-color: #5cb85c;
    }
    .skill.master {
      border-color: black;
    }
  }
  @media (max-width: 768px) {
    .quote {
      font-size: inherit;
    }
  }
  @media print {
    body {
      font-size: 10pt;
    }
    a[href]:after {
      content: none !important;
    }
    .pagebreak {
      page-break-before: always;
    }
    .background-card h4:not(:first-child) {
      margin-top: 0 !important;
    }
    .card {
      border: 0;
      padding: 0;
    }
    .container {
      max-width: 100%;
      width: 100%;
    }
    .contact-details .detail .icon {
      color: #888 !important;
    }
</style>
</head>
</html>
<form method=" post " action="">
<?php
$sql=" SELECT count(result) FROM `mark` ";
$res=$con->query($sql);
while( $row= mysqli_fetch_array($res)){

$cnt = $row['count(result)'];
if($cnt<=0){
    echo "<button> Notfication(  ) </button>";
}else {
    ?>
<input type=" submit " id= 'i'  name= "sub" value= "Notfication (<?php echo $cnt; ?>)"> </button> <br>
&nbsp;
&nbsp;
<?php
}
}
if(isset($_POST['sub'])){
$qry="select *  FROM `mark`";
$re=$con->query($qry);
while($row=mysqli_fetch_array($re)){
?>
&nbsp;
&nbsp;
<?php echo "<b id='i1'>".$row['result']."</b>.<br>"; ?>
<?php   
}
}
echo "<style>
.i1{
background-color:gray;   
}
</style>";

?>

Before Output:






After Output:

            











Jquery or Javascript Start Exam Time

 <script> function startTimer() {      var date = "<?php echo $date ?>"; // dynamic date      var time = "<?...