Home

Friday, July 29, 2011

How to use PUSH in Javascript

<select name="sub_cat_id" id="sub_cat_id"  multiple="multiple">
                <option value="1">Dhirendra</option>
                <option value="2">Prashant</option>
                <option value="3">Darshak</option>
</select>

var combo1 = document.getElementById("sub_cat_id");
var len = combo1.length
        var i
        var chosen = new Array();
        var j=0;
        for (i = 0; i < len; i++) {
        if (combo1[i].selected) {
        chosen.push(combo1[i].value)
       
        }
        }

Thursday, July 28, 2011

Automatic Logout after 1 minutes of inactive PHP


Logout after 1 minutes.
$_SESSION['last_click']=time();
if(($_SESSION['last_click'] + 1*60) < time())
{
session_destroy();
header("location:index.php");
}

Saturday, July 23, 2011

Display data dynamically in Matrix form using PHP

<?php
    $i="";
    $display_columns = 3;
    $sqlm="SELECT * FROM tr_teams ORDER BY id";
    $rsm=mysql_query($sqlm) or die("Database Error".mysql_error());
    $count = mysql_num_rows($rsm);
    $padding = ($display_columns-1)-(($count-1)%$display_columns);                 
             
    echo '<table width="90%" class="plan">';
    while($row=mysql_fetch_array($rsm))
    { 
        if($i%$display_columns == 0)
            echo '<tr>';
            echo '<td>';                      
          
            echo $row['team_name'];
          
            echo '</td>';
             
        if($i%$display_columns == $display_columns-1)
            echo '</tr>';
            $i++;
    }
        if($padding!=0)
        { 
            for($i=0;$i<$padding;$i++)
                echo '<td></td>';
                echo '</tr>';
        }
    echo '</table>';
?>    

Tuesday, July 19, 2011

How to Get Parameters Values in HTML with Javascript

<a href="get.html?name=Dhirendra">Test</a>
<SCRIPT LANGUAGE=JAVASCRIPT TYPE="TEXT/JAVASCRIPT">

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
var frank_param = gup( 'name' );
//alert(frank_param);
document.write(frank_param);
</script>

Wednesday, July 13, 2011

Read files name in folder using php

<?php
                $dir = realpath('images/big');
                $images = scandir($dir);
                foreach ($images as $image)
                {
                    if (substr($image, 0, 1) != '.')
                    {
                        ?>
                        <li>
                            <a href="images/big/<?=$image;?>">
                                <img src="images/thumb/<?=$image;?>"/>
                            </a>
                        </li><?
                     
                    }
                }
                ?>

Friday, July 8, 2011

How to Save Images on your local drive script in php

<?php

$file=$_GET['file'];

//$file = 'monkey.gif';

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}
?>

Friday, July 1, 2011

In Wordpress Retrieves the information pertaining to the currently logged in user

<?php global $current_user;
      get_currentuserinfo();

      echo 'Username: ' . $current_user->user_login . "\n";
      echo 'User email: ' . $current_user->user_email . "\n";
      echo 'User first name: ' . $current_user->user_firstname . "\n";
      echo 'User last name: ' . $current_user->user_lastname . "\n";
      echo 'User display name: ' . $current_user->display_name . "\n";
      echo 'User ID: ' . $current_user->ID . "\n";
?>

In Wordpress Display content to registered users only

<?php global $user_login; get_currentuserinfo();
if ($user_login) :?>
<li><a href="your-uri-goes-here">Write a New Post</a></li>
<?php endif; ?>


This puts a link in to the write post page if the user is logged in. 
rathoddhirendra.blogspot.com-Google pagerank and Worth