Wednesday, December 28, 2016

Print header and footer on every printed page of a document HTML CSS

If you take the element that you want to be the footer and set it to be position:fixed and bottom:0, when the page prints it will repeat that element at the bottom of each printed page. The same would work for a header element, just set top:0 instead.


For example:
<div class="divFooter">Printed By Sharif</div>
CSS:
@media screen {
  div.divFooter {
    display: none;
  }
}
@media print {
  div.divFooter {
    position: fixed;
    bottom: 0;
  }
}

Monday, November 21, 2016

Calculate age from date of birth php

Most easiest way to find age (years/month)

 function return_age($dob){  
   $from = new DateTime($dob);  
   $to  = new DateTime('today');  
   if( $from->diff($to)->y!=0){  
        echo $from->diff($to)->y." Years";  
   }  
   else{  
     echo $from->diff($to)->m." Months";  
   }  
 }  

now use it echo return_age('2010-02-01');

if  age less than one year then it'll show month like 9 Months.

Saturday, November 12, 2016

incorrect integer value '' for column 'id' at row 1 mysql Solution

I just found that one of my applications no longer works in one server but same program working another server. 
A lot of head scratching ensued, as the same code is working still working perfectly elsewhere. I checked the php versions and configs, checked the apache setups, all similar enough not to cause any problems. The only clue to what was going on was a mysql log file entry of:
Incorrect integer value: '' for column 'id' at row 1
Now, this isn't a bug, as int_column = '', is basically saying set the int_column to be a string of no value or a NULL value, which is not an integer, so it shouldn't be allowed to be inserted into the table, but previously MySQL would have converted this to the empty value and auto-incremented my int_column.
You can test this using the following:
CREATE TABLE `int_column_test` (

`int_column_id` INT NOT NULL

) TYPE = MYISAM ;


INSERT INTO int_column_test SET int_column_id = '';
You should get the Incorrect integer value: '' for column 'int_column_id' at row 1 error.
This is an sql-mode issue, the mode defines what SQL syntax should be supported and what kind of data validation should be performed. In my problem MySQL is trying to assign an empty string to an auto-increment INT field and, as we should all know, strings into INTs don't go. Cue errors and the script dies.
Longer term I am going to have to re-work my code to fix this issue, but in the short term, I am going to reduce the sensitivity of the control. To lower the level of data validation we can set the sql-mode to a lower level or comment it out altogether.
Short Term Solution
Edit the my.cnf (my.ini in windows) file and find and comment out the line:
#sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

The STRICT_TRANS_TABLES or it might be STRICT_ALL_TABLES is the bit that is causing the problem for me and with that line gone, STRICT mode is disallows invalid or missing values in a statement and aborts the command.
With this line commented out, STRICT mode is no longer applied and MySQL should now insert adjusted values for invalid or missing values and more specifically, it should allow my empty string to be put into the int column.
Long Term Solution
I think, I will have to remove all mentions of the id field from my INSERT commands, so that a value is not assigned and the auto-increment is left to do its own thing.

Saturday, October 22, 2016

School Session

<label>Session  </label>
                                    <select name="year" required class="form-control">
                                         <?php  for ($i=$start_year;$i<$end_year;$i++)
                                                {
                                                    $j=$i+1;
                                                    echo '<option value="'.$i."-".$j.'"';  if(date("Y")==$i) echo 'selected="selected"'; echo '>'.$i."-".$j.'</option>';
                                                }  ?>
                                        <?php echo isset($_POST['year']) ?
                                        '<option value="'.$_POST['year'].'" selected="selected">'.$_POST['year'].'</option>'  : ''; ?>                                              
                                    </select>

Tuesday, September 27, 2016

Best way to add/insert to array in php

<?php
$array = array();
for (
$x 1$x <= 100000$x++)
{
    
$array[] = $x;
}
?>
takes 0.0622200965881 seconds

and

<?php
$array 
= array();
for (
$x 1$x <= 100000$x++)
{
    
array_push($array$x);
}
?>

takes 1.63195490837 seconds

so if your not making use of the return value of array_push() its better to use the $array[] way.

Hope this helps someone.

Best way to add/insert to array in php

<?php
$array = array();
for (
$x 1$x <= 100000$x++)
{
    
$array[] = $x;
}
?>
takes 0.0622200965881 seconds

and

<?php
$array 
= array();
for (
$x 1$x <= 100000$x++)
{
    
array_push($array$x);
}
?>

takes 1.63195490837 seconds

so if your not making use of the return value of array_push() its better to use the $array[] way.

Hope this helps someone.

Wednesday, August 24, 2016

Line up text under Font Awesome icon

I am trying to display font awesome icon in a box like a button. I've been able to do that. So far so good...It'll look like this. without hover and with hover
HTML

 <div class="fa-hover">  
 <a href="www.awtsoft.com"><i class="fa fa-pencil-square-o fa-3x" aria-hidden="true"></i>New Post</a>   
 </div>  

CSS
 .fa-hover a {  
   overflow: hidden;  
   white-space: nowrap;  
   display: block;  
   color: #222;  
   line-height: 20px;  
   height: 80px;  
   padding: 10px;  
   border-radius: 4px;  
   border: 2px dotted greenyellow;  
 }  
 .fa-hover a:hover {  
   background-color: #1d9d74;  
   color: #fff;  
   text-decoration: none;  
 }  
 a i.fa {  
  display: block;  
  text-align: center;  
 }  

Thursday, August 18, 2016

Disk Quota in WHM/cpanel is not working properly

In my VPS server Disk Quota in WHM/cpanel is not working properly. Every account's disk quota is showing unlimited. There is a easily solution if you have SSH access

You can fix this issue by yourself.
You need to login SSH and just copy and past this command and press enter
"/scripts/fixquotas"

Then you'll get this following notice
" The '/'' partition uses the XFS® filesystem. You must reboot the server to enable quotas."

Then reboot the server to active this feature.

Saturday, August 6, 2016

Why API/ file(url) request is not working/sending in cpanel / php

One of my web apps using API for SMS. I was using to send request as URL using file() function. Everything was working till i transfered my apps to another server. In new server it was not working even it was not sending the request.

I found from phpinfo() that allow_url_fopen was disable. To use file related php build-in function
like  fopen()copy()file_exists() , readfile()file() , file_get_contents() ,filesize() We need to make sure that  allow_url_fopen  is enabled.

If PHP has decided that filename specifies a registered protocol, and that protocol is registered as a network URL, PHP will check to make sure that allow_url_fopen is enabled. If it is switched off, PHP will emit a warning and the fopen call will fail.

allow_url_fopen, how to enable

This can be done via your php.ini file by adding the following line:
allow_url_fopen = On
The php.ini file is where you declare changes to your PHP settings. You can edit the existing php.ini, or create a new text file in any subdirectory and name it php.ini.

Wednesday, July 27, 2016

How many default tables joomla 3 has

Most of times joomla user download quick start package of joomla and install. Which contains many extensions. many joomla user don't know/notice actually how many joomla tables has by default.
Total default joomla 3 tables 68.

Thanks

Tuesday, July 26, 2016

How to access my localhost(WAMP/XAMPP server) from other pc/mobile

Here we want to use/browse  your localhost (WAMP/XAMPP server) from any other device like my

Android phone or PC or Laptop.

Turn on Wifi Hotspot of your android phone/other laptop and connect your Laptop with your phone.

Start your server at localhost (I am using wamp server)

Now open command prompt and enter ipconfig command you will get following things

Wireless LAN adapter Wireless Network Connection:
  Connection-specific DNS Suffix  . :
  Link-local IPv6 Address . . . . . : fe80::80bc:e378:19ab:e448%11
  IPv4 Address. . . . . . . . . . . : 192.160.10.2  Subnet Mask . . . . . . . . . . . : 255.255.255.0
  Default Gateway . . . . . . . . . : 192.160.10.1
Copy this 192.160.10.2 in your mobile/laptop browser.
Note : Please set you network as "Home Network".

Monday, June 27, 2016

Get / display all dates between two dates-php

It's very common uses to get all dates between two dates rang.

However php has a own class callled "DatePeriod" class which made our work easy for this task.


 $begin = new DateTime('2016-06-01');  
 $end = new DateTime('2016-06-28');  
 $end = $end->modify( '+1 day' );   
 $daterange = new DatePeriod($begin, new DateInterval('P1D'), $end);  
 foreach($daterange as $date){  
   echo $date->format("Y-m-d") . "<br>";  
 }  

Note :
 //(P1D stands for period of one day, see DateInterval for further documentation)
 //$end = $end->modify( '+1 day' ); mean dates include the last day 2016-06-28  

Output will looks like
2016-06-01
2016-06-02
2016-06-03
2016-06-04
2016-06-05

Saturday, May 28, 2016

Decodes a complex JSON string and converted into associative arrays using php

Call a API 
 $jsonurl = "https://api.coindesk.com/v1/bpi/currentprice/USD.json";  
 $json = file_get_contents($jsonurl); 
 echo var_dump(json_decode($json)); 

Which will return this

 object(stdClass)[5]  
  public 'time' =>   
   object(stdClass)[6]  
    public 'updated' => string 'May 29, 2016 06:05:00 UTC' (length=25)  
    public 'updatedISO' => string '2016-05-29T06:05:00+00:00' (length=25)  
    public 'updateduk' => string 'May 29, 2016 at 07:05 BST' (length=25)  
  public 'disclaimer' => string 'This data was produced from the CoinDesk Bitcoin Price Index (USD). Non-USD currency data converted using hourly conversion rate from openexchangerates.org' (length=155)  
  public 'bpi' =>   
   object(stdClass)[7]  
    public 'USD' =>   
     object(stdClass)[8]  
      public 'code' => string 'USD' (length=3)  
      public 'rate' => string '519.1350' (length=8)  
      public 'description' => string 'United States Dollar' (length=20)  
      public 'rate_float' => float 519.135  

Or as plain json return

 {"time":{"updated":"May 29, 2016 03:59:00 UTC","updatedISO":"2016-05-29T03:59:00+00:00","updateduk":"May 29, 2016 at 04:59 BST"},"disclaimer":"This data was produced from the CoinDesk Bitcoin Price Index (USD). Non-USD currency data converted using hourly conversion rate from openexchangerates.org","bpi":{"USD":{"code":"USD","rate":"516.4050","description":"United States Dollar","rate_float":516.405}}}  
Now we want to get data as associative arrays

 $jsonurl = "https://api.coindesk.com/v1/bpi/currentprice/USD.json";  
 $json = file_get_contents($jsonurl);  
 $obj = json_decode($json);  
 echo $obj->bpi->USD->{'rate'}; // show the rate   

Thursday, May 12, 2016

Popup new window center screen php javascript

First Create a javascript function for popup window. w=width , h=height of the window
 // Popup windows   
 function popupwindow(url, title, w, h) {  
        var left = (screen.width/2)-(w/2);  
        var top = (screen.height/2)-(h/2);  
        return window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);  
 }  

Now make a php function to use this java-script function everywhere in php easily.

 /**  
  * Return pop up   
  * @author Sharif Ahmed  
  * @param str url  
  * @param str title/value  
  * @param int width  
  * @param int height  
  * @return return popup center windows  
  */  
 function my_anchor_popup($url,$title,$width,$height)   
   {  
     return '<a href="'.$url.'" onclick="popupwindow(\''.$url."','".$title."', '".$width."','".$height."'); return false;\">".$title.'</a>';  
   }   

Sunday, May 1, 2016

Point website to somewhere else, but keep email on cpanel/server

Think I have a domain mydomain.com and my website which is hosted in a cpanel / web server like serverplushost.com . All my email is also running in serverplushost.com.

But now i want to move my website to other server/ dedicated server(like IP 123.124.125.126) but keep email on serverplushost.com as it was before.

1. Login cpanel of  mydomain.com. Click on Advanced DNS zone/ Simple DNS zone.

2. Add A record  name mydomain.com and to the new server IP 123.124.125.126. Also add a CNAME for www.mydomain.com to point mydomain.com. (If there is already have one then edit it).

3. Add A record for webmail.mydomain.com and IP of serverplushost.com (default cpanel IP).
(it's possible that you already have a mail.mydomain.com / webmail.mydomain.com CNAME - delete that and only keep the A record).


So www.mydomain.com and mydomain.com is now pointed to new server IP and webmail.mydomain.com is now pointed to default cpanel hosting.

Monday, April 18, 2016

Time Into Timestamp Or Timestamp Into Time In PHP

The easiest (and most reliable) way to store the time in a database table is with a timestamp. It is also the most convenient way of working out time scales as you don't have to do calculations in base 60. In MySQL this is accomplished by the UNIXTIME() function, which can be reversed by using another MySQL function called FROM_UNIXTIME().
However, you can sometimes be left with timestamps in your code and the task of trying to figure out what to do with them.
NOTE : Timestamps in MariaDB/MYSQL have a maximum value of 2147483647, equivalent to 2038-01-19 05:14:07. This is due to the underlying 32-bit limitation. Using the function on a date beyond this will result in NULL being returned. 
So It's a good option to use other way like this simple php function.
The first problem is trying to convert a timestamp into a date. So here is a PHP function that does this.




// 1460865605 -> 2016-04-17 00:00:05

function Timestamp2Date($t = null){
 if($t == null){
  $t = time();
 }
 return date('Y-m-d H:i:s', $t);
}

// Any Date format to Timestamp
echo(strtotime("now") . "<br>");  // 1461001723
echo(strtotime("2016-04-17") . "<br>"); // 1460865600
echo(strtotime("2016-04-17 00:00:05") . "<br>"); //  1460865605
echo(strtotime("16 October 2016") . "<br>");  //  1476590400
echo(strtotime("+5 hours") . "<br>");  //  1461019723
echo(strtotime("+1 week") . "<br>");  //  1461606523
echo(strtotime("+1 week 3 days 7 hours 5 seconds")."<br>");//1461890928
echo(strtotime("next Monday") . "<br>");  //1461556800
echo(strtotime("last Sunday")); // 1460865600

Convert different date time format functions

function return_date($date="") {
  if (!empty($date)) {
    return date("d-m-Y",strtotime($date));
  } else {
    return  "";
  }  
}
//  
function return_time($datetime="") {
  if (!empty($datetime)) {
    return date("d-m-Y h:i A",strtotime($datetime));
  } else {
    return  "";
  }  
}

function convert_date($date="") {
  if (!empty($date)) {
    return date("Y-m-d",strtotime($date));
  } else {
    return  "";
  }  
}

function convert_time($datetime="") {
  if (!empty($datetime)) {
    return date("Y-m-d H:i:s",strtotime($datetime));
  } else {
    return  "";
  }  
}
The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT).

Thursday, April 7, 2016

Find Tomcat 7 installation folder on Linux/centos or folder /webapps/root/

Their are several way to find installed Apache Tomcat/7.0.61 folder location or web root folder/ www folder which is known webapps in tomcat.

Since late 2012, it is usually under /usr/share/tomcat7.

 Prior to that, it was usually found under /opt/tomcat7.

If tomcat is already running on your machine you can try in this way which is most easy way to use this command

ps -ef | grep tomcat
OR
ps -ef | grep java
to check where it's running from.

Saturday, March 12, 2016

Removing Mad4media copyright Link On Joomla Proforms

I installed Proforms Basic component which is excellent form builder component for joomla and it's also free.
But problem is this component by default has backlink / copyright link under form.Which is very odd and annoying.

It's very hard to remove that link. I was searching every file of this component but could not find that backlink. I spent several hours to solve this. 1st i found they use JavaScript for this backlink and that was encrypt so it's hard to find in which file that put that.
At last  somehow  i found a solution.

1. Go to site/component/com_proforms/views/form/tmpl open default.php file
check line 67 <div class='proformsFormWrap'  edit to  proformsFormWrap1

2. Go to site/component/com_proforms/css open responsivesystem.css file
replace all proformsFormWrap   to  proformsFormWrap1

That's it.
Thanks

Wednesday, February 24, 2016

Count and display number of characters in a textbox using Javascript & Jquery

We could do this in jQuery, assuming we want the character count displayed in a div with id="characters"


<textarea></textarea>
<span id="characters"><span>
$('textarea').keyup(updateCount);
$('textarea').keydown(updateCount);

function updateCount() {
    var cs = $(this).val().length;
    $('#characters').text(cs);
}
This is the most easiest way to do it.

Total Pageviews