Tuesday 22 October 2019

Captcha

phptextClass.php

?php

class phptextClass
{
public function phpcaptcha($textColor,$backgroundColor,$imgWidth,$imgHeight,$noiceLines=0,$noiceDots=0,$noiceColor='#162453')
{
/* Settings */
$text=$this->random();
$font = './font/monofont.ttf';/* font */
$textColor=$this->hexToRGB($textColor);
$fontSize = $imgHeight * 0.75;

$im = imagecreatetruecolor($imgWidth, $imgHeight);
$textColor = imagecolorallocate($im, $textColor['r'],$textColor['g'],$textColor['b']);

$backgroundColor = $this->hexToRGB($backgroundColor);
$backgroundColor = imagecolorallocate($im, $backgroundColor['r'],$backgroundColor['g'],$backgroundColor['b']);

/* generating lines randomly in background of image */
if($noiceLines>0){
$noiceColor=$this->hexToRGB($noiceColor);
$noiceColor = imagecolorallocate($im, $noiceColor['r'],$noiceColor['g'],$noiceColor['b']);
for( $i=0; $i<$noiceLines; $i++ ) {
imageline($im, mt_rand(0,$imgWidth), mt_rand(0,$imgHeight),
mt_rand(0,$imgWidth), mt_rand(0,$imgHeight), $noiceColor);
}}

if($noiceDots>0){/* generating the dots randomly in background */
for( $i=0; $i<$noiceDots; $i++ ) {
imagefilledellipse($im, mt_rand(0,$imgWidth),
mt_rand(0,$imgHeight), 3, 3, $textColor);
}}

imagefill($im,0,0,$backgroundColor);
list($x, $y) = $this->ImageTTFCenter($im, $text, $font, $fontSize);
imagettftext($im, $fontSize, 0, $x, $y, $textColor, $font, $text);

imagejpeg($im,NULL,90);/* Showing image */
header('Content-Type: image/jpeg');/* defining the image type to be shown in browser widow */
imagedestroy($im);/* Destroying image instance */
if(isset($_SESSION)){
$_SESSION['captcha_code'] = $text;/* set random text in session for captcha validation*/
}
}

/*function to convert hex value to rgb array*/
protected function hexToRGB($colour)
{
        if ( $colour[0] == '#' ) {
$colour = substr( $colour, 1 );
        }
        if ( strlen( $colour ) == 6 ) {
list( $r, $g, $b ) = array( $colour[0] . $colour[1], $colour[2] . $colour[3], $colour[4] . $colour[5] );
        } elseif ( strlen( $colour ) == 3 ) {
list( $r, $g, $b ) = array( $colour[0] . $colour[0], $colour[1] . $colour[1], $colour[2] . $colour[2] );
        } else {
return false;
        }
        $r = hexdec( $r );
        $g = hexdec( $g );
        $b = hexdec( $b );
        return array( 'r' => $r, 'g' => $g, 'b' => $b );
}


/*function to get center position on image*/
protected function ImageTTFCenter($image, $text, $font, $size, $angle = 8)
{
$xi = imagesx($image);
$yi = imagesy($image);
$box = imagettfbbox($size, $angle, $font, $text);
$xr = abs(max($box[2], $box[4]))+5;
$yr = abs(max($box[5], $box[7]));
$x = intval(($xi - $xr) / 2);
$y = intval(($yi + $yr) / 2);
return array($x, $y);
}

}
?>
_________________________________________________

demo.php

<?php session_start();

if(isset($_POST['Submit'])){
// code for check server side validation
if(empty($_SESSION['captcha_code'] ) || strcasecmp($_SESSION['captcha_code'], $_POST['captcha_code']) != 0){ 
$msg="<span style='color:red'>The Validation code does not match!</span>";// Captcha verification is incorrect.
}else{// Captcha verification is Correct. Final Code Execute here!
$msg="<span style='color:green'>The Validation code has been matched.</span>";
}
}
?>
 
  <form action="" method="post" name="form1" id="form1" >
  <table width="400" border="0" align="center" cellpadding="5" cellspacing="1" class="table">
    <?php if(isset($msg)){?>
    <tr>
      <td colspan="2" align="center" valign="top"><?php echo $msg;?></td>
    </tr>
    <?php } ?>
    <tr>
      <td align="right" valign="top"> Validation code:</td>
      <td><img src="captcha.php?rand=<?php echo rand();?>" id='captchaimg'><br>
        <label for='message'>Enter the code above here :</label>
        <br>
        <input id="captcha_code" name="captcha_code" type="text">
        <br>
        Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh.</td>
    </tr>
    <tr>
      <td> </td>
      <td><input name="Submit" type="submit" onclick="return validate();" value="Submit" class="button1"></td>
    </tr>
  </table>
</form>
________________________________________
captcha.php


<?php
session_start();
include("./phptextClass.php");

/*create class object*/
$phptextObj = new phptextClass();
/*phptext function to genrate image with text*/
$phptextObj->phpcaptcha('#162453','#fff',120,40,10,25);
 ?>

PHP Calc

<?php

$page = $_GET['page'];

// Defining the "calc" class
class calc {
     var $number1;
     var $number2;

          function add($number1,$number2)
          {
                   $result =$number1 + $number2;
                    echo("The sum of $number1 and $number2 is $result<br><br>");
                    echo("$number1 + $number2 = $result");
                    exit;
           }

          function subtract($number1,$number2)
          {
                   $result =$number1 - $number2;
                    echo("The difference of $number1 and $number2 is $result<br><br>");
                    echo("$number1 &#045 $number2 = $result");
                    exit;
           }

          function divide($number1,$number2)
          {
                   $result =$number1 / $number2;
                    echo("$number1 divided by $number2 is $result<br><br>");
                    echo("$number1 ÷ $number2 = $result");
                    exit;
           }

          function multiply($number1,$number2)
          {
                   $result =$number1 * $number2;
                    echo("The product of $number1 and $number2 is $result<br><br>");
                    echo("$number1 x $number2 = $result");
                    exit;
           }
}
$calc = new calc();
?>
<TITLE>PHP Calculator v1</TITLE>
<form name="calc" action="?page=calc" method="POST">
Number 1: <input type=text name=value1><br>
Number 2: <input type=text name=value2><br>
Operation: <input type=radio name=oper value="add">Addition <input type=radio name=oper value="subtract">Subtraction <input type=radio name=oper value="divide">Division <input type=radio name=oper value="multiply">Multiplication</input><br>
<input type=submit value="Calculate">
</form>
<?php
if($page == "calc"){
$number1 = $_POST['value1'];
$number2 = $_POST['value2'];
$oper = $_POST['oper'];
     if(!$number1){
          echo("You must enter number 1!");
          exit;
     }
     if(!$number2){
          echo("You must enter number 2!");
          exit;
     }
     if(!$oper){
          echo("You must select an operation to do with the numbers!");
          exit;
     }
     if(!eregi("[0-9]", $number1)){
          echo("Number 1 MUST be numbers!");
          exit;
     }
     if(!eregi("[0-9]", $number2)){
          echo("Number 2 MUST be numbers!");
          exit;
     }
     if($oper == "add"){
          $calc->add($number1,$number2);
     }
     if($oper == "subtract"){
          $calc->subtract($number1,$number2);
     }
     if($oper == "divide"){
          $calc->divide($number1,$number2);
     }
     if($oper == "multiply"){
          $calc->multiply($number1,$number2);
     }
}
?>

PHP New

login.php

<form action="" method="post" name="Login_Form">
  <table width="400" border="0" align="center" cellpadding="5" cellspacing="1" class="Table">
    <?php if(isset($msg)){?>
    <tr>
      <td colspan="2" align="center" valign="top"><?php echo $msg;?></td>
    </tr>
    <?php } ?>
    <tr>
      <td colspan="2" align="left" valign="top"><h3>Login</h3></td>
    </tr>
    <tr>
      <td align="right" valign="top">Username</td>
      <td><input name="Username" type="text" class="Input"></td>
    </tr>
    <tr>
      <td align="right">Password</td>
      <td><input name="Password" type="password" class="Input"></td>
    </tr>
    <tr>
      <td> </td>
      <td><input name="Submit" type="submit" value="Login" class="Button3"></td>
    </tr>
  </table>
</form>

______________________________________________________
Step 2: Next we need to write a php script to check the
login authentication.


<?php session_start(); /* Starts the session */

/* Check Login form submitted */
if(isset($_POST['Submit'])){
/* Define username and associated password array */
$logins = array('Alex' => '123456','username1' => 'password1','username2' => 'password2');

/* Check and assign submitted Username and Password to new variable */
$Username = isset($_POST['Username']) ? $_POST['Username'] : '';
$Password = isset($_POST['Password']) ? $_POST['Password'] : '';

/* Check Username and Password existence in defined array */
if (isset($logins[$Username]) && $logins[$Username] == $Password){
/* Success: Set session variables and redirect to Protected page  */
$_SESSION['UserData']['Username']=$logins[$Username];
header("location:index.php");
exit;
} else {
/*Unsuccessful attempt: Set error message */
$msg="<span style='color:red'>Invalid Login Details</span>";
}
}
?>

____________________________________________________________

Step 3: If the login is correct then we need to redirect page to
 protected area.So need an protected script page too.

index.php

<?php session_start(); /* Starts the session */

if(!isset($_SESSION['UserData']['Username'])){
header("location:login.php");
exit;
}
?>
__________________________________________________________

index.php

<?php session_start(); /* Starts the session */

if(!isset($_SESSION['UserData']['Username'])){
header("location:login.php");
exit;
}
?>

Congratulation! You have logged into password protected page.
<a href="logout.php">Click here</a> to Logout.
__________________________________________________________

logout.php

<?php session_start(); /* Starts the session */
session_destroy(); /* Destroy started session */
header("location:login.php");  /* Redirect to login page */
exit;
?>
Congratulation! You have logged into password protected page. <a href="logout.php">Click here</a> to Logout.
Ready, now our login system perfectly done but we also need to provide a logout facility to user, so we require to create a logout page.

logout.php
Example:
<?php session_start(); /* Starts the session */
session_destroy(); /* Destroy started session */
header("location:login.php");  /* Redirect to login page */
exit;
?>

Thursday 17 October 2019

DT -EA

install.packages("party")
library(party)
View(readingSkills)

input = readingSkills[c(1:105),]

View(input)

output = ctree(
  nativeSpeaker ~ age + shoeSize + score,
  data = input)

plot(output)

Sunday 13 October 2019

Kmeans

library(ggplot2)

df <- data.frame(age = c(18, 21, 22, 24, 26, 26, 27, 30, 31, 35, 39, 40, 41, 42, 44, 46, 47, 48, 49, 54),
    spend = c(10, 11, 22, 15, 12, 13, 14, 33, 39, 37, 44, 27, 29, 20, 28, 21, 30, 31, 23, 24))

ggplot(df, aes(x = age, y = spend)) + geom_point()

____________________________________________________________

CODE: HIERACHICAL CLUSTERING

clusters <- hclust(dist(iris[, 3:4]))
plot(clusters)

clusterCut <- cutree(clusters, 3)

plot(clusterCut,type="p")
table(clusterCut, iris$Species)

ggplot(iris, aes(Petal.Length, Petal.Width, color = iris$Species)) +
  geom_point(alpha = 0.4, size = 3.5) + geom_point(col = clusterCut) +
  scale_color_manual(values = c('black', 'red', 'green'))

_______________________________________

install.packages(“devtools”)
install.packages(“factoextra”)

library(devtools)
library(factoextra)
 
data("multishapes")
df <- multishapes[, 1:2]
set.seed(123)
km.res <- kmeans(df, 5, nstart = 25)
fviz_cluster(km.res, df, frame = FALSE, geom = "point")

Saturday 12 October 2019

LR shiny


library(shiny)

ui <- fluidPage(
  pageWithSidebar(
   
    headerPanel("HP prediction"),
   
    sidebarPanel(
      numericInput(inputId = "noofCYL",
                   label = "noofCYL",
                   min = 40, max = 160, value = 100),
      actionButton('go',"Predict")
    ),
   
    mainPanel( textOutput("value") )
  )
)




server <- function(input, output, session) {
 
  data <- reactiveValues()
  observeEvent(input$go,{
    #browser()
    data$var <-input$noofCYL
   
    newPredict = data.frame(cyl=data$var)
   
    modelLM = lm(hp~cyl, data = mtcars)
   
    data$op = predict(modelLM, newPredict)
  })
 
  lstat = renderText({data$var})
 
  output$value <- renderPrint({data$op})
}

shinyApp(ui, server)

Friday 11 October 2019

Rshiny

library(shiny)

ui = fluidPage(
   titlePanel("TABLE"),
    sidebarLayout(
      sidebarPanel(
        sliderInput("num", "integer", 1, 20, 1,
                    step = 1, animate =
                      animationOptions(interval=400, loop=TRUE))),
      mainPanel(
        tableOutput("iim")
      )) )
 
server = function(input, output) {
    output$iim = renderPrint({ x<-input$num
    for(i in 1:10){
      a=x*i
      cat(x,"x",i,"=",a,"<br>")
       }})}

shinyApp(ui = ui, server = server)

Wednesday 9 October 2019

DataSets - IIM

https://drive.google.com/open?id=1oD1mFi4zmqz5xGuCJ7_OdUKZgW5fekct


https://drive.google.com/file/d/1M4sGfss3DLYosCxWZoai2i9X1AMZoolb/view?usp=sharing




s=subset(movies_data,(movies_data$Rating>=3 & movies_data$Rating<4)& (grepl("^5",movies_data$Duration) &  grepl("*5$",movies_data$Duration)))




View(s)

___________________________________

greatest=function(A,B,C){

if(A>B){
  {
    if(A>C)
print("A is greater number")
  }}else if(B>C){
print("B is greater")
}else{
  print("C is greater")
}}


greatest(3,15,417)
__________________________________________

colors=c("green","orange","brown")                  
months=c("mar","apr","may","jun","jul")
regions=c("east","west","north")
values=matrix(c(2,4,5,3,5,2,5,3,7,8,9,4,7),nrow=3,ncol=5,byrow=TRUE)
barplot(values,names.arg=m,xlab="month",ylab="revenue",col=colors,main="revenue chart",border="red")

legend("topleft",regions,cex=1.3,fill=colors)


Tuesday 8 October 2019

R Shiny

library(shiny)
ui <- fluidPage(
   titlePanel("TABLE"),
    sidebarLayout(
      sidebarPanel(
        sliderInput("num", "integer", 1, 20, 1,
                    step = 1, animate =
                      animationOptions(interval=400, loop=TRUE))),
      mainPanel(
        tableOutput("prod")
      )) )
 
server <- function(input, output) {
    output$prod <- renderPrint({ x<-input$num
    for(i in 1:10){
      a=x*i
      cat(x,"x",i,"=",a,"<br>")
       }})}

shinyApp(ui = ui, server = server)