Sunday, 15 September 2013

Trait

What a Trait Looks Like

A trait is similar to an abstract class which cannot be instantiated on its own (though more often it’s compared to an interface). The PHP documentation defines traits as follows:
Traits is a mechanism for code reuse in single inheritance languages such as PHP. A Trait is intended to reduce some limitations of single inheritance by enabling a developer to reuse sets of methods freely in several independent classes living in different class hierarchies.

Saturday, 14 September 2013

good php interview question

Q: What is T_PAAMAYIM_NEKUDOTAYIM?
A: Its the scope resolution operator (double colon)
Q: What is the cause of this warning: 'Warning: Cannot modify header information - headers already sent', and what is a good practice to prevent it?
A: *Cause:* body data was sent, causing headers to be sent too.
Prevention: Be sure to execute header specific code first before you output any body data. Be sure you haven't accidentally sent out whitespace or any other characters.

Q: What is wrong with this query: "SELECT * FROM table WHERE id = $_POST[ 'id' ]"?
A: 1. It is vulnarable to SQL injection. Never use user input directly in queries. Sanitize it first. Preferebly use prepared statements (PDO) 2. Don't select all columns (*), but specify every single column. This is predominantly ment to prevent queries hogging up memory when for instance a BLOB column is added at some point in the future.

Q: What is wrong with this if statement: if( !strpos( $haystack, $needle ) ...?
A: strpos returns the index position of where it first found the $needle, which could be 0. Since 0 also resolves to false the solution is to use strict comparison: if( false !== strpos( $haystack, $needle )...

Q: What is the preferred way to write this if statement, and why?
if( 5 == $someVar ) or if( $someVar == 5 )
A: The former, as it prevents accidental assignment of 5 to $someVar when you forget to use 2 equalsigns ($someVar = 5), and will cause an error, the latter won't.

Friday, 13 September 2013

date formate check

<?php
$format =array('m','d','y');
$strDate = date("m-d-Y");
$ex = "-";
echo isValidDate($strDate,$format,$ex);
function isValidDate($strDate,$format,$ex) {
      $valid = false;
      if(is_array($format) && count($format) == 3 && count(explode($ex,$strDate))==3)
      {
         $date = array_combine($format,explode($ex,$strDate));
         //print_r($date);
         if(intval($date['m']) && intval($date['d']) && intval($date['y'])){
           $m = $date['m']; $d = $date['d']; $y = $date['y'];
            $valid = checkdate($m,$d,$y);
         }
      }
      return $valid;
   }
?>

Friday, 30 August 2013

date compare validation

javascript


$(document).ready(function(){
    $("#txtFromDate").datepicker({
        minDate: 0,
        maxDate: "+60D",
        numberOfMonths: 2,
        onSelect: function(selected) {
          $("#txtToDate").datepicker("option","minDate", selected)
        }
    });
    $("#txtToDate").datepicker({ 
        minDate: 0,
        maxDate:"+60D",
        numberOfMonths: 2,
        onSelect: function(selected) {
           $("#txtFromDate").datepicker("option","maxDate", selected)
        }
    });  
});
 
 
html
 
 
From: <input type="text" id="txtFromDate" />
To: <input type="text" id="txtToDate" /> 

Monday, 26 August 2013

date picker

 <script>
$(function() {
$( "#datepicker").datepicker({
numberOfMonths: 3, showCurrentAtPos: 0,minDate: 0,dateFormat: 'dd-mm-yy', showOn: "button",
buttonImage: "image/cicon.png",
buttonImageOnly: true,
showOn: 'both',
});
});
</script>

Sunday, 18 August 2013

what is the session



(1) The session of activity that a user with a unique IP address spends on a Web site during a specified period of time. The number of user sessions on a site is used in measuring the amount of traffic a Web site gets. The site administrator determines what the time frame of a user session will be (e.g., 30 minutes). If the visitor comes back to the site within that time period, it is still considered one user session because any number of visits within that 30 minutes will only count as one session. If the visitor returns to the site after the allotted time period has expired, say an hour from the initial visit, then it is counted as a separate user session.
Contrast with unique visitor, hit, click-through and page view, which are all other ways that site administrators measure the amount of traffic a Web site gets.
(2) The period of time a user interfaces with an application. The user session begins when the user accesses the application and ends when the user quits the application.

Saturday, 6 July 2013

XML TO PHPMYADMIN DATA INSERT THROUGH PHP

<?php
include_once('conf/conf.php');
?>
<?php
$xml=simplexml_load_file("CityList.xml");
foreach($xml as $child)
  {
  mysql_query("INSERT INTO `tr_in_city`set CityCode='$child->CityCode',CityName='$child->CityName',CountryCode='$child->CountryCode'") or die("not inserted");
  }
?>