Home

Wednesday, August 22, 2012

How to get Computer Information Using JavaScript


<Script language="javascript">
          var WshNetwork = new ActiveXObject("WScript.Network");
          alert('domain ='+   WshNetwork.UserDomain);
          alert('machine name = '+  WshNetwork.ComputerName );
          alert('user name = '+   WshNetwork.UserName);
</script>

Import a CSV File Using PHP and MySQL


<?php
error_reporting(0);
//connect to the database
$connect = mysql_connect("localhost","root","");
mysql_select_db("test",$connect); //select the table
//

if ($_FILES[csv][size] > 0) {

    //get the csv file
    $file = $_FILES[csv][tmp_name];
    $handle = fopen($file,"r");
   
    //loop through the csv file and insert into database
 
    $row = 0;
while ($data = fgetcsv($handle,1000,",","'"))
{
if($row!=0)// First (Title) Row is not inserted
{
if ($data[0]) {
mysql_query("INSERT INTO contacts (contact_first, contact_last, contact_email) VALUES
(
'".addslashes($data[0])."',
'".addslashes($data[1])."',
'".addslashes($data[2])."'
)
");
}
}
$row++;
}
    //

    //redirect
    header('Location: index.php?success=1'); die;

//echo "success";

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Import a CSV File with PHP & MySQL</title>
</head>

<body>

<?php if (!empty($_GET[success])) { echo "<b>Your file has been imported.</b><br><br>"; } //generic success notice ?>

<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
  Choose your file: <br />
  <input name="csv" type="file" id="csv" />
  <input type="submit" name="Submit" value="Submit" />
</form>

</body>
</html>

Saturday, August 18, 2012

Retrieve windows username in php

<?php
              $nw = new COM("WScript.Network");
              print "username: " . $nw->username . "<br><br>";

              $computername = $nw->computername;
              print "computername: $computername<br><br>";

              $owmi = new COM("winmgmts:\\\\$computername\\root\\cimv2");
              $comp = $owmi->get("win32_computersystem.name='$computername'" );

                print "username: " . $comp->username;
?>

Export Mysql data to CSV with PHP


<?php
$database="wordpress";
$table="wp_member";
mysql_connect("localhost","root","");
mysql_select_db("wordpress");
$result = mysql_query("SELECT * FROM wp_member");

$out = '';

// Get all fields names in table "wp_member" in database "wordpress".
$fields = mysql_list_fields($database,$table);

// Count the table fields and put the value into $columns.
$columns = mysql_num_fields($fields);

// Put the name of all fields to $out.
for ($i = 0; $i < $columns; $i++) {
$l=mysql_field_name($fields, $i);
$out .= '"'.$l.'",';
}
$out .="\n";

// Add all values in the table to $out.
while ($l = mysql_fetch_array($result)) {
for ($i = 0; $i < $columns; $i++) {
$out .='"'.$l["$i"].'",';
}
$out .="\n";
}

// Open file export.csv.
$f = fopen ('export.csv','w');

// Put all values from $out to export.csv.
fputs($f, $out);
fclose($f);

header('Content-type: application/csv');
header('Content-Disposition: attachment; filename="export.csv"');
readfile('export.csv');
?>

Friday, August 17, 2012

How to develop a website in Hindi Gujarati language

Step : 1 -> Create Database: `language`

Step : 2 -> Create Table
                  CREATE TABLE IF NOT EXISTS `lan` (
                          `id` int(11) NOT NULL AUTO_INCREMENT,
                          `hindi` mediumtext COLLATE utf8_bin NOT NULL,
                           PRIMARY KEY (`id`)
      ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1 ;

Step : 3 -> Index.php
                 <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>How to develop a website in Hindi Gujarati language</title>    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">

      // Load the Google Transliterate API
      google.load("elements", "1", {
            packages: "transliteration"
          });

      function onLoad() {
        var options = {
            sourceLanguage:
                google.elements.transliteration.LanguageCode.ENGLISH,
            destinationLanguage:
                [google.elements.transliteration.LanguageCode.HINDI],
               // if u want Gujarati Typing Please Replace HINDI With GUJARATI
            shortcutKey: 'ctrl+g',
            transliterationEnabled: true
        };

        // Create an instance on TransliterationControl with the required
        // options.
        var control =
            new google.elements.transliteration.TransliterationControl(options);

        // Enable transliteration in the textbox with id       
control.makeTransliteratable(['hindi']);
      }
      google.setOnLoadCallback(onLoad);
    </script>
</head>


<?php

mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("language") or die(mysql_error());

mysql_query('SET character_set_results=utf8');
mysql_query('SET names=utf8');
mysql_query('SET character_set_client=utf8');
mysql_query('SET character_set_connection=utf8');
mysql_query('SET character_set_results=utf8');

if($_SERVER['REQUEST_METHOD']=="POST")
{
$hindi = addslashes($_POST['hindi']);
$qry = "INSERT INTO lan (hindi) VALUES ('".$hindi."')";
mysql_query($qry) or die(mysql_error());
}

$sql = "SELECT * FROM lan";
$rs = mysql_query($sql) or die(mysql_error());

?>

<table width="100%" border="1">
<tr>    
        <td>Hindi Content</td>       
    </tr>
    <?php while($row = mysql_fetch_assoc($rs)){?>
    <tr>    
        <td><?php echo $row['hindi'];?></td>        
    </tr>
    <?php } ?>
</table>

<form method="post">
    Type in Hindi<br>    
    <!-- <textarea id="guj" name="guj" style="width:600px;height:200px"></textarea><br />-->
    <textarea id="hindi" name="hindi" style="width:600px;height:200px"></textarea><br />    
    <input type="submit" />
</form>

Thursday, August 16, 2012

Tinymce editor with Indian Lanugage using google translation


<!-- TinyMCE -->

    <script type="text/javascript" src="../jscripts/tiny_mce/tiny_mce.js"></script>
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">
        // Load the Google Transliteration API
        google.load("elements", "1", {
            packages: "transliteration"
        });
    </script>
    <script type="text/javascript">

        tinyMCE.init({
            mode: "textareas",
            theme: "advanced",
            plugins: "translitration,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",
         
// Theme options
theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect,google",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft,visualblocks",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
        });
    </script>


 <textarea name="content" style="width: 100%" rows="40"></textarea>

Tinymce In Gujarati, Hindi Language


Step 1 : Download Tinymce From this side
                            http://www.tinymce.com/download/download.php

Step 2 : Download PramukhIME TinyMCE Plugin   
                            http://www.vishalon.net/PramukhIME /TinyMCEPlugin.aspx

Step 3 :   Plugin Installation:
                 1. Unzip the file on your local hard disk.
                 2. Upload "pramukhime" folder to TinyMCE_ROOT/plugins/

Step 4 :    This Javascript Add in Your Editor Page   
                   <!-- TinyMCE -->
                      <script type="text/javascript" src="../jscripts/tiny_mce/tiny_mce.js"></script>
                     <script type="text/javascript">
                          tinyMCE.init({
                               theme : "advanced",
                               language : "en",
                               mode : "textareas",
                               safari_warning : false,
                               plugins : "advlink, advimage,  preview, visualchars, media, nonbreaking,           pramukhime",
                              theme_advanced_buttons3_add : "styleprops, visualchars, media, nonbreaking, pramukhime",
                              debug : false,
                              fullscreen_settings : {
                                     theme_advanced_path_location : "top"
                             }
                         });
                  </script>


Step 5  : Enjoy :)

Tuesday, August 14, 2012

How to use Curl with json (API)


Step - 1 --> index.php
<?php
  $url = 'http://your_domain_name.com/api.php';
 
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, 1);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  $result = curl_exec($ch);
  $info = curl_getinfo($ch);
  curl_close($ch);
  $data = json_decode($result, true);
  echo "<pre>";
  print_r($data);
  echo "</pre>";
?>

Step - 2 --> api.php

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("medical",$con) or die("database Error".mysql_error());

$aData = getAll();

if (count($aData))
 {
echo json_encode(array('data' => $aData));
} else {
echo json_encode(array('data' => 'Nothing found'));
}

 function getAll()
 {
        $query = "SELECT * FROM user";
if (! $query)
            return array();

        $res = mysql_query($query) or die("Query Error".mysql_error());
        $arr_res = array();
        if ($res) {
            while ($row = mysql_fetch_assoc($res))
                $arr_res[] = $row;
            mysql_free_result($res);
        }
        return $arr_res;
 }
?>
rathoddhirendra.blogspot.com-Google pagerank and Worth