Kamis, 22 Agustus 2019

Import XLS


    <html>
    <head>
    <title>How To Import Excel (.xls) File To MySql Database Using PHP</title>
    </head>
    <body>
    <center><h1>TES UPLOAD</h1></center>
    <form name="import_export_form" method="post" action="" enctype="multipart/form-data">
    <label>Select Excel File : </label><input type="file" name="excelfile"/><br>
    <input type="submit" name="form_submit"/>
    </form>
    </body>
    </html>


<?php
 if(isset($_POST['form_submit'])){
require_once 'Excel/reader.php';
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('CP1251');
$filename = $_FILES['excelfile']['tmp_name'];
$nf = $_FILES['excelfile']['name'];

$data->read($filename);
$n=0;

for($x =2; $x <=count ($data->sheets[0]["cells"]); $x++){
$v1 = $data->sheets[0]["cells"][$x][2];
$v2= $data->sheets[0]["cells"][$x][3];
$v3= $data->sheets[0]["cells"][$x][4];
$v4= $data->sheets[0]["cells"][$x][5];
$v5= $data->sheets[0]["cells"][$x][6];
$v6= $data->sheets[0]["cells"][$x][7];

$n++;
echo $sql=" INSERT INTO `tb_data` (
``v1` ,`v2` ,`v3` ,`v4` ,`v5` ,`v6`) VALUES
('$v1', '$v2', '$v3', '$v4', '$v5', '$v6')";


}//for
}//isset




Download

Download File

<?php
$direktori = "ypathfile/";
$namafile=$_GET["file"];
if (!file_exists($direktori.$namafile)) {
  echo "<h1>Access forbidden!</h1>
        <p>Maaf, file $namafile yang Anda download sudah tidak tersedia atau filenya (direktorinya) telah diproteksi. <br />
        Silahkan hubungi <a href='mailto:adiarray@gmail.com'>Administrator Web</a>.</p>";
  exit();
}
else {
  header("Content-Type: octet/stream");
  header("Content-Disposition: attachment; filename=\"".$namafile."\"");
  $fp = fopen($direktori.$namafile, "r");
  $data = fread($fp, filesize($direktori.$namafile));
  fclose($fp);
  print $data;
}
?>




PHP Tiny

Download
<html>
<head>
<title>Dengan Editor TinyMCE</title>
<script type="text/javascript" src="jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
   tinyMCE.init({
mode : "textareas",
theme : "advanced",
   });
</script>
</head>
<body>

<form method="post" action="">
  Isi Berita:<br />
  <textarea name="isi" cols="30" rows="10"></textarea>
  <input type="submit" value="Simpan" />
</form>
</body>
</html>



PHP COde Pilihan Biasa

<div class="top_right">
<div class="languages">
<div class="lang_text"><b><font color='red'>PILIHAN BAHASA</font></b><ul></div>
        <a href="http://209.85.135.104/translate_c?hl=id&langpair=id%7Cen&u=<?php echo $web;?>/" class="lang">
        <img src="ypathicon/en.gif" alt="" border="0" /></a>
       
        <a href="http://209.85.135.104/translate_c?hl=id&langpair=id%7Cen&u=<?php echo $web;?>/" class="lang">
        <img src="ypathicon/de.gif" alt="" border="0" /></a>
       
        <a href="#" class="lang">
        <img src="ypathicon/id.jpeg" alt="" border="0" /></a>
</div>
</div>
<hr>




Ajax Combobox

<html>
<head>

<script type="text/javascript">
var xmlHttp

function showUser(str){
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){
 alert ("Browser tidak support HTTP Request")
 return
 }
var url="getuser.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=SC1
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function SC1() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
 document.getElementById("txtHint").innerHTML=xmlHttp.responseText
 }
}

function GetXmlHttpObject(){
var xmlHttp=null;
try{xmlHttp=new XMLHttpRequest();}
catch (e){
try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
  catch (e){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
 }
return xmlHttp;
}
</script>

</head>
<body>
<form>
Pilih User:
<select name="users" onChange="showUser(this.value)">
<option value="1">Nama ID 1</option>
<option value="2">Nama ID 2</option>
<option value="3">Nama ID 3</option>
    <option value="4">Nama ID 4</option>
</select>
</form>
<p>
<div id="txtHint"><b>Informasi user akan tampil di sini...</b></div>
</p>
</body>
</html>



+++++++++++++++
<?php
session_start();
$jmldata=10;
?>
<html>
<head>
<script type="text/javascript">
function Ajax(){
var $http,$self = arguments.callee;

if (window.XMLHttpRequest) {$http = new XMLHttpRequest();} 
else if (window.ActiveXObject) {
try {$http = new ActiveXObject('Msxml2.XMLHTTP');} 
catch(e) {$http = new ActiveXObject('Microsoft.XMLHTTP');}
}

if ($http) {
$http.onreadystatechange = function(){
if (/4|^complete$/.test($http.readyState)) {
document.getElementById('ReloadThis').innerHTML = $http.responseText;
setTimeout(function(){$self();}, 1000);
}
};
$http.open('GET', 'songinfo.php' + '?' + new Date().getTime(), true);
$http.send(null);
}
}
</script>
<script type="text/javascript">setTimeout(function() {Ajax();}, 1000);</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body></body>
</html>
<hr />HTTP://www.LP2M-ARAY: <div id="ReloadThis">Default text</div>


PHP Code Captcha

Download

<?php
session_start();

?>
<form action="" method="post">
<table width="407"  style='border: 1pt dashed #0000CC;padding: 10px;'>

<tr>
  <td>Input Kode
  <td>
  <td><img src="setcaptcha.php"></td>
</tr>
<tr>
  <td>
  <td>
  <td>
  <input type="text" name="kodecaptcha" size="6" maxlength="6">
   (Masukkan 6 kode diatas)
  </td>
</tr>

<tr>
<td>
<td>
<td><input name="Simpan" type="submit" id="Simpan" value="Simpan" />
</td></tr>
</table>
</form>


<?php
if(isset($_POST["Simpan"])){


if($_POST["kodecaptcha"]==$_SESSION["captcha_session"]){

echo"<h1>Sukses Simpan....</h1>";
}
else{
echo"<h1>Gagal Simpan....</h1>";

}
}
?>

+++++++++++++++++++

<?php
session_start();
header("Content-type: image/png");
$captcha_image = imagecreatefrompng("captcha.png");
$captcha_font = imageloadfont("font.gdf");
$captcha_text = substr(md5(uniqid('')),-6,6);

$_SESSION['captcha_session'] = $captcha_text;

$captcha_color = imagecolorallocate($captcha_image,0,0,0);
imagestring($captcha_image,$captcha_font,15,5,$captcha_text,$captcha_color);
imagepng($captcha_image);
imagedestroy($captcha_image);
?>

PHP TO PDF FILE



<?php
session_start();
ob_start();

?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Laporan Data Nilai</title>
</head>
<body>
<?php
echo "<h1>Nilai Siswa LP2MARAY</h1>";
echo '<table border="0">
  <tr>
    <td width="100">NAMA</td>
    <td width="10">:</td>
    <td width="250">Riadi Marta Dinata</td>
  </tr>
  <tr>
    <td>TGL LAHIR</td>
    <td>:</td>
    <td>20 Agustus 1987</td>
  </tr>
  <tr>
    <td>ALAMAT</td>
    <td>:</td>
    <td>Kampung Sawah RT01/01 Jakarta Selatan</td>
  </tr>
   <tr>
    <td>TELEPON</td>
    <td>:</td>
    <td>082111476069</td>
  </tr>
  <tr>
    <td>ANGKATAN</td>
    <td>:</td>
    <td>B I M A</td>
  </tr>
</table>';

echo "<p>data yang tertera di atas adalah Siswa Terbaik di LP2M ARAY.</p>";
echo "<p align='right'>JAKARTA, ".date('d-m-Y')."
<img src='ttd.jpg' width='120'>
( Riadi Marta Dinata )</p>";
?>
</body>
</html>





<?php
$filename="namafile-".date("YmdHis").".pdf";


$content = ob_get_clean();
$content = '<page style="font-family: freeserif">'.nl2br($content).'</page>';
 require_once(dirname(__FILE__).'/html2pdf/html2pdf.class.php');
 try
 {
  $html2pdf = new HTML2PDF('P','A4','en', false, 'ISO-8859-15',array(30, 0, 20, 0));
  $html2pdf->setDefaultFont('Arial');
  $html2pdf->writeHTML($content, isset($_GET['vuehtml']));
  $html2pdf->Output($filename);
 }
 catch(HTML2PDF_exception $e) { echo $e; }
?>


DOWNLOAD


IFRAME GMAPS

<?php
echo"<div class='center_content'>";
echo "<div class='center_title_bar'>Lokasi Kami</b></div>";
echo "<div class='center_prod_box_big'>"; 


$frame="http://maps.google.com/maps/ms?msa=0&msid=203038942996608606794.000499e7b9b2535ca5b0d&ie=UTF8&t=m&vpsrc=0&z=16&output=embed";

echo "<iframe width='100%' height='630' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='$frame'></iframe><br />
<div align='center'>
<a href='$frame' title='Lokasi Kami'><strong>Lihat Lebih Dekat</strong></a><br>
<h1>LP2MARAY</h1>
</div>";

echo"</div></div>";
?>





GRAPH




https://canvasjs.com/
https://canvasjs.com/javascript-charts/
https://canvasjs.com/php-charts/










<head>
    <link class="include" rel="stylesheet" type="text/css" href="lib/jquery.jqplot.min.css" />
    <link rel="stylesheet" type="text/css" href="lib/examples.min.css" />
    <link type="text/css" rel="stylesheet" href="lib/syntaxhighlighter/styles/shCoreDefault.min.css" />
    <link type="text/css" rel="stylesheet" href="lib/syntaxhighlighter/styles/shThemejqPlot.min.css" />
 
    <script class="include" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
</head>

<h1>Grafik LP2MARAY</h1>
<div id="chart1" style="width:1100; height:300px"></div>

<script class="code" type="text/javascript">
    $(document).ready(function () {
        var s1 = [[2002, 112000], [2003, 122000], [2004, 104000], [2005, 99000], [2006, 121000],
        [2007, 148000], [2008, 114000], [2009, 133000], [2010, 161000], [2011, 173000]];

        var s2 = [[2002, 10200], [2003, 10800], [2004, 11200], [2005, 11800], [2006, 12400],
        [2007, 12800], [2008, 13200], [2009, 12600], [2010, 13100]];

        plot1 = $.jqplot("chart1", [s2, s1], {
            animate: true,
            animateReplot: true,
            cursor: {
                show: true,
                zoom: true,
                looseZoom: true,
                showTooltip: true
            },
            series:[
                {
                    pointLabels: { show: true },
                    renderer: $.jqplot.BarRenderer,
                    showHighlight: false,
                    yaxis: 'y2axis',
                    rendererOptions: {
                        animation: { speed: 2500 },
                        barWidth: 25,
                        barPadding: -150,
                        barMargin: 50,
                        highlightMouseOver: false
                    }
                },
                {
                    rendererOptions: { animation: { speed: 2000 } }
                }
            ],
            axesDefaults: {
                pad: 0
            },
            axes: {
                xaxis: {
                    tickInterval: 10,
                    drawMajorGridlines: true,
                    drawMinorGridlines: true,
                    drawMajorTickMarks: true,
                    rendererOptions: { tickInset: 0.5,
                    minorTicks: 1 }
                },
                yaxis: {
                    tickOptions: {
                        formatString: "%'d"
                    },
                    rendererOptions: {
                        forceTickAt0: true
                    }
                },
                y2axis: {
                    tickOptions: { formatString: "%'d" },
                    rendererOptions: {
                        alignTicks: true,
                        forceTickAt0: true
                    }
                }
            },
            highlighter: {
                show: true,
                showLabel: true,
                tooltipAxes: 'y',
                sizeAdjust: 127.5 , tooltipLocation : 'ne'
            }
        });
     
    });

</script>
    <script class="include" type="text/javascript" src="lib/jquery.jqplot.min.js"></script>
    <script type="text/javascript" src="lib/syntaxhighlighter/scripts/shCore.min.js"></script>
    <script type="text/javascript" src="lib/syntaxhighlighter/scripts/shBrushJScript.min.js"></script>
    <script type="text/javascript" src="lib/syntaxhighlighter/scripts/shBrushXml.min.js"></script>
  <script class="include" type="text/javascript" src="lib/plugins/jqplot.barRenderer.min.js"></script>
  <script class="include" type="text/javascript" src="lib/plugins/jqplot.highlighter.min.js"></script>
  <script class="include" type="text/javascript" src="lib/plugins/jqplot.cursor.min.js"></script>
  <script class="include" type="text/javascript" src="lib/plugins/jqplot.pointLabels.min.js"></script>
<script type="text/javascript" src="lib/example.min.js"></script>




Download

CS LIB

cs.php
download 

<?php
$comment=$_GET["comment"];
$user=$_GET["user"];

require_once __DIR__ . '/vendor/autoload.php';

//error_reporting(0);

$initos = new \Sastrawi\Stemmer\StemmerFactory();
$bikinos = $initos->createStemmer();
$stemming=$bikinos->stem($comment);
$stemmingnew=strtolower($stemming);

$ak=getStopNumber();
$ar=getStopWords();
$wordStop=$stemmingnew;
for($i=0;$i<count($ar);$i++){
 $wordStop =str_replace($ar[$i]." ","", $wordStop);
}

for($i=0;$i<count($ak);$i++){
 $wordStop =str_replace($ak[$i],"", $wordStop);
}
$juduluji=str_replace("  "," ", $wordStop);
//=====================================================
 $stemming=$juduluji;

 ?>


<table width="80%">

<tr>
<td height="24"><label for="nim">User</label>
<td>:<td colspan="2"><?php echo $user;?></td>
</tr>
<tr>
<td height="24"><label for="nim">Comment</label>
<td>:<td colspan="2"><?php echo $comment;?></td>
</tr>
<tr>
<td height="24"><label for="nim">Casefolding</label>
<td>:<td colspan="2"><?php echo strtolower($comment);?></td>
</tr>
<tr>
<td height="24"><label for="nim">Stemming</label>
<td>:<td colspan="2"><?php echo $stemmingnew;?></td>
</tr>

<tr>
<td height="24"><label for="nim">Wordstop</label>
<td>:<td colspan="2"><?php echo $stemming;?></td>
</tr>

</table>
<?php
 //======================================
 
    $sql="select * from `data_training`  order by `id` asc"; // limit 0,4
$arr=getData($conn,$sql);
$i=0;
$arNorm[$i]=$stemming;
$arKomentar[$i]=$comment;
$arKode[$i]=0;
$arKat[$i]="?";
$arKe[$i]="Dokumen ke-".($i);
$TOT[$i]=0;

$gabungan=$stemming." ";
foreach($arr as $d) {
$i++;
$id=$d["id"];
$komentar=$d["komentar"];
$label=$d["label"];
$normalisasi=$d["normalisasi"];

$arKode[$i]=$id;
$arKat[$i]=$label;
$arKomentar[$i]=$komentar;
$arNorm[$i]=$normalisasi;
$arKe[$i]="Dokumen ke-".($i);
$TOT[$i]=0;

$gabungan.=$normalisasi." ";
}
$jumk=$i;
 //======================================


  $arAsli=explode(" ",$gabungan);
  $arUnix0=array_unique($arAsli);

  $ii=0;
  for($i=0;$i<count($arUnix0);$i++){
  if($arUnix0[$i]==""){}
  else{
  $arUnix[$ii]=$arUnix0[$i];
  $ii++;
}
  }

 $jumb=count($arUnix);

echo"<table width='100%' border='1'>";
echo"<tr><td>Kata";
echo"<td>Q";
 for($i=0;$i<$jumk;$i++){
  $u=$i+1;
  echo"<td>D".$u;
 }
 echo"<td>df";
 echo"<td>IDF";
 echo"<td>QDF";
 for($i=0;$i<$jumk;$i++){
  $u=$i+1;
  echo"<td>QD".$u;
 }

  for($i=0;$i<$jumk;$i++){
  $u=$i+1;
  echo"<td>QDFxQD".$u;
 }

  for($i=0;$i<=$jumk;$i++){
 
if($i==0){
echo"<td>QDF<sup>2</sup>";
}
else{
$u=$i;
echo"<td>QD$u<sup>2</sup>";
}
 }

echo"</tr>";

 $bar=count($arUnix);
 for($i=0;$i<$bar;$i++){
  $kata=$arUnix[$i];
  $hitung=0;
echo"<tr><td>".$kata."</td>";
$jumada=0;

   for($j=0;$j<=$jumk;$j++){
$ada=getHit($kata,$arNorm[$j]);
$MA[$i][$j]=$ada;
if($ada>0){
$jumada++;
}
echo"<td>".$ada;
   }
// $log=log($jumk+1,10)/$jumada;
$log=log(($jumk)/$jumada,10);
$log=abs($log);
echo"<td>$jumada</td>";//idf
echo"<td>log($jumk/$jumada)=$log";

   for($j=0;$j<=$jumk;$j++){
$ada=$MA[$i][$j];
$N[$i][$j]=$ada * $log;//X
$N2[$i][$j]=pow($N[$i][$j],2);

$TOT[$j]=$TOT[$j]+$N[$i][$j];
echo "<td>=$ada x $log";//.$N[$i][$j];//

   }
 
  for($j=1;$j<=$jumk;$j++){
$NN[$i][$j-1]=$N[$i][0] * $N[$i][$j];
echo "<td>".$NN[$i][$j-1];//Y
$TOT1[$j-1]+=$NN[$i][$j-1];//QDFxDF1...
   }
  for($j=0;$j<=$jumk;$j++){
echo "<td>".$N2[$i][$j];//Z
$TOT2[$j]+=$N2[$i][$j];
   }
 
 echo"</tr>";
 }//for i

//------------------------------------
echo"<tr><td>Kata";
echo"<td>Q";
 for($i=0;$i<$jumk;$i++){
  $u=$i+1;
  echo"<td>D".$u;
 }
 echo"<td>df";
 echo"<td>IDF";
 echo"<td>QDF";
 for($i=0;$i<$jumk;$i++){
  $u=$i+1;
  echo"<td>QD".$u;
 }

  for($i=0;$i<$jumk;$i++){
  echo"<td>".$TOT1[$i];
 }

  for($i=0;$i<=$jumk+1;$i++){
  echo"<td>".$TOT2[$i];
 }

echo"</tr>";


echo"</table>";
$Q=pow($TOT2[0],0.5);
//TOT1 mulai dari 0 krn tak ada Q
//TOT2 mulai dari 1 krn ada Q
$gab.="Qvalue=$TOT2[0]<sup>0.5</sup> =".$Q."<br><br>";
$gab.="Cosine Similarity Terhadap tiap-tiap dokumen:<br>";
$gab."<ol>";

 for($i=1;$i<=$jumk;$i++){
$E=pow($TOT2[$i],0.5);

$ES=$TOT2[$i]."<sup>0.5</sup>";
$QS=$TOT2[0]."<sup>0.5</sup>";

$D=pow(($TOT2[0]) * $TOT1[$i-1],0.5);
$DS="(".$TOT2[0]." x ".$TOT1[$i-1].")<sup>0.5</sup>";

//==========================================
$H[$i]=$D/($Q * $E)+0;
$PRO[$i]=round($H[$i]*100,2);

//$kes="<font color='green'>Negatif</font>";
$CS="CSvalue<sub>$i</sub> =$DS/($QS x ".$ES.")";

$komentar=$arKomentar[$i];
$kategori=$arKat[$i];
$rekapitulasi=$arNorm[$i]."<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=>".$CS.", #<i>Label $kategori</i>";

//==========================================OUT

$hsl="<li>Comment $i :<b>".$komentar."</b><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=>Proses Normalisasi: $rekapitulasi
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=><i>Bobot Cosine Similariry: $PRO[$i] %</i>";

$gab.=$hsl;

$hasilPro[$i-1]=$PRO[$i];
$hasilRekap[$i-1]=$hsl;
$hasilKomentar[$i-1]=$komentar;
$hasilNorm[$i-1]=$arNorm[$i];
$hasilKategori[$i-1]=$arKat[$i];
 }
 $gab.="</ol>";
echo $gab;


 $array_count = count($hasilPro);
        for($x = 0; $x < $array_count; $x++){
            for($a = 0 ;  $a < $array_count - 1 ; $a++){
                if($a < $array_count ){
                    if($hasilPro[$a] < $hasilPro[$a + 1] ){
                            swap($hasilPro, $a, $a+1);
swap($hasilRekap, $a, $a+1);
swap($hasilKomentar, $a, $a+1);
swap($hasilNorm, $a, $a+1);
swap($hasilKategori, $a, $a+1);

                    }
                }
            }
        }

$K=5;
$gab="<h3><b>Pengurutan Nilai K=$K besar</b></h3>";
$gab.="<ul>";
$J1=0;
$J2=0;
for($x = 0; $x < $array_count; $x++){
$gab.=$hasilRekap[$x];

if($hasilKategori[$x]==1){$J1++;}
else{$J2++;}
}
$gab.="<ul>";

$kes="LABEL 1";
if($J2>$J1){
$kes="LABEL 0";
}
echo $gab;
echo"<h3>HASIL KATEGORI $kes</h3><hr>";

?>


</div>
</div>


+++++++++++++++++++++++++++++++

comment.php

<?php


require_once __DIR__ . '/vendor/autoload.php';
$initos = new \Sastrawi\Stemmer\StemmerFactory();
$bikinos = $initos->createStemmer();
$ak=getStopNumber();
$ar=getStopWords();


function getUJUI($bikinos, $comment,$ak,$ar,$conn){
$stemming=$bikinos->stem($comment);
$stemmingnew=strtolower($stemming);

$wordStop=$stemmingnew;
for($i=0;$i<count($ar);$i++){
$wordStop =str_replace($ar[$i]." ","", $wordStop); 
}

for($i=0;$i<count($ak);$i++){
$wordStop =str_replace($ak[$i],"", $wordStop); 
}
$juduluji=str_replace("  "," ", $wordStop); 
//=====================================================
$stemming=$juduluji;


$sql="select * from `data_training`  order by `id` asc"; // limit 0,4
$arr=getData($conn,$sql);
$i=0;
$arNorm[$i]=$stemming;
$arKomentar[$i]=$comment;
$arKode[$i]=0;
$arKat[$i]="?";
$arKe[$i]="Dokumen ke-".($i);
$TOT[$i]=0;
$gabungan=$stemming." ";
foreach($arr as $d) {
$i++;
$id=$d["id"];
$komentar=$d["komentar"];
$label=$d["label"];
$normalisasi=$d["normalisasi"];
$arKode[$i]=$id;
$arKat[$i]=$label;
$arKomentar[$i]=$komentar;
$arNorm[$i]=$normalisasi;
$arKe[$i]="Dokumen ke-".($i);
$TOT[$i]=0;
 
$gabungan.=$normalisasi." ";
}
$jumk=$i;
 //======================================
  $arAsli=explode(" ",$gabungan);
  $arUnix0=array_unique($arAsli);
  
  $ii=0;
  for($i=0;$i<count($arUnix0);$i++){
  if($arUnix0[$i]==""){}
  else{
  $arUnix[$ii]=$arUnix0[$i];
  $ii++;
}
  }
  
 $jumb=count($arUnix);
 $bar=count($arUnix);
 for($i=0;$i<$bar;$i++){
  $kata=$arUnix[$i];
  $hitung=0;
$jumada=0;
   for($j=0;$j<=$jumk;$j++){
$ada=getHit($kata,$arNorm[$j]);
$MA[$i][$j]=$ada;
if($ada>0){
$jumada++;
}
   }
$log=log(($jumk)/$jumada,10); 
$log=abs($log);
   for($j=0;$j<=$jumk;$j++){
$ada=$MA[$i][$j];
$N[$i][$j]=$ada * $log;//X
$N2[$i][$j]=pow($N[$i][$j],2);
$TOT[$j]=$TOT[$j]+$N[$i][$j];
   }
   
  for($j=1;$j<=$jumk;$j++){
$NN[$i][$j-1]=$N[$i][0] * $N[$i][$j];
$TOT1[$j-1]+=$NN[$i][$j-1];//QDFxDF1...
   }
  for($j=0;$j<=$jumk;$j++){
$TOT2[$j]+=$N2[$i][$j];
   }
   
 }//for i

$Q=pow($TOT2[0],0.5);
 for($i=1;$i<=$jumk;$i++){
$E=pow($TOT2[$i],0.5);
$ES=$TOT2[$i]."<sup>0.5</sup>";
$QS=$TOT2[0]."<sup>0.5</sup>";
$D=pow(($TOT2[0]) * $TOT1[$i-1],0.5);
$DS="(".$TOT2[0]." x ".$TOT1[$i-1].")<sup>0.5</sup>";
//==========================================
$H[$i]=$D/($Q * $E)+0;
$PRO[$i]=round($H[$i]*100,2);
$CS="CSvalue<sub>$i</sub> =$DS/($QS x ".$ES.")";
$komentar=$arKomentar[$i];
$kategori=$arKat[$i];
$rekapitulasi=$arNorm[$i]."<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=>".$CS.", #<i>Label $kategori</i>";
//==========================================OUT
$hsl="<li>Comment $i :<b>".$komentar."</b><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=>Proses Normalisasi: $rekapitulasi
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=><i>Bobot Cosine Similariry: $PRO[$i] %</i>";
$gab.=$hsl;
$hasilPro[$i-1]=$PRO[$i];
$hasilRekap[$i-1]=$hsl;
$hasilKomentar[$i-1]=$komentar;
$hasilNorm[$i-1]=$arNorm[$i];
$hasilKategori[$i-1]=$arKat[$i];
 }
 $gab.="</ol>";
 $array_count = count($hasilPro);
        for($x = 0; $x < $array_count; $x++){
            for($a = 0 ;  $a < $array_count - 1 ; $a++){
                if($a < $array_count ){
                    if($hasilPro[$a] < $hasilPro[$a + 1] ){
                            swap($hasilPro, $a, $a+1);
swap($hasilRekap, $a, $a+1);
swap($hasilKomentar, $a, $a+1);
swap($hasilNorm, $a, $a+1);
swap($hasilKategori, $a, $a+1);
                    }
                }
            }
        }

$K=5;
$gab="<h3><b>Pengurutan Nilai K=$K besar</b></h3>";
$gab.="<ul>";
$J1=0;
$J2=0;
for($x = 0; $x < $array_count; $x++){
$gab.=$hasilRekap[$x];
if($hasilKategori[$x]==1){$J1++;}
else{$J2++;}
}
$gab.="<ul>";

$kes="LABEL 1";
if($J2>$J1){
$kes="LABEL 0";
}
//echo $gab;
return $kes;
}//fungsi
?>

<div class="container-fluid">
    <h1 align="center">INSTAGRAM</h1>
    <div class="row">
        <div class="col-sm-12">
            <h4>Komentar</h4>
            <ul class="list-group">
            <?php
                foreach ($comments->data as $media) {
                    $username_comment = $media->from->username;
                    $text = $media->text;
                    $id_post = $media_id;
                    $cek = mysqli_query($con, "SELECT * FROM comment WHERE username_comment LIKE '$username_comment' AND comment LIKE '$text' AND id_post='$id_post' ");
                    $itung = mysqli_num_rows($cek);
                    $see = mysqli_fetch_assoc($cek);
                    $username = $see['username_comment'];
                    $comment = $see['comment'];
                    $idpost = $see['id_post'];


                    if ($itung==0) {
                        // echo "kurang dari 0";
                        $addcomment = mysqli_query($conn, "INSERT INTO comment (username_comment, comment, id_post) VALUES ('$username_comment','$text','$id_post') ") or die (mysqli_error($con));
                    }else{
                        // echo "lebih banyak dari 0";
                        $update = mysqli_query($conn, "UPDATE comment SET username_comment='$username_comment', comment='$text', id_post='$id_post' WHERE username_comment LIKE '$username' AND comment LIKE '$comment' AND id_post='$idpost' ");
                    }
                }
            ?>
            
                <?php 
                $query = mysqli_query($conn, "SELECT * FROM comment WHERE id_post='$id_post' ");
                while ($fetch = mysqli_fetch_assoc($query)) {
                ?>
                <li class="list-group-item list-group-item-success">
<b><?php 
$user=$fetch['username_comment'];
$comment=$fetch['comment'];
$hsl=getUJUI($bikinos, $comment,$ak,$ar,$con);




echo $user; ?>
</b> 
<?php echo $comment; ?>
|
<a href="index.php?page=cs&comment=<?php echo $comment;?>&user=<?php echo $user;?>">TFIDF  =><?php echo $hsl;?></a>
</li>
            <?php
                }
            ?>
            </ul>
        </div>
    </div>
</div> 


<img src="analisa.png" width="30"  width="30">


base.php


<?php
function RP($rupiah){return number_format($rupiah,"2",",",".");}?>
<?php
function WKT($sekarang){
$tanggal = substr($sekarang,8,2)+0;
$bulan = substr($sekarang,5,2);
$tahun = substr($sekarang,0,4);

$judul_bln=array(1=> "Januari", "Februari", "Maret", "April", "Mei","Juni", "Juli", "Agustus", "September","Oktober", "November", "Desember");
$wk=$tanggal." ".$judul_bln[(int)$bulan]." ".$tahun;
return $wk;
}
?>
<?php
function WKTP($sekarang){
$tanggal = substr($sekarang,8,2)+0;
$bulan = substr($sekarang,5,2);
$tahun = substr($sekarang,2,2);

$judul_bln=array(1=> "Jan", "Feb", "Mar", "Apr", "Mei","Jun", "Jul", "Agu", "Sep","Okt", "Nov", "Des");
$wk=$tanggal." ".$judul_bln[(int)$bulan]."'".$tahun;
return $wk;
}
?>
<?php
function BAL($tanggal){
$arr=explode(" ",$tanggal);
if($arr[1]=="Januari"||$arr[1]=="January"){$bul="01";}
else if($arr[1]=="Februari"||$arr[1]=="February"){$bul="02";}
else if($arr[1]=="Maret"||$arr[1]=="March"){$bul="03";}
else if($arr[1]=="April"){$bul="04";}
else if($arr[1]=="Mei"||$arr[1]=="May"){$bul="05";}
else if($arr[1]=="Juni"||$arr[1]=="June"){$bul="06";}
else if($arr[1]=="Juli"||$arr[1]=="July"){$bul="07";}
else if($arr[1]=="Agustus"||$arr[1]=="August"){$bul="08";}
else if($arr[1]=="September"){$bul="09";}
else if($arr[1]=="Oktober"||$arr[1]=="October"){$bul="10";}
else if($arr[1]=="November"){$bul="11";}
else if($arr[1]=="Nopember"){$bul="11";}
else if($arr[1]=="Desember"||$arr[1]=="December"){$bul="12";}
return "$arr[2]-$bul-$arr[0]";
}
?>


<?php
function BALP($tanggal){
$arr=split(" ",$tanggal);
if($arr[1]=="Jan"){$bul="01";}
else if($arr[1]=="Feb"){$bul="02";}
else if($arr[1]=="Mar"){$bul="03";}
else if($arr[1]=="Apr"){$bul="04";}
else if($arr[1]=="Mei"){$bul="05";}
else if($arr[1]=="Jun"){$bul="06";}
else if($arr[1]=="Jul"){$bul="07";}
else if($arr[1]=="Agu"){$bul="08";}
else if($arr[1]=="Sep"){$bul="09";}
else if($arr[1]=="Okt"){$bul="10";}
else if($arr[1]=="Nov"){$bul="11";}
else if($arr[1]=="Nop"){$bul="11";}
else if($arr[1]=="Des"){$bul="12";}
return "$arr[2]-$bul-$arr[0]";
}
?>


<?php
function process($conn,$sql){
$s=false;
$conn->autocommit(FALSE);
try {
  $rs = $conn->query($sql);
  if($rs){
    $conn->commit();
    $last_inserted_id = $conn->insert_id;
  $affected_rows = $conn->affected_rows;
  $s=true;
  }
catch (Exception $e) {
echo 'fail: ' . $e->getMessage();
  $conn->rollback();
}
$conn->autocommit(TRUE);
return $s;
}

function getJum($conn,$sql){
  $rs=$conn->query($sql);
  $jum= $rs->num_rows;
$rs->free();
return $jum;
}

function getField($conn,$sql){
$rs=$conn->query($sql);
$rs->data_seek(0);
$d= $rs->fetch_assoc();
$rs->free();
return $d;
}

function getData($conn,$sql){
$rs=$conn->query($sql);
$rs->data_seek(0);
$arr = $rs->fetch_all(MYSQLI_ASSOC);
//foreach($arr as $row) {
//  echo $row['nama_kelas'] . '*<br>';
//}
$rs->free();
return $arr;
}


function getNorm($bikinos,$instagram){
$stemming=$bikinos->stem($instagram);
$stemmingnew=strtolower($stemming);

$ak=getStopNumber();
$ar=getStopWords();

$wordStop=$stemmingnew;
for($i=0;$i<count($ar);$i++){
 $wordStop =str_replace($ar[$i]." ","", $wordStop); 
}

for($i=0;$i<count($ak);$i++){
 $wordStop =str_replace($ak[$i],"", $wordStop); 
}
$instagramuji=str_replace("  "," ", $wordStop); 
//=====================================================
 $stemming=$instagramuji;
 return $stemming;
 }
?>


 <?php
 function getHit($kal,$kalimat){
  $ar=explode(" ",$kalimat);
  $ada=0;
  for($i=0;$i<count($ar);$i++){
   if($kal==$ar[$i]){$ada++;}
   }//for
  return $ada;
  } 
 ?>
  
    
    

<?php
function getStopWords()
    {
        return array(
            'yang', 'untuk','kereta','roda','api', 'pada', 'ke', 'para', 'namun', 'menurut', 'antara', 'dia', 'dua',
            'ia', 'seperti', 'jika', 'jika', 'sehingga', 'kembali', 'dan', 'tidak', 'ini', 'karena',
            'kepada', 'oleh', 'saat', 'harus', 'sementara', 'setelah', 'belum', 'kami', 'sekitar',
            'bagi', 'serta', 'di', 'dari', 'telah', 'sebagai', 'masih', 'hal', 'ketika', 'adalah',
            'itu', 'dalam', 'bisa', 'bahwa', 'atau', 'hanya', 'kita', 'dengan', 'akan', 'juga',
            'ada', 'mereka', 'sudah', 'saya', 'terhadap', 'secara', 'agar', 'lain', 'anda',
            'begitu', 'mengapa', 'kenapa', 'yaitu', 'yakni', 'daripada', 'itulah', 'lagi', 'maka',
            'tentang', 'demi', 'dimana', 'kemana', 'pula', 'sambil', 'sebelum', 'sesudah', 'supaya',
            'guna', 'kah', 'pun', 'sampai', 'sedangkan', 'selagi', 'sementara', 'tetapi', 'apakah',
            'kecuali', 'sebab', 'selain', 'seolah', 'seraya', 'seterusnya', 'tanpa', 'agak', 'boleh',
            'dapat', 'dsb', 'dst', 'dll', 'dahulu', 'dulunya', 'anu', 'demikian', 'tapi', 'ingin',
            'juga', 'nggak', 'mari', 'nanti', 'melainkan', 'oh', 'ok', 'seharusnya', 'sebetulnya',
            'setiap', 'setidaknya', 'sesuatu', 'pasti', 'saja', 'toh', 'ya', 'walau', 'tolong',
            'tentu', 'amat', 'apalagi', 'bagaimanapun'
        );
    }


function getStopNumber()
    {
        return array(
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!', '@', '#', '$', '%'
        );
    }
function getUnix($array){
error_reporting(0);
$unique = array_flip(array_flip($array));
//print_r($unique);
$jd=count($array);
//echo $jd."#<br>";
$m=0;
for($i=0;$i<$jd;$i++){
 if(strlen($unique[$i])>0){
  //echo "$m =".$unique[$i]."<br>";
  $M[$m]=$unique[$i];
  $m++;
 }
}
 return $M;
}

 function swap(&$arr, $a, $b) {
        $tmp = $arr[$a];
        $arr[$a] = $arr[$b];
        $arr[$b] = $tmp;
    }
?>






PHP SNORT TELEGRAM

<?php
if (version_compare(phpversion(), "5.3.0", ">=")  == 1)
  error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
else
  error_reporting(E_ALL & ~E_NOTICE); 
  ?>
<?php
session_start();
// error_reporting(0);
require_once"konmysqli.php";

$mnu=$_GET["mnu"];
date_default_timezone_set("Asia/Jakarta");

?>
<html>
<head>
<script type="text/javascript">
function Ajax(){
var $http,$self = arguments.callee;

if (window.XMLHttpRequest) {$http = new XMLHttpRequest();}
else if (window.ActiveXObject) {
try {$http = new ActiveXObject('Msxml2.XMLHTTP');}
catch(e) {$http = new ActiveXObject('Microsoft.XMLHTTP');}
}

if ($http) {
$http.onreadystatechange = function(){
if (/4|^complete$/.test($http.readyState)) {
document.getElementById('ReloadThis').innerHTML = $http.responseText;
setTimeout(function(){$self();}, 1000);
}
};
$http.open('GET', 'load.php' + '?' + new Date().getTime(), true);
$http.send(null);
}
}
</script>
<script type="text/javascript">setTimeout(function() {Ajax();}, 1000);</script>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body></body>
</html>
<hr /><div id="ReloadThis">LP2MARAY</div>


+++++++++++++
<?php

date_default_timezone_set("Asia/Jakarta");

$wkt=date("Y-m-d H:i:s");
require_once"konmysqli.php";

$temp=$wkt;
echo $temp;

$sql="select `temp` from `tb_temp`";
$ada=getJum($conn,$sql);
if($ada>0){
$d=getField($conn,$sql);
$temp=$d["temp"];



$sql2="select `sig_class_id`,`signature`,`sig_name`,`timestamp`,`layer4_dport`,`layer4_sport`,inet_ntoa(`ip_src`) as `ip_src`,inet_ntoa(`ip_dst`) as `ip_dst`,`sig_priority` from `acid_event` where `timestamp` > '$temp' order by cid desc";// where `temp`>'$temp' order by ID desc";
$d2=getField($conn,$sql2);
$sig_class_id=$d2["sig_class_id"];
$signature=$d2["signature"];
$sig_name=$d2["sig_name"];
$timestamp=$d2["timestamp"];
$layer4_dport=$d2["layer4_dport"];
$layer4_sport=$d2["layer4_sport"];

$ip_src=$d2["ip_src"];
$ip_dst=$d2["ip_dst"];

if($timestamp=="0000-00-00 00:00:00" || strlen($timestamp)<5){}
else{
echo ">>Ada penyusup masuk $ip_src to $ip_dst ($timestamp)/$sig_name";


$sqlb="select `sig_class_name` from `sig_class` where sig_class_id='$sig_class_id'";
$db=getField($conn,$sqlb);
$sig_class_name=$db["sig_class_name"];


$name = "Admin LAN";
$message = "$name:Ada penyusup masuk $ip_dst to $ip_src ($timestamp)/$sig_name: $sig_class_name";

echo"<hr>";
echo $message;

$sql3="DELETE from `tb_temp`";
process($conn,$sql3);

$sql3="INSERT INTO `tb_temp` (`temp`) VALUES ('$timestamp');";
process($conn,$sql3);

///////////////////
define ('url',"https://api.telegram.org/bot763220421:AAHt3f2V5qnJ1sjSg2kRva1uxL4ytt5df6Q212/");
$update = json_decode(file_get_contents("php://input") ,true);
$chat_id ="647876166212";
file_get_contents(url."sendmessage?text=".$message."&chat_id=".$chat_id."");
//======================
}//else
}


 //where `temp`>'$temp'
 //inet_ntoa
//token: 763220421:AAHt3f2V5qnJ1sjSg2kRva1uxL4ytt5df6Q
//chat_id: 647876166

?>

Senin, 12 Agustus 2019

PHP menghitung Selisih Tahun


$wk=$d["tanggal_lahir"];//2000-09-01

$awal  = new DateTime("$wk");
$akhir = new DateTime(); // Waktu sekarang
$diff  = $awal->diff($akhir);
$umur= $diff->format('%Y');



PHP download file

<?php$direktori = "file/";
$namafile=$_GET["ypathfile"];

if (!file_exists($direktori.$namafile)) {
  echo "<h1>Access forbidden!</h1>
        <p>Maaf, file $namafile yang Anda download sudah tidak tersedia atau filenya (direktorinya) telah diproteksi. <br />
        Silahkan hubungi <a href='mailto:adiarray@gmail.com'>Administrator</a>.</p>";
  exit();
}
else {
   header("Content-Type: octet/stream");
  header("Content-Disposition: attachment; filename=\"".$namafile."\"");
  $fp = fopen($direktori.$namafile, "r");
  $data = fread($fp, filesize($direktori.$namafile));
  fclose($fp);
  print $data;
}
?>

Mencari Tanggal Terakhir Suatu Bulan

  $a_date = "$tahun-$bulan-01"; $lastdate= date('t',strtotime($a_date));//Y-m-t <?php require_once"koneksivar.php&...