Thursday, 26 February 2015

Get Back To Previous Page

<button type="button" onclick="history.back();">Back</button>

Other Things

back()                 Loads the previous URL in the history list.

forward()          Loads the next URL in the history list.

go()                         Loads a specific URL from the history list.

Side note: this is straight Javascript, not jQuery. There are completely history plugins designed using the jQuery plugin framework, but they are meant to handle ajax and your history (to not break the back button on a single page that behaves as many pages)

Tuesday, 24 February 2015

Clear All Input Fields in a Specific div With JQuery

I have added two buttons in the Fiddle to illustrate how you can insert or clear values in those input fields through buttons. You just capture the onClick event and call the function.


//Fires when the Document Loads, clears all input fields
$(document).ready(function() {
  $('.fetch_results').find('input:text').val('');    
});


//Custom Functions that you can call
function resetAllValues() {
  $('.fetch_results').find('input:text').val('');
}


function addSomeValues() {
  $('.fetch_results').find('input:text').val('Lala.');
}


This function is used to clear all the elements in the form including radio button, check-box, select, multiple select, password, text, textarea, file.


function clear_form_elements(class_name) {
  jQuery("."+class_name).find(':input').each(function() {
    switch(this.type) {
        case 'password':
        case 'text':
        case 'textarea':
        case 'file':
        case 'select-one':
        case 'select-multiple':
            jQuery(this).val('');
            break;
        case 'checkbox':
        case 'radio':
            this.checked = false;
    }
  });

}

Saturday, 21 February 2015

Php String Function

You can create own function in PHP Language but , PHP has many predefined function like string function , array function , numeric function etc.
PHP all String functions as bellow table…

Php Function

PHP functions are comparable to other programming languages. A function is a portion of code which takes one more input in the form of parameter and does some processing and returns a value.

PHP have already built-in functions but PHP gives you option to create your own functions as well.

Readmore.

Friday, 20 February 2015

10 Powerful SQL Injection Tools That Penetration Testers Can Use

 An SQL injection attack is a code injection attack that is used to exploit web applications and websites. It is one of the most common methods for hackers to get into your system. Learning such attacks are important for anyone looking to perform their own exploits. Here are 10 of the most powerful tools that aid in performing SQL Injection attacks.

1. BSQL Hacker

This is a useful tool for both experts and beginners that automates SQL Injection attacks on websites.

2. The Mole

This is an SQL Injection tool that uses the union technique or the boolean query-based technique.

3. Pangolin

This is a penetration testing tool developed by NOSEC. It is aimed at detecting and exploiting SQL injection vulnerabilities on websites.

4. Sqlmap

This is an open source penetration testing tool that security professionals can use. Like the BSQL Hacker tool, this one also automates SQL Injection attacks.

5. Havij

This is an automated SQL injection tool that can be used by penetration testers in order to detect vulnerabilities in web applications and exploit them.

6. Enema SQLi

This is a dynamic penetration testing tool for professionals. It is an auto-hacking software.

7. Sqlninja

This is a tool targeted at exploiting SQL injection vulnerabilities. It uses the Microsoft SQL server as its back end.

8. sqlsus

Written using the Perl programming language, this is an open source penetration testing tool for MySQL Injection and takeover.

9. Safe3 SQL Injector

This is a powerful penetration testing tool, which automates the process of detecting and exploiting SQL Injection vulnerabilities.

10. SQL Poizon

This tool includes php , asp , rfi , lf dorks that can be used for penetration testing.

Monday, 16 February 2015

Schedule tasks in mysql using Event Scheduler

Event Scheduler in MySQL is like a task scheduler which performs database related tasks in MySQL. Event scheduler is available in MySQL version > MySQL 5.1.12.
To use event scheduler, first it should be set ON for your database server either in my.ini or my.cnf file. Even you can enable it on run time by using either of following:
SET GLOBAL event_scheduler = ON;
SET @@global.event_scheduler = ON;
SET GLOBAL event_scheduler = 1;
SET @@global.event_scheduler = 1;

A general syntax is as follows:

DELIMITER $$

-- SET GLOBAL event_scheduler = ON$$     -- required for event to execute but not create    

CREATE /*[DEFINER = { user | CURRENT_USER }]*/ EVENT `<<event_name>>`

ON SCHEDULE
/* uncomment the example below you want to use */

--  run once

   --  AT 'YYYY-MM-DD HH:MM.SS'/CURRENT_TIMESTAMP { + INTERVAL 1 [HOUR|MONTH|WEEK|DAY|MINUTE|...] }

--  run at intervals forever after creation

   -- EVERY 1 [HOUR|MONTH|WEEK|DAY|MINUTE|...]

-- specified start time, end time and interval for execution
   /*EVERY 1  [HOUR|MONTH|WEEK|DAY|MINUTE|...]

   STARTS CURRENT_TIMESTAMP/'YYYY-MM-DD HH:MM.SS' { + INTERVAL 1[HOUR|MONTH|WEEK|DAY|MINUTE|...] }

   ENDS CURRENT_TIMESTAMP/'YYYY-MM-DD HH:MM.SS' { + INTERVAL 1 [HOUR|MONTH|WEEK|DAY|MINUTE|...] } */

DO
BEGIN
    COMMENT 'any sql_statements'
END$$

DELIMITER ;


An example of Event:


SQL>CREATE EVENT e_hourly
    ON SCHEDULE
      EVERY 1 HOUR
    COMMENT 'Clears out sessions table each hour.'
    DO
      DELETE FROM site_activity.sessions;
 
 
 
To check any running event or details of event, following query will be used:


mysql> SHOW EVENTS\G

Some more examples of Events:

CREATE EVENT e_daily
    ON SCHEDULE
      EVERY 1 DAY
    COMMENT 'will run every day'
    DO
      BEGIN
        INSERT INTO site_activity.totals (time, total)
          SELECT CURRENT_TIMESTAMP, COUNT(*)
            FROM site_activity.sessions;
        DELETE FROM site_activity.sessions;
      END |

delimiter ;

Prevent Sql Injection in PHP

Hi there! Today In this post I will mention few of the methods which is usually used in php application to prevent SQL injections.
It is said, “Never Trust Your User’s Input”. Preventing and cleaning user input in your php code is always a good and recommended practice.
1) Using mysql_real_escape_string() function:
Use if mysql_real_escape_string() is always a good practice into your code, but we can make it even better, consider following Code:

A BAD PRACTICE:

Example:

<?php

$uname = $_POST['username'];
$query = "SELECT password FROM tbl_user WHERE user_name = $uname "; // very hazardous, your system may prone to SQL injection
$res = mysql_query($query);

?>

A GOOD PRACTICE:
Example I:

<?php

$uname = mysql_real_escape_string($_POST['username']); //use of mysql_real_escape_string()
$query = "SELECT password FROM tbl_user WHERE user_name = '$uname' "; // use of single quotes for STRING $uname
$res = mysql_query($query);

?>

Example II:

<?php

$usrid = mysql_real_escape_string($_POST['userid']); //use of mysql_real_escape_string()
$usrid = (int)$usrid ; // cast id as int
$query = "SELECT username, password FROM tbl_user WHERE id = $usrid ";
$res = mysql_query($query);

?>

Also, if possible set your default charset to UTF8 using mysql_set_charset() function, it will be an another good approach.

2) PDO Prepared statements:

Following code will be quiet safe for pdo:


<?php
$stmt = $dbh->prepare("SELECT * FROM tbl_user where name = ?");
if ($stmt->execute(array($_POST['name']))) {
  while ($row = $stmt->fetch()) {
    print_r($row);
  }
}
?>

3) Using mysqli prepared statement:

<?php

$city = $_POST['cname'];
/* create a prepared statement */
if ($stmt = $mysqli->prepare("SELECT * FROM tbl_city WHERE cty_name=?")) {

    /* bind parameters for markers */
    $stmt->bind_param("s", $city);

    /* execute query */
    $stmt->execute();

    /* bind result variables */
    $stmt->bind_result($district);
    $stmt->fetch();
    $stmt->close();
}

/* close connection */
$mysqli->close();
?>

Automatically Refresh HTML page or div after specific time Interval

There are several ways to refresh a complete HTML page after specific time interval, and same is the case with any specific Div or Span or any HTML element on a page, that we can refresh any specific part/element of HTML page without reloading the complete page.
First let’s take a look at refreshing HTML page after specific time interval, this can be achieved using either JavaScript or by meta tags.
A) Using Javascript:
You can use either of the following scripts to refresh after every 5 secounds, say:


Code I:

<script>

function autoRefresh()
{
window.location = window.location.href;
}

setInterval('autoRefresh()', 5000); // this will reload page after every 5 secounds; Method I
</script>

OR
Code II:


<script>

function autoRefresh1()
{
   window.location.reload();
}

setInterval('autoRefresh1()', 5000); // this will reload page after every 5 secounds; Method II
</script>

B) Refresh page using Meta tags
Its very easy, you just have to put a meta tag in head tag as follows:


<head>

<meta http-equiv="refresh" content="5" />
    <!-- This will refresh page in every 5 seconds, change content= x to refresh page after x seconds -->
</head>

Refresh Div/Span on HTML page after specific time:
In this part we will use JQuery to perform the task, as its provides few of the best options that can help us.
Suppose you have a div with ID as result similar to following:


<div id="result"></div>
Then JQuery code will be as follows:


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
function autoRefresh_div()
{
    $("#result").load("load.html");// a function which will load data from other file after x seconds
}

setInterval('autoRefresh_div()', 5000); // refresh div after 5 secs
</script>

Similarly you can use $.ajax() or $.post() etc instead of load() function and put the response in a div or a span.
— Automatically Refresh HTML page or div after specific time Interval –

Saturday, 14 February 2015

Create a google map and display it on your wesite

Generate your own Google map for your Website, Blog or Facebook page. Just enter your address and copy a small snippett of code to your Generate your own Google map for your Website, Blog or Facebook page. Jusenter your address and copy a small snippett of code to your page. It's that easypage. It's that easy.

http://www.yourmapmaker.com/

CodeIgniter browser back button showing history fix

You may have noticed an issue while coding on CodeIgniter that even though you have destroyed the session values (invoking the $this->session->sess_destroy()) after logging out the page, the browser back button still takes you to your previous history page. Even though we may have made a provision to check empty session parameters and log out the page if the session has been destroyed, the browser back button still displays the previous pages that we have browsed.
The session check if we have used, tends to be working while refreshing the page, and doesn't let us browse new pages further. However, the back button lets us browse previous history items and it may raise an issue on privacy. User's private data may be visible to others too.
This occurs because the browser back button goes to the history when clicked.
We can prevent it by setting a header with no-cache. To prevent it, we should put the code given below in our index.php file with in the project.

header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");header("Cache-Control: no-store, no-cache, must-revalidate");

Print Page or Section of Page Using JQuery

We often need to print our output so that we can take a hard copy of that by printing it. To achieve this, we need to allow users to print a page or a section, div, span of HTML page. JQuery has a great plugin which is very easy to use and even allow us to tweak/configure printing. Here we are talking about JQuery.print.jswhich you can download from HERE.
Using this plugin we can print any Text content in a div or a span as shown below:
Usage is quiet simple:

Just include the main JS file along with JQuery:

<script type="text/JavaScript" src="path/to/jquery.print.js" />
And use below in document.ready() function

$("#myElementId").print(/*options*/);
or

$.print("#myElementId" /*, options*/);
Advance parameters are below:


$("#myElementId").print({
addGlobalStyles : true,
stylesheet : null,
rejectWindow : true,
noPrintSelector : ".no-print",
iframe : true,
append : null,
prepend : null
});

Sample Code:
Download JQuery.print.js and Put below code in your tag:


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
            <script src="jQuery.print.js"></script>
            <script>
                $(document).ready(function() {
                    $(".print_div").find('button').on('click', function() {
                        var dv_id = $(this).parents(".print_div").attr('id');
                        //Print ele4 with custom options
                        $('#' + dv_id).print({
                            //Use Global styles
                            globalStyles: false,
                            //Add link with attrbute media=print
                            mediaPrint: false,
                            //Custom stylesheet
                            stylesheet: "http://fonts.googleapis.com/css?family=Inconsolata",
                            //Print in a hidden iframe
                            iframe: true,
                            //Don't print this
                            noPrintSelector: ".avoid-this"
                        });
                    });
                });
            </script>
            <div class="content">
                <div class="heading">
                    Print Page or Section of Page using JQuery
                </div>
                <div id='dv1'>
                    <div id='print-div1' class="print_div"><b>Print Text</b>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,<button class="print-link avoid-this"> Print this </button></div>
                    <div id='print-div2' class="print_div"><b>Print Text with Image  </b><img src="jquery-devzone.co.in.png" height="100" width="150"/>Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,<button class="print-link avoid-this"> Print this </button></div>
                    <div id='print-div3' class="print_div">
                        <b>Print Table  </b>
                        <style type="text/css">
                            table.gridtable {
                                font-family: verdana,arial,sans-serif;
                                font-size:11px;
                                color:#333333;
                                border-width: 1px;
                                border-color: #666666;
                                border-collapse: collapse;
                            }
                            table.gridtable th {
                                border-width: 1px;
                                padding: 8px;
                                border-style: solid;
                                border-color: #666666;
                                background-color: #dedede;
                            }
                            table.gridtable td {
                                border-width: 1px;
                                padding: 8px;
                                border-style: solid;
                                border-color: #666666;
                                background-color: #ffffff;
                            }
                        </style>
                        <table class="gridtable">
                            <tr>
                                <th>Header 1</th><th>Header 2</th><th>Header 3</th>
                            </tr>
                            <tr>
                                <td>Text 1A</td><td>Text 1B</td><td>Text 1C</td>
                            </tr>
                            <tr>
                                <td>Text 2A</td><td>Text 2B</td><td>Text 2C</td>
                            </tr>
                            <tr>
                                <td>Text 3A</td><td>Text 3B</td><td>Text 3C</td>
                            </tr>
                        </table>
                        <button class="print-link avoid-this"> Print this</button>
                    </div>
                </div>
                <div style="clear:both;"></div>
                <button class="print-link avoid-this" onclick="$('body').print({noPrintSelector: '.avoid-this'});"> Print Page </button>            </div></div>

Download Code Sample:
https://drive.google.com/file/d/0B-CQMvJeiunsS3BTcGhraVlVMlU/view?usp=sharing