Friday, December 13, 2013

Disable F5 keyboard key using jquery

// Load latest jquery
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

// Script

<script type="text/javascript">
function disable_f5(e)
{
  if ((e.which || e.keyCode) == 116)
  {
      e.preventDefault();
  }
}

$(document).ready(function(){
    $(document).bind("keydown", disable_f5);   
});
</script>

Monday, December 02, 2013

Get Facebook Share ,Like , Comments Count

Just Run the follwing Code , Please assign your url in $source_url
 
<?php
 
$source_url = "http://www.flightpodcast.com/episode-6-john-bartels-qantas-qf30";
$url = "http://api.facebook.com/restserver.php?method=links.getStats&urls=".urlencode($source_url);
$xml = file_get_contents($url);
$xml = simplexml_load_string($xml);

echo "Share --- ".$shares = $xml->link_stat->share_count;
echo "<br/>";

echo "Like --- ".$likes = $xml->link_stat->like_count;
echo "<br/>";

echo "Comments ---".$comments = $xml->link_stat->comment_count; 
echo "<br/>";

echo "Total --- ".$total = $xml->link_stat->total_count;
echo "<br/>";

Wednesday, November 20, 2013

jQuery - show only current ul

Here the simple explanations with demo.

STEP 1:
<nav>
    <li><a href="#">1.0.0</a></li>
    <li><a href="#">2.0.0</a>
        <ul class='children'>
            <li><a href="#">2.1.0</a>
                <ul class='children'>
                    <li><a href="#">2.1.1</a></li>
                    <li><a href="#">2.1.2</a></li>
                </ul>
            </li>
            <li><a href="#">2.2.0</a>
                <ul class='children'>
                    <li><a href="#">2.2.1</a></li>
                    <li><a href="#">2.2.2</a></li>
                    <li><a href="#">2.2.3</a></li>
                    <li><a href="#">2.2.4</a></li>
                </ul>
            </li>
        </ul>
    </li>
    <li><a href="#">3.0.0</a></li>
    <li><a href="#">4.0.0</a></li>
    <li><a href="#">5.0.0</a></li>
</nav>

STEP 2:
<script type='text/javascript' src='http://code.jquery.com/jquery-1.6.2.js'></script>
<script>
$("nav li").find("ul").hide().end().find("a")
// hide all other ul's in the nav
.click(function(e) {
    $(this).parent().siblings().find('ul').fadeOut('fast');
    $(this).parent().children('ul').delay(200).fadeToggle('fast');
});
</script>

STEP 3:
<style>
body {
    font-size: 12px;
    line-height: 16px;
    font-family: "Helvetica Neue", Arial, sans-serif;
    color: #575757;
}
a, a:active, a:visited {
    color:#575757;
    text-decoration:none;
}
a:hover {
    color:#888888;
}
nav {
    font-size: 14px;
    text-transform:uppercase;
    position:relative;
}
.children {
    width:146px;
    top:0;
    position:absolute;
    margin-left: 160px;
}
.selected { color:blue; }
</style>

Demo url : http://fiddle.jshell.net/866UZ/show/

Thanks to fiddle , its learn and run from that site and thanks to jquery :)

Wednesday, November 13, 2013

Get Ajax respone data from outside of success handler

 You must use async false in ajax

<script type="text/javascript">
var ajaxResponse;
    
    $.ajax({
            type: "POST",
            url: "get_price.php",
            async: false,
            data: "var"+var1,
            cache: false,
            success: function(response){
                ajaxResponse  = response;
            }
        });        

alert(ajaxResponse);
</script>
 

Monday, November 11, 2013

Customize facebook's sharer.php

Facebook Share button, or commonly known as sharer.php is the easiest way to share link on Facebook. It is easy to use. You don't need an App ID, and you don't need to include any Facebook dependencies.

Simply : 
http://www.facebook.com/sharer.php?u=http://yoursite.com&t=Here's my customized title

I could dynamically generate customized og tag, but due to Facebook caching mechanism there's almost no point of doing that.

Customize :
http://www.facebook.com/sharer.php?s=100
&p[url]=http://yoursite.com
&p[images][0]=http://yoursite.com/assets/vote.png
&p[title]=My customized title
&p[summary]=My customized summary


open-graph-protocol-examples:
https://github.com/niallkennedy/open-graph-protocol-examples


Debugger:
Debug your url and check everything fine .
Input URL, Access Token, or Open Graph Action ID

https://developers.facebook.com/tools/debug/

og tags:
<head prefix="og: http://ogp.me/ns#">
<meta charset="utf-8">
<title>Structured audio property</title>
<meta property="og:title" content="Structured audio property">
<meta property="og:site_name" content="Open Graph protocol examples">
<meta property="og:type" content="website">
<meta property="og:locale" content="en_US">
<link rel="canonical" href="http://examples.opengraphprotocol.us/audio-url.html">
<meta property="og:url" content="http://examples.opengraphprotocol.us/audio-url.html">
<meta property="og:image" content="http://examples.opengraphprotocol.us/media/images/50.png">
<meta property="og:image:secure_url" content="https://d72cgtgi6hvvl.cloudfront.net/media/images/50.png">
<meta property="og:image:width" content="50">
<meta property="og:image:height" content="50">
<meta property="og:image:type" content="image/png">
<meta property="og:audio:url" content="http://examples.opengraphprotocol.us/media/audio/250hz.mp3">
<meta property="og:audio:secure_url" content="https://d72cgtgi6hvvl.cloudfront.net/media/audio/250hz.mp3">
<meta property="og:audio:type" content="audio/mpeg">
</head>

Monday, October 14, 2013

Scroll Bar Display For iPad - overflow-auto - css - Fixed

To display Scroll Bar for your overflow-auto

Please use the following css code
<style>
::-webkit-scrollbar {
    -webkit-appearancenone;
    width7px;
}
::-webkit-scrollbar-thumb {
    border-radius4px;
    background-colorrgba(0,0,0,.5);
    -webkit-box-shadow1px rgba(255,255,255,.5);
}
</style>

Friday, September 27, 2013

Database exported automatically in mysql

Simply to export database in mysql and stored in your particular path. See the following code and run in your system with your db details. After run successfully set the file in cron job. so you get the db backup daily or weekly or monthly to store automatically and take from particular path. cheers :)

<?php
$db_host="localhost"; //your host name
$db_user="root"; //your db user name
$db_pass="root"; //your db password
$db_name="test_db"; //your db name
$tables="*"; // all tables to select as *

db_backup($db_host,$db_user,$db_pass,$db_name,$tables);


function db_backup($db_host,$db_user,$db_pass,$db_name,$tables = '*')
{

  $con= mysql_connect($db_host,$db_user,$db_pass);
  mysql_select_db($db_name,$con);

  //get all of the tables
  if($tables == '*')
  {
    $tables = array();
    $result = mysql_query('SHOW TABLES');
    while($row = mysql_fetch_row($result))
    {
      $tables[] = $row[0];
    }
  }
  else
  {
    $tables = is_array($tables) ? $tables : explode(',',$tables);
  }

  //cycle through
  foreach($tables as $table)
  {
    $result = mysql_query('SELECT * FROM '.$table);
    $num_fields = mysql_num_fields($result);

    $return.= 'DROP TABLE IF  EXISTS '.$table.';';
    $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
    $return.= "\n\n".$row2[1].";\n\n";

    for ($i = 0; $i < $num_fields; $i++)
    {
      while($row = mysql_fetch_row($result))
      {
        $return.= 'INSERT INTO '.$table.' VALUES(';
        for($j=0; $j<$num_fields; $j++)
        {
          $row[$j] = addslashes($row[$j]);
          $row[$j] = ereg_replace("\n","\\n",$row[$j]);
          if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
          if ($j<($num_fields-1)) { $return.= ','; }
        }
        $return.= ");\n";
      }
    }
    $return.="\n\n\n";
  }

  //save file
  $filename='db-backup-'.time().'.sql';
  $handle = fopen($filename,'w+');
  fwrite($handle,$return);
  fclose($handle);
}
?>

Tuesday, September 03, 2013

Downloading a remote file using curl

Just like the contents of a remote url can be fetched, a remote file with a given url can be downloaded and saved to local storage too.

    /**
        Download remote file in php using curl
        Files larger that php memory will result in corrupted data
    */
     $url  = 'http://localhost/sugar.zip';
     $path = '/var/www/lemon.zip';

     $ch = curl_init($url);
     if($ch === false)
     {
         die('Failed to create curl handle');
     }

     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

     $data = curl_exec($ch);
     file_put_contents($path, $data);
     echo 'File download complete';

     curl_close($ch); 

The above program can download remote files but has few restrictions. If the download file size is larger than the total amount of memory available to php, then either a memory exceeded error would be thrown or the downloaded file would be corrupt.

PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 60527991 bytes) in  /var/www/curl.php on line 19

Hence the problem has to be fixed as shown in the next code example  


/**
    Download remote file in php using curl
    chunking with fopen
*/
$url  = 'http://localhost/bang.zip';
$path = '/var/www/lemon.zip';

$ch = curl_init($url);
if($ch === false)
{
    die('Failed to create curl handle');
}

$fp = fopen($path, 'w');
  
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);
  
$data = curl_exec($ch);
  
curl_close($ch);
fclose($fp);

The above code would download large files and save them without any problem. The option CURLOPT_FILE tells curl to write the output to a file.

Wednesday, August 14, 2013

Top Ten Security Vulnerabilities in PHP Code

1. Unvalidated Parameters

Most importantly, turn off register_globals. This configuration setting defaults to off in PHP 4.2.0 and later. Access values from URLs, forms, and cookies through the superglobal arrays $_GET, $_POST, and $_COOKIE.
Before you use values from the superglobal arrays, validate them to make sure they don’t contain unexpected input. If you know what type of value you are expecting, make sure what you’ve got conforms to an expected format. For example, if you’re expecting a US ZIP Code, make sure your value is either five digits or five digits, a hyphen, and four more digits (ZIP+4). Often, regular expressions are the easiest way to validate data:
if (preg_match('/^\d{5}(-\d{4})?$/',$_GET['zip'])) {
    $zip = $_GET['zip'];
} else {
    die('Invalid ZIP Code format.');
}
If you’re expecting to receive data in a cookie or a hidden form field that you’ve previously sent to a client, make sure it hasn’t been tampered with by sending a hash of the data and a secret word along with the data. Put the hash in a hidden form field (or in the cookie) along with the data. When you receive the data and the hash, re-hash the data and make sure the new hash matches the old one:
// sending the cookie
$secret_word = 'gargamel';
$id = 123745323;
$hash = md5($secret_word.$id);
setcookie('id',$id.'-'.$hash);

// receiving and verifying the cookie
list($cookie_id,$cookie_hash) = explode('-',$_COOKIE['id']);
if (md5($secret_word.$cookie_id) == $cookie_hash) {
    $id = $cookie_id;
} else {
    die('Invalid cookie.');
}

If a user has changed the ID value in the cookie, the hashes won’t match. The success of this method obviously depends on keeping $secret_word secret, so put it in a file that can’t be read by just anybody and change it periodically. (But remember, when you change it, old hashes that might be lying around in cookies will no longer be valid.)


2. Broken Access Control

Instead of rolling your own access control solution, use PEAR modules. Auth does cookie-based authentication for you and Auth_HTTP does browser-based authentication.


3. Broken Account and Session Management

Use PHP’s built-in session management functions for secure, standardized session management. However, be careful how your server is configured to store session information. For example, if session contents are stored as world-readable files in /tmp, then any user that logs into the server can see the contents of all the sessions. Store the sessions in a database or in a part of the file system that only trusted users can access.

To prevent network sniffers from scooping up session IDs, session-specific traffic should be sent over SSL. You don’t need to do anything special to PHP when you’re using an SSL connection, but you do need to specially configure your webserver.


4. Cross-Site Scripting (XSS) Flaws

Never display any information coming from outside your program without filtering it first. Filter variables before including them in hidden form fields, in query strings, or just plain page output.
PHP gives you plenty of tools to filter untrusted data:

  • htmlspecialchars() turns & > " < into their HTML-entity equivalents and can also convert single quotes by passing ENT_QUOTES as a second argument.
  • strtr() filters any characters you’d like. Pass strtr() an array of characters and their replacements. To change ( and ) into their entity equivalents, which is recommended to prevent XSS attacks, do:
    $safer = strtr($untrusted, array('(' => '(', ')' => ')'));
  • strip_tags() removes HTML and PHP tags from a string.
  • utf8_decode() converts the ISO-8859-1 characters in a string encoded with the Unicode UTF-8 encoding to single-byte ASCII characters. Sometimes cross-site scripting attackers attempt to hide their attacks in Unicode encoding. You can use utf8_decode() to peel off that encoding.

5. Buffer Overflows

You can’t allocate memory at runtime in PHP and their are no pointers like in C so your PHP code, however sloppy it may be, won’t have any buffer overflows. What you do have to watch out for, however, are buffer overflows in PHP itself (and its extensions.) Subscribe to the php-announce mailing list to keep abreast of patches and new releases.

6. Command Injection Flaws

Cross-site scripting flaws happen when you display unfiltered, unescaped malicious content to a user’s browser. Command injection flaws happen when you pass unfiltered, unescaped malicious commands to an external process or database. To prevent command injection flaws, in addition to validating input, always escape user input before passing it to an external process or database.

If you’re passing user input to a shell (via a command like exec(), system(), or the backtick operator), first, ask yourself if you really need to. Most file operations can be performed with native PHP functions. If you absolutely, positively need to run an external program whose name or arguments come from untrusted input, escape program names with escapeshellcmd() and arguments with escapeshellarg().

Before executing an external program or opening an external file, you should also canonicalize its pathname with realpath(). This expands all symbolic links, translates . (current directory) .. (parent directory), and removes duplicate directory separators. Once a pathname is canonicalized you can test it to make sure it meets certain criteria, like being beneath the web server document root or in a user’s home directory.


If you’re passing user input to a SQL query, escape the input with addslashes() before putting it into the query. If you’re using MySQL, escape strings with mysql_real_escape_string() (or mysql_escape_string() for PHP versions before 4.3.0). If you’re using the PEAR DB database abstraction layer, you can use the DB::quote() method or use a query placeholder like ?, which automatically escapes the value that replaces the placeholder.

7. Error Handling Problems

If users (and attackers) can see the raw error messages returned from PHP, your database, or external programs, they can make educated guesses about how your system is organized and what software you use. These educated guesses make it easier for attackers to break into your system. Error messages shouldn’t contain any descriptive system information. Tell PHP to put error messages in your server’s error log instead of displaying them to a user with these configuration directives:

log_errors = On
display_errors = Off

8. Insecure Use of Cryptography

The mcrypt extension provides a standardized interface to many popular cryptographic algorithms. Use mcrypt instead of rolling your own encryption scheme. Also, be careful about where (if anywhere) you store encryption keys. The strongest algorithm in the world is pointless if an attacker can easily obtain a key for decryption. If you need to store keys at all, store them apart from encrypted data. Better yet, don’t store the keys and prompt users to enter them when something needs to be decrypted. (Of course, if you’re prompting a user over the web for sensitive information like an encryption key, that prompt and the user’s reply should be passed over SSL.)

9. Remote Administration Flaws

When possible, run remote administration tools over an SSL connection to prevent sniffing of passwords and content. If you’ve installed third-party software that has a remote administration component, change the default administrative user names and passwords. Change the default administrative URL as well, if possible. Running administrative tools on a different web server than the public web server that the administrative tool administrates can be a good idea as well.

10. Web and Application Server Misconfiguration

Keep on top of PHP patches and security problems by subscribing to the php-announce mailing list. Stay away from the automatic PHP source display handler (AddType application/x-httpd-php-source .phps), since it lets attackers look at your code. Of the two sample php.ini files distributed with PHP ( php.ini-dist and php.ini-recommended), use php.ini-recommended as a base for your site configuration.

How to speed up your php website

There is a nice technique to reduce the amount of calls your browsers has to make to the server. This will be every image, every css and every JavaScript file included in the webpage. Each time you want to load in one of these elements you will be sending a request to the server which will return the requested object known as a HTTP request.

Reduce Page Loading Time With PHP

Each one of these uses up time on your page loading, so to reduce page load all you have to do is reduce the amount of calls being made. But what if you want to organise you JavaScript files, jquery file, general file, application file and page file. There could be upto 4 requests for some javascript for the page.

It is possible in PHP to combine these JavaScript files together and trick the browser into thinking they are just one JavaScript file, therefore reducing the amount of calls being made to the server. This is done by reading the JavaScript with PHP then changing the header to JavaScript like the example below.

Create a PHP file and use the readfile function to bring in your Javascript files then change the header to Javascript and the server will treat this page as Javascript.

readfile(jquery.js’);
readfile(general.js’);
readfile(jquery-ui.js’);
readfile(page.js’);
header(‘Content-type: text/javascript’);



This technique can be used for css files too.. cheers and thanks to paulund.

ffmpeg mp3 file crop and reduce bit rate

FFmpeg is a complete, cross-platform solution to record, convert and stream audio and video. It includes libavcodec - the leading audio/video codec library.

Now i am used this ffmpeg tool to crop the mp3 song for particular minutes and change the quality of the song.

CROP:

  • ffmpeg -t and -ss (output-only) options are now sample-accurate when trans-coding audio
  • 1 is the starting point of the mp3 and 120 is the number of seconds   crop the song.
  • input.mp3 is your input file name and output.mp3 is the result store that name  in the same path.

Example:  exec("ffmpeg -ss 1 -t 120 -acodec copy -i input.mp3 output.mp3");

Change the bit rate:

  • Convert mp3 to lower bitrate using ffmpeg
  • 96k is the bit rate. if you want like 126k ,320k just need to adjust that.

Example: exec("ffmpeg -i input.mp3 -ar 44100 -ab 96k -f mp3 output.mp3");



Wednesday, July 31, 2013

Quickly Removing Empty Array Elements in PHP

Different ways of removing empty array slots in PHP.

Removing empty array slots in PHP, leaving holes in the array.

A quick way to remove empty elements from an array is using array_filter without a callback function. This will also remove 0s (zeroes) though.

$myArray = array_filter( $myArray );

Alternatively, array_diff allows you to decide which elements to keep. The following example will only remove empty strings, but keep 0

$myArray = array_diff($myArray, array(''));

Removing empty array slots in PHP, and compacting the array
Both functions leave ‘gaps’ where the empty entries used to be:

$myArray = array( 0, 'red', '', 'blue');

print_r(array_filter($myArray));
Array
(
  [1] => 'red'
  [3] => 'blue'
)

print_r(array_diff($myArray, array('')));
Array
(
  [0] => 0
  [1] => 'red'
  [3] => 'blue'
)

array_slice can remove those gaps:

$myArray = array(0, 'red', '', 'blue');
$myArray = array_filter($myArray);
print_r(array_slice($myArray, 0));
Array
(
  [0] => 'red'
  [1] => 'blue'
)

see whether it is faster than a loop.

One more example

    $data = array(42, "foo", 96, "", 100.96, "php");
   
    // Filter each value of $data through the function is_numeric
    $numeric_data = array_filter($data, "is_numeric");
   
    // Re-key the array so the keys are sequential and numeric (starting at 0)
    $numeric_data = array_values($numeric_data);
   
    // Print out the new, filtered data
    print_r($numeric_data);

The output from above is:

Array
(
    [0] => 42
    [1] => 96
    [2] => 100.96
)

Wednesday, June 19, 2013

Remove duplicate array keys and values with case insensitive.

We have two array.
First array contains some key and values.
Second array contains some keys and values.
I want to merge this two array if duplicate values occurred remove first array duplicate value only.
I want to check key and value is case insensitive.

Please use below code for these requirements.

Code :

<?php
$alname = array(
    "CHE" => "Chennai" ,
    "JKT" => "Jakarta" ,
    "KOL" => "Kolkata" ,
    "MDU" => "Madurai" ,
    "MUM" => "Mumbai" ,
    "SHG" => "Shanghai" );

$alname1 =  array(
    "TKY" => "Tokyo" ,
    "MXI" => "Mexico City" ,
    "DHI" => "Delhi" ,
    "KAR" => "Karachi" ,
    "CHN" => "CheNnai" ,
    "ShG" => "ShaNghai" ,
    "ISB" => "Istanbul" );
   
    echo "<pre>";
    echo "<br/>First Array : <br/>";
    print_r($alname);
    echo "<br/>Second Array : <br/>";
    print_r($alname1);
   
    $arr2 = array_merge($alname,$alname1);
    echo "<br/>Merge first and second array Before remove duplicate values : <br/>";
    print_r($arr2);
   
    foreach($alname as $alkey => $alval)
        {
           $slow_key = strtolower($alkey);
           $slow_val = strtolower($alval);
           $slow_alname1 = unserialize(strtolower(serialize($alname1)));
           $slow_alname1 = array_change_key_case($slow_alname1,CASE_LOWER);
           if(isset($slow_alname1[$slow_key]))
           {
             unset($alname[$alkey]);
           }
          
           if(in_array($slow_val,$slow_alname1))
           {
              unset($alname[$alkey]);
           }
          
        }
        $arr2 = array_merge($alname,$alname1);
        echo "<br/><br/>Merge first and second array After remove duplicate values : <br/><br/>";
        print_r($arr2);
        echo "</pre>";
       
?>


OUTPUT :



Tuesday, May 28, 2013

Convert Array To Object

Use json_encode - convert array to json.
Json_decode - Convert json to PHP array or Object.
If set json_decode  json value , option TRUE comes to array value.
If set json_decode  json value , option FALSE comes to php Object.

<?php
$array = array("UID" => "615371-9834293-3232","code" => "AEPVC1");
$object = json_decode(json_encode($array), FALSE);
echo "<pre>";
print_r($array);
print_r($object);
echo "</pre>";
?>

Output :
 
Array
(
    [UID] => 615371-9834293-3232
    [code] => AEPVC1
)
stdClass Object
(
    [UID] => 615371-9834293-3232
    [code] => AEPVC1
)

Monday, May 27, 2013

Jquery UI Tab With Iframe Example

If You use Jquery ui tab and iframe use inside tab content.
It rasied some issues.you will use below code for jquery ui tab avoid issues and run perfectly.




 Code:

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Tabs with Iframe Example</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css" />
<script>
$(function() {
 $("#vlayout_tabs").tabs();
   iframe_pop($("#vlayout_tabs ul li:eq(0) a.tab_lnk").attr("href"),$("#vlayout_tabs ul li:eq(0) a.tab_lnk").attr("rel"));
          
                $("a.tab_lnk").click(function() {
                   iframe_pop($(this).attr("href"),$(this).attr("rel"));
               });

});

  function iframe_pop(tab, url) {
                if ($(tab).find("iframe").length == 0) {
                    var html_cnt = [];
                    html_cnt.push('<iframe class="iframetab" src="' + url + '" width="670" height="700">Load Failed?</iframe>');
                    $(tab).find('.tb_content').append(html_cnt.join(""));
                }
                return false;
            }

</script>
</head>
<body>
     <div id="vlayout_tabs">
<ul>
<li><a href="#tabs-1" class="tab_lnk" rel="http://jquery.com/">Jquery</a></li>
<li><a href="#tabs-2" class="tab_lnk" rel="http://jqueryui.com/">Jquery UI</a></li>
<li><a href="#tabs-3" class="tab_lnk" rel="http://ellislab.com/codeigniter">Codeigniter</a></li>
</ul>
<div id="tabs-1">
    <div class="tb_content">
       &nbsp;
    </div>
<p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.</p>
</div>
<div id="tabs-2">
    <div class="tb_content">
       &nbsp;
    </div>
<p>Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante, ut pharetra massa metus id nunc. Duis scelerisque molestie turpis. Sed fringilla, massa eget luctus malesuada, metus eros molestie lectus, ut tempus eros massa ut dolor. Aenean aliquet fringilla sem. Suspendisse sed ligula in ligula suscipit aliquam. Praesent in eros vestibulum mi adipiscing adipiscing. Morbi facilisis. Curabitur ornare consequat nunc. Aenean vel metus. Ut posuere viverra nulla. Aliquam erat volutpat. Pellentesque convallis. Maecenas feugiat, tellus pellentesque pretium posuere, felis lorem euismod felis, eu ornare leo nisi vel felis. Mauris consectetur tortor et purus.</p>
</div>
<div id="tabs-3">
    <div class="tb_content">
       &nbsp;
    </div>
<p>Mauris eleifend est et turpis. Duis id erat. Suspendisse potenti. Aliquam vulputate, pede vel vehicula accumsan, mi neque rutrum erat, eu congue orci lorem eget lorem. Vestibulum non ante. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce sodales. Quisque eu urna vel enim commodo pellentesque. Praesent eu risus hendrerit ligula tempus pretium. Curabitur lorem enim, pretium nec, feugiat nec, luctus a, lacus.</p>
<p>Duis cursus. Maecenas ligula eros, blandit nec, pharetra at, semper at, magna. Nullam ac lacus. Nulla facilisi. Praesent viverra justo vitae neque. Praesent blandit adipiscing velit. Suspendisse potenti. Donec mattis, pede vel pharetra blandit, magna ligula faucibus eros, id euismod lacus dolor eget odio. Nam scelerisque. Donec non libero sed nulla mattis commodo. Ut sagittis. Donec nisi lectus, feugiat porttitor, tempor ac, tempor vitae, pede. Aenean vehicula velit eu tellus interdum rutrum. Maecenas commodo. Pellentesque nec elit. Fusce in lacus. Vivamus a libero vitae lectus hendrerit hendrerit.</p>
</div>
</div>


</body>
</html>

Output :




Sunday, May 26, 2013

Generate URL-encoded query string (http_build_query) :



If you passed associative array and return result is query string with encoded.

Code:

<?php
$data = array('foo'=>'bar',
              'baz'=>'boom',
              'cow'=>'milk',
              'php'=>'hypertext processor');

echo http_build_query($data) . "\n";
echo http_build_query($data'''&amp;');

?>

OutPut:

foo=bar&baz=boom&cow=milk&php=hypertext+processor
foo=bar&amp;baz=boom&amp;cow=milk&amp;php=hypertext+processor

 


Friday, May 24, 2013

send sms from website in php


 Send message from your site to any one mobile , simply use this script and do it .Register in mvaayoo.com and get the username and password. Free account only get 20 messages.

$ch = curl_init();
$user="yourmail@gmail.com:yourpassword";
$receipientno="919849558211";
$senderID="mVaayoo";
$msgtxt="this is test message , test";
curl_setopt($ch,CURLOPT_URL,  "http://api.mVaayoo.com/mvaayooapi/MessageCompose");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "user=$user&senderID=$senderID&receipientno=$receipientno&msgtxt=$msgtxt");
$buffer = curl_exec($ch);
if(empty ($buffer))
{ echo " buffer is empty "; }
else
{ echo $buffer; }
curl_close($ch);

special thanks to mvaayoo.com . cheers friends :)

5 Reasons Why the Web Platform War is Over: PHP Won with 75% says Google



Google I/O is a event mainly for developers that Google organizes every year to present the latest developments of their products.
This year Google announced a new language being supported in AppEngine, their so called "cloud" hosting platform. This time the new language was PHP.
A Google manager for AppEngine explained that PHP is running in 75% of the Web sites. That explains why PHP support is the top most requested feature for AppEngine.

For more please see here.


http://www.phpclasses.org/blog/post/208-5-Reasons-Why-the-Web-Platform-War-is-Over-PHP-Won-with-75-says-Google.html

Wednesday, May 22, 2013

Ternary Operators (?:)


What Does Ternary Logic Look Like?

/* most basic usage */
$var = 5;
$var_is_greater_than_two = ($var > 2 ? true : false); // returns true

What Are The Advantages of Ternary Logic?
There are some valuable advantages to using this type of logic:
  • Makes coding simple if/else logic quicker
  • You can do your if/else logic inline with output instead of breaking your output building for if/else statements
  • Makes code shorter
  • Makes maintaining code quicker, easier

How to Import Data in MySql from MS SQL SERVER


I have a very good and Easy Steps for import Data in MySql from MS SQL Server.

1.) First of All You have to open Visual Studio 2010.

2.) Go to Server Explorer.

3.) Add a New Connection of MySql.

4.) Add Database which you want to import Data From SQL Server Db.

5.) Add another Connection of MS SQL Server.

6.) Add Database which you want to Export Data for MySql.

7.) Now you have Opened both Databases in Server Explorer of Visual Studio 2010.

8.) Now Right Click on Table (which you want to copy data to MySql) and click on SHOW TABLE DATA.

9.) Now Select All data from your table and Copy that records.

10.) Now Open MySql Database and open same Table (which you want to paste data into) from MySql and Paste all Data you copied from MS SQL SERVER.

Tuesday, May 21, 2013

Send mail with multiple attachments in php

Following these two steps to send multiple attachments in mail.

Step 1: 

<html>  
<head>  
<title>How to send mail in PHP with multiple attachments</title>  
</head>  
<body>    
<form name="sendmail" action="sendmail.php" method="post" enctype="multipart/form-data">  
    <label>E-mail ID:</label>  
    <input name="email" type="text" /><br />  
  
    <label>Subject:</label>  
    <input name="subject" type="text" /><br />  
  
    <label>Body:</label><br />  
    <textarea name="body" rows="4"></textarea><br />  
  
    <label>Attachments:</label><br />  
    <input name="file1" type="file" /><br />  
    <input name="file2" type="file" /><br />  
    <input name="file3" type="file" /><br />  
  
    <input name="submit" type="submit" value="Send Mail" />  
</form>    
</body>  
</html> 

Step 2:  (sendmail.php)

<?php  
$from = "YOUR FROM EMAIL";  
$to = $_POST['email'];  
$subject =$_POST['subject'];  
$message = $_POST['body'];  
  
// Temporary paths of selected files  
$file1 = $_FILES['file1']['tmp_name'];  
$file2 = $_FILES['file2']['tmp_name'];  
$file3 = $_FILES['file3']['tmp_name'];  
  
// File names of selected files  
$filename1 = $_FILES['file1']['name'];  
$filename2 = $_FILES['file2']['name'];  
$filename3 = $_FILES['file3']['name'];  
  
// array of filenames to be as attachments  
$files = array($file1, $file2, $file3);  
$filenames = array($filename1, $filename2, $filename3);  
  
// include the from email in the headers  
$headers = "From: $from";  
  
// boundary  
$time = md5(time());  
$boundary = "==Multipart_Boundary_x{$time}x";  
  
// headers used for send attachment with email  
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$boundary}\"";  
  
// multipart boundary  
$message = "--{$boundary}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";  
$message .= "--{$boundary}\n";  
  
// attach the attachments to the message  
for($x = 0; $x < count($files); $x++) {  
    $file = fopen($files[$x],"r");  
    $content = fread($file,filesize($files[$x]));  
    fclose($file);  
    $content = chunk_split(base64_encode($content));  
    $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" . "Content-Disposition: attachment;\n" . " filename=\"$filenames[$x]\"\n" . "Content-Transfer-Encoding: base64\n\n" . $content . "\n\n";  
    $message .= "--{$boundary}\n";  
}  
  
// sending mail  
$sendmail = mail($to, $subject, $message, $headers);  
  
// verify if mail is sent or not  
if ($sendmail) {  
    echo "Mail Sent successfully!";  
} else {  
    echo "Error occurred!!!";  
}  
?> 

Now you learn how to send multiple attachment send in mail using php in simply two steps. special thanks to codegambler.com . Cheers!!!!!