Wednesday, October 26, 2011

Upgrade Phpmyadmin in XAMPP

What is Phpmyadmin? Phpmyadmin is a tool written in PHP for viewing the MySQL tables & execute the SQL queries with the interface.

I'm just explaining how to upgrade the Phpmyadmin.

Want to Upgrade the latest Phpmyadmin in XAMPP, it is as simple as the usage.

Just download the latest version of Phpmyadmin from phpmyadmin or download from the link below.

First take a copy of Phpmyadmin folder in XAMPP or else just rename it in XAMPP then extract the downloaded files into XAMPP folder.

And now, take the config.inc.php file from the renamed folder & place it in the new folder, thats it & just check the latest version is running successfully.

Download, the latest phpmyadmin here


Sunday, September 25, 2011

jQuery Basics

Below are the basics of jQuery. How to create a simple variable, array, objects and a function.

This is explained by Mike Kamminga (Managing director of W3industries). We had a nice session on some other things but I've considered below is the basic jQuery reference for creating objects, arrays.


// simple variable
var myVar = 'value1';
console.log(myVar); //By having console.log we can check the output of javascript in Console of Chrome


// simple array
var myArray = ['value1','value2'];
console.log(myArray);
console.log(myArray[1]);


// simple object
var myObject = {
key1:'value1',
key2:'value2'
};
console.log(myObject);
console.log(myObject.key2);


// multidimensional array
var myArray2 = ['value1','value2', ['value3','value4']];
console.log(myArray2);
console.log(myArray2[2][0]);
console.log(myArray2.length);


// multidimensional object
var myObject2 = {
key1:'value1',
key2:'value2',
key3:{key4:'value4'}
};
console.log(myObject2);
console.log(myObject2.key3.key4);


// example of object references
var settings = {
width : '100',
height : '200',
img : ['img/img1.jpg']
};
// creating reference (not copy)
var someSettings = settings;
// this overwrites the original
settings.img = ['img/img1.jpg','img/img1.jpg','img/img1.jpg','img/img1.jpg'];
someSettings.img = ['boe'];

console.log('settings');
console.log(settings);
console.log('someSettings');
console.log(someSettings);


// creating an object as a function
var settingsObj = function(){

this.width = '100';
this.height = '200';
this.img = ['img/img1.jpg'];
return this;
}


// instantiating the settingsObj twice (copies)
var mySettings1 = new settingsObj;
var mySettings2 = new settingsObj;

var testSettings = settingsObj();

// give first instance a new value
mySettings1.img = ['img/img1.jpg','img/img1.jpg','img/img1.jpg','img/img1.jpg'];

console.log('mySettings1.img:');
console.log(mySettings1.img);
console.log('mySettings2.img:');
console.log(mySettings2.img);
console.log('testSettings.img:');
console.log(testSettings.img);


// make a function that does a simple calculation
function test(i) {
this.value = 5;
return this.value*i;
}

// store result in a variable
var myTest = test(5);
console.log('myTest: '+myTest);
var myTest2 = test(10);
console.log('myTest2: '+myTest2);





/*
* Binding events to elements
*/

$('#my_button').bind({
click : function(){
console.log('clicked');
},
mouseenter : function(){
console.log('mouseenter');

var my_div = $('<div>This is my div</div>');
$('#container').append(my_div);
my_div.slideUp().fadeIn();

console.log(this);

// binding mouseleave inside mouseenter
// this way I have access to the variable my_div
$(this).bind({
mouseleave : function(){
my_div.fadeOut();
}
});
},
mouseleave : function(){
// binding mouseleave again
console.log('mouseleave');
}
});




// difference between each() and for() and while()
var arraylength = myArray.length;

// for loop
for(i = 0; i < arraylength; i++){
console.log(myArray[i]);
}

// while loop
var k = -1;
while(++k < arraylength){
console.log('testing while:');
console.log(myArray[k]);
}

// each() notiation 1
$(myArray).each(function(key, value){
console.log(key, value);
});

// each() notation 2
$.each(myArray, function(key, some){
console.log(key, some);
});

// jquery notation for array length (length is native JS)
console.log($(myArray).length);




Monday, September 5, 2011

Google map using Javascript

To show the google map in our website using javascript, first we need to register Google map API and need to provide the API key in the below code.


<div id="map" style="width: 400px; height: 300px"></div>

<script type="text/javascript">
<script src="http://maps.google.com/maps?file=api&v=1&key=REGISTERED_API_KEY_HERE" type="text/javascript"></script>
var map = new GMap(document.getElementById("map")); var point = GPoint(17.0477624,80.0981869); var address = 'L.B.Nagar | Hyderabad'; var mark = createInfoMarker(point, address); map.addOverlay(mark); function createInfoMarker(point, address) { var marker = new GMarker(point); map.centerAndZoom(point, 3); GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(address); } ); return marker; } </script>






Wednesday, August 31, 2011

Restrict the file uploads using PHP


Below is the php code to restrict the file uploads for a particular type of files. As an example, I'm showing all the extension types in the "Allowed extensions" variable.


<?php

  $allowedExtensions = array("txt","csv","htm","html","xml",
    "css","doc","xls","rtf","ppt","pdf","swf","flv","avi",
    "wmv","mov","jpg","jpeg","gif","png");
    if ($_FILES['upload_file']['tmp_name'] > '') {
      if (!in_array(end(explode(".",
            strtolower($_FILES['upload_file']['name']))),
            $allowedExtensions)) {
       die($_FILES['upload_file']['name'].' is an invalid file type!<br/>'.
        '<a href="javascript:history.go(-1);">'.
        '&lt;&lt Go Back</a>');
      }
    }

?>





Saturday, August 13, 2011

Remove the special characters from the query string

Function to remove the special characters from the query string using PHP.

function trim_req($string){
$string=preg_replace('/[^A-Za-z0-9-]+/', '', $string);
$string = str_replace("<", "", $string);
$slug = str_replace(">", "", $string);
return $slug;
}




Change the color of selected text in a browser for ur site

Below is the css Code to change the default color of the selected text as shown in the below screen shots.


::-moz-selection{ background: #DA3E34; color:#fff; text-shadow: none; }
::selection { background:#DA3E34; color:#fff; text-shadow: none; }




Compress & decrease the page loading time using HTACCESS

Place the below code in htaccess & decrease the loading time taken for the browser.


<IfModule mod_gzip.c>
    mod_gzip_on       Yes
    mod_gzip_dechunk  Yes
    mod_gzip_item_include file      \.(html?|txt|css|js|php|pl)$
    mod_gzip_item_include handler   ^cgi-script$
    mod_gzip_item_include mime      ^text/.*
    mod_gzip_item_include mime      ^application/x-javascript.*
    mod_gzip_item_include mime      ^image/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>

Above code will compress the HTML,CSS,JS,PHP,PL script files and also image files. 


Monday, August 8, 2011

count of checkboxes selected using javascript

Below is the code to know the number of checkboxes selected in a form. The function returns the total count of the Checkbox checked.

<script type="text/javascript">
function anyCheck(form) {
var total = 0;
var Count = document.playlist.count.value;
for (var idx = 1; idx < Count; idx++) {
if (eval("document.playlist.ckbox" + idx + ".checked") == true) {
total += 1;
}
}
alert("You selected " + total + " boxes.");
}
</script>
<form method="post" name=playlist>
1<input type=checkbox name=ckbox>
<br>2<input type="checkbox" name="ckbox1" onchange="anyCheck(this.value)">
<br>3<input type="checkbox" name="ckbox2" onchange="anyCheck(this.value)">
<br>4<input type="checkbox" name="ckbox3" onchange="anyCheck(this.value)">
<br>5<input type="checkbox" name="ckbox4" onchange="anyCheck(this.value)">
<br>6<input type="checkbox" name="ckbox5" onchange="anyCheck(this.value)">
<br>7<input type="checkbox" name="ckbox6" onchange="anyCheck(this.value)">
<br>8<input type="checkbox" name="ckbox7" onchange="anyCheck(this.value)">
<br>9<input type="checkbox" name="ckbox8" onchange="anyCheck(this.value)" >
<input type="hidden" value="8" name="count">
</form>


Wednesday, June 1, 2011

include a javascript file in js file

Code to include a js file in another js file.

var js1 = document.createElement('script');
js1.type = 'text/javascript';
js1.src = 'js1.js';

var headEl = document.getElementsByTagName('head')[0];
headEl.appendChild(js1);





Wednesday, May 25, 2011

Maximum length for the POST and GET methods

Maximum length of the POST is defined in the PHP ini file. Mostly it is 128M. To know the maximum POST length check your ini file for post_max_size

Maximum URL length is 2083 characters i.e. maxlength in GET method.


Monday, May 23, 2011

Geography of India, India Geography Map, India Boarders, India Coordinates, ancient india geography

Continent     Asia
Region     Southern Asia
Indian subcontinent
Coordinates     21°N 78°E
Area     Ranked 7th
3,287,263 km2 (1,269,219.3 sq mi)
90.44% land
9.56 % water
Borders     Total land borders: 15,106.70 km (9,386.87 mi)
Bangladesh: 4,096.70 km (2,545.57 mi)
China (PRC): 3,488 km (2,167 mi)
Pakistan: 3,323 km (2,065 mi)
Nepal: 1,751 km (1,088 mi)
Myanmar: 1,643 km (1,021 mi)
Bhutan: 699 km (434 mi)
Afghanistan: 106 km (66 mi)
Highest point    Kangchenjunga 8,586 m (28,169.3 ft)
Lowest point    Kuttanad −2.2 m (−7.2 ft)
Longest river     Ganges–Brahmaputra
Largest lake     Chilka Lake



Friday, May 13, 2011

Force files to Download using HTACCESS

Add the below code in HTACCESS file to show download option whereas in PHP we can use header functions to give the download option for file.

AddType application/octet-stream .csv
AddType application/octet-stream .xls
AddType application/octet-stream .doc
AddType application/octet-stream .avi
AddType application/octet-stream .mpg
AddType application/octet-stream .mov
AddType application/octet-stream .pdf




Saturday, April 23, 2011

Limit the text area using Javascript


 To limit the textarea using javascript, we can use the below simple code which limits the textarea characters.

function textLimit(field, maxlen) {
        if (field.value.length > maxlen + 1)
            alert('Total Length is only '+ maxlen +' Characters');
        if (field.value.length > maxlen)
            field.value = field.value.substring(0, maxlen);
    }

and the code to be used in the textarea is shown below.

<textarea name='address'  cols='28' rows='4'  onkeyup="textLimit(this,350)"></textarea>






Tuesday, March 22, 2011

Check whether site is down or good using php

Below is the function to check whether the site is down or good using php.

function VisitSite($url){
    $agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL,$url );
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch,CURLOPT_VERBOSE,false);
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    $page=curl_exec($ch);
    //echo curl_error($ch);
    $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    if($httpcode >= 200 && $httpcode < 300){
        return true;
    }
    else {
        return false;
    }
}
if(VisitSite('http://www.google.com')){
       echo "Website looks Good";
}else{
      echo "Website looks Down";
}
 

Saturday, March 5, 2011

Photoshop Shortcuts

Photoshop shortcuts. Please check the below image for the photograph shortcuts. This may help you.

If I miss any of them, please make a comment so that I can also know it.





 

Wednesday, February 23, 2011

Change Page title using Javascript

Code to change the Page title using Javascript is shown below.

document.title = 'Page Title has been Changed using Javascript';


Monday, January 31, 2011

Auto Refresh a Div or an Element using Jquery

Below is the code to refresh a div or an element using Jquery.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Refresh</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function()
{
$('#replace_content').load('
replace_content.php');
}, 1000);
</script>
<style type="text/css">
#shouts { background: #36F; height: 200px; overflow: auto; width: 300px; }
</style>
</head>

<body>
<div id="replace_content"><?php include'replace_content.php'?></div>
</body>
</html>