Saturday, 18 April 2015

random string genrate in php

<?php
function Password_genrator($length = 10) {
    $characters = '0123456789!@#$%^&*abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}

echo Password_genrator();

?>

Wednesday, 11 March 2015

inactive user session expire in php

 <?php

$expireAfter = 5; //expire session after 5 mints.
if(isset($_SESSION['last_action'])){

    $secondsInactive = time() - $_SESSION['last_action'];
  
  
    $expireAfterSeconds = $expireAfter * 60;
  
  
    if($secondsInactive >= $expireAfterSeconds){
        unset($_SESSION['vendor']);
    }
  
}

$_SESSION['last_action'] = time();

?>

simple pop up through css

<style type="text/css">
.blankdiv{background-color:#000;
position:fixed;
z-index: 9001;
top:0px; height:100%;
left:0px;
width:100%; opacity: 0.65;
filter:alpha(opacity=65);}


#popupform{height: 100%;
    left: 0;
    padding: 15px;
    position: fixed;
    top: 0;
    width:97%;
    z-index: 10001;
    }
  
#popupform .applyform{position:relative; overflow:auto;
background-color:#fff;
width:670px;
height:500px;  margin:5% auto auto auto;
z-index: 9002; padding:10px; border:10px solid #7F3814; }


#pclose{
    background-position: left top;
    background-repeat: no-repeat;
    cursor: pointer;
    height: 25px;
    margin: 5% auto -6%;
    position: relative;
    right: -324px;
    top: 24px;
    width: 25px;
    z-index: 9999;}
</style>

  <a href="javascript:void(0)" id="apply" onclick="javascript:document.getElementById('popupform').style.display='block';return false;">Click Me</a>
 <div id="popupform" style="display:none">
  <div class="blankdiv"></div>
  <div id="pclose" onclick="javascript:document.getElementById('popupform').style.display='none';">close</div>
    <div class="applyform">
        <p id="contactArea">
        purushotam
        </p>
    </div>
 </div>

Friday, 27 February 2015

how to remove no selected file in javascript

<div><input type='file' title="Choose a video please" id="aa" onchange="pressed()"><label id="fileLabel">Select New file</label></div>

<style>
input[type=file]{
    width:80px;
    color:transparent;
}

</style>


<script>
window.pressed = function(){
    var a = document.getElementById('aa');
    if(a.value == "")
    {
        fileLabel.innerHTML = "Select New file";
    }
    else
    {
        var theSplit = a.value.split('\\');
        fileLabel.innerHTML = theSplit[theSplit.length-1];
    }
};
</script>

Thursday, 26 February 2015

get last 30 days data in php

select * from `tablename` where `yourdatefield` >= 
 DATE_SUB(CURDATE(), INTERVAL 30 DAY)

Monday, 16 February 2015

set timezone and get timezone in php

 1.) Set timezone :-
<?php echo date_default_timezone_set("Asia/Kolkata"); ?>

 2.) Get timezone :-
<?php echo date_default_timezone_get(); ?>

export sql table to csv format in php

<?php 
//First create db connection.
$output = "";
$sql = mysql_query("select col1,col2,col3 from table_name where 1");
$columns_total = mysql_num_fields($sql);
for ($i = 0; $i < $columns_total; $i++) {
$heading = mysql_field_name($sql, $i);
$output .= '"'.$heading.'",';
}
$output .="\r\n";
while ($row = mysql_fetch_array($sql)) {
for ($i = 0; $i < $columns_total; $i++) {
$output .='"'.$row["$i"].'",';
}
$output .="\n";
}
$filename = "Vendor-data-export.csv";
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename='.$filename);

echo $output;
?>