Monday 22 August 2011

To Stick Footer to Bottom of page

Many times it requires to forcefully stick footer to bottom of page if content of web page is less this makes footer to appear at middle or top bottom section of page which is odd. so to make forcefully stick footer at bottom even if content of page varies , the following are the steps.

<html></body>
<div id="main">
    <div id="container">
      <div id="header">
              this is header, with logo and all
      </div>
      <div id="content">
              This is page content with less or variable text ,forms, images etc
       </div>
     </div>

     <div id="footer">
            this is footer...
     </div>
</div>  <!-- #main ends --->
</body>
</html>

Here #main is the div which encloses all the content of a page , inside main there is 2 div one is #container and other is #footer , we will concentrate on height and position of #main,#container and #footer div. the rest inner div header and content can be optional you can put any number of div's inside #container.

<style><!-- css -->

html,body{
    font-family:Arial, Helvetica, sans-serif;
    font-weight:normal;
    color:#333;   
    height:100%; 
        /* this is important to give height to html and body */
    margin:0px;
    padding:0px;
}

#main{
    min-height:100%;
        /* important thing to give min height so that footer can go to bottom */
    position:relative;                
        /* Position relative so that , in footer we can give position absolute */
    float:left;
    height:auto ! important;       /* for cross browser compatible */
    height:100%;                 /* have to give height 100% */
    width: 100%;
}

#container {
    float: left;
    margin: 1px 2px 20px 14px;     
        /*  you can give any margin according to your need */
    padding-bottom: 34px;             
        /* only important thing the padding-bottom should be equal to footer height */
    width: auto;
}

#footer{
    bottom: 0 ! important;   
        /* this will stuck footer to bottom of page */
    clear: both;
    color: #FFFFFF;
    height: 34px;             
        /* height of footer , same as padding-bottom of container */
    position: absolute;    
        /* position to settle down the footer */

    width: 100%;
}
</style>

Thursday 4 August 2011

CSS Selectors


CSS Selectors

Below are examples of all of the CSS selectors For their precise definition please refer to the CSS specifications.

Universal

*elements in the default namespace
|*elements in no namespace
ns|*elements in the namespace with prefix ns
*|*elements in any or no namespace

Type

divdiv elements in the default namespace
|divdiv elements in no namespace
ns|divdiv elements in the namespace with prefix ns
*|divdiv elements in any namespace or in none

Descendant

div pp elements that are within a div element
* pp elements that are within any element (ie. not the root element)

Child

div > pp elements that are the direct children of div elements
p > *any elements that are the direct children of p elements

Direct Sibling

div + pp elements that directly follow div elements
p + *any elements that directly follow p elements

Indirect Sibling

div ~ pp elements anywhere after div elements
p ~ *any elements anywhere after p elements

Attribute

*[href]elements with an href attribute
*[align="right"]elements with an align attribute of right
*[href^="http:"]elements with an href attribute beginning with http:
*[href$=foo]elements with an href attribute ending with foo
*[href*=foo]elements with an href attribute containing foo
*[words~=foo]elements with a words attribute containing the word foo
*[lang|=en]elements with a lang attribute equal to or beginning with en

Class

p.introp elements with a class attribute containing the word intro

ID

p#introp elements with an id attribute of intro

Link

:linkelements that represent links
a[href^="mailto:"]:linkelements that link to an email address

Lang

:lang(en)elements whose specified language is English
q:lang(fr-CA)quotes whose specified language is French (Canadian)

Contains

p:contains("synergy")paragraphs containing the text "synergy"

Root

:rootthe root element of the document
html:roothtml root elements
:root > *children of the root element

Empty

div:emptyevery empty div element

Not

*:not(p)every element except p elements
div:not(:empty)every non-empty div element
a:not([href])every a element without a href attribute

First Child

div > :first-childthe first child of a div element

Last Child

div > :last-childthe last child of a div element

Only Child

div > :only-childthe only child of a div element

First of Type

div > p:first-of-typethe first p element child of a div element

Last of Type

div > p:last-of-typethe last p element child of a div element

Only of Type

div > p:only-of-typethe only p element child of a div element

Nth Child

div > :nth-child(3)the third child of a div element
div > :nth-child(even)every even child of a div element
div > :nth-child(odd)every odd child of a div element
div > :nth-child(3n)every third child of a div element

Nth Last Child

div > :nth-last-child(3)the third last child of a div element
div > :nth-last-child(even)every even last child of a div element
div > :nth-last-child(odd)every odd last child of a div element
div > :nth-last-child(3n)every third last child of a div element

Nth of Type

div > p:nth-of-type(3)the third p element child of a div element
div > p:nth-of-type(even)every even p element child of a div element
div > p:nth-of-type(odd)every odd p element child of a div element
div > p:nth-of-type(3n)every third p element child of a div element

Nth Last of Type

div > p:nth-last-of-type(3)the third last p element child of a div element
div > p:nth-last-of-type(even)every even last p element child of a div element
div > p:nth-last-of-type(odd)every odd last p element child of a div element
div > p:nth-last-of-type(3n)every third last p element child of a div element

Pseudo-elements

::beforeThis pseudo-element can be used with the content property to add generated content not present in the original document. For example, p::before can be used to insert text at the beginning of every paragraph element.
::afterThis pseudo-element can be used with the content property to add generated content not present in the original document. For example, p::after can be used to insert text at the end of every paragraph element.
::markerThis pseudo-element is for applying style to list item markers.
::first-letterThis pseudo-element is for applying style to the first letter of an element.
::footnote-callThis pseudo-element is for applying style to footnote calls, the numeric anchors in the main text that refer to footnotes.
::footnote-markerThis pseudo-element is for applying style to footnote markers, the numeric markers placed in front of the footnote text.
reference from  

Wednesday 3 August 2011

PHP Interview Questions and Answer

What is PHP  .ini file
PHP.ini is very useful and it is a configuration file that is used to customize behavior of PHP at runtime. This enables easy administration in the way you administer Apache web server using configuration files. The Settings in which  upload directory, register global variables, display errors, log errors, max uploading size setting, maximum time to execute a script and other configurations is written in this file.When PHP Server starts up it looks for PHP.ini file first to load various values for settings. If you made changes in PHP.ini then you need to restart your server to check the changes be effected

How can we encrypt the username and password using PHP?
use MD5 or You can use the MySQL PASSWORD() function to encrypt username and password. For example,
INSERT into user (password, ...) VALUES (PASSWORD($password?)), ...);


When are you supposed to use endif to end the conditional statement?
When the original if was followed by : and then the code block without braces.


How can we send mail using JavaScript?
No. There is no way to send emails directly using JavaScript.
But you can use JavaScript to execute a client side email program send the email using the "mailto" code. Here is an example:
function myfunction(form)
{
tdata=document.myform.tbox1.value;
location="mailto:mailid@domain.com?subject=...";
return true;
}


How do I find out the number of parameters passed into function.
func_num_args() function returns the number of parameters passed in.


What is the difference between $message and $$message
$message is a simple variable whereas $$message is a reference variable. Example:
$user = 'bob'
is equivalent to
$holder = 'user';
$$holder = 'bob';
They are both variables. But $message is a variable with a fixed name. $$message is a variable who's name is stored in $message. For example, if $message contains "var", $$message is the same as $var.

How many ways we can pass the variable through the navigation between the pages
At least 3 ways:
1. Put the variable into session in the first page, and get it back from session in the next page.
2. Put the variable into cookie in the first page, and get it back from the cookie in the next page.
3. Put the variable into a hidden form field, and get it back from the form in the next page.

What is the maximum length of a table name, a database name, or a field name in MySQL
Database name: 64 characters
Table name: 64 characters
Column name: 64 characters

What?s the difference between md5(), crc32() and sha1() crypto on PHP
The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit value, and md5() returns a 160 bit value. This is important when avoiding collisions.

What is the difference between CHAR and VARCHAR data types
CHAR is a fixed length data type. CHAR(n) will take n characters of storage even if you enter less than n characters to that column. For example, "Hello!" will be stored as "Hello! " in CHAR(10) column. will take memory of all fixed 10 characters
VARCHAR is a variable length data type. VARCHAR(n) will take only the required storage for the actual number of characters entered to that column. For example, "Hello!" will be stored as "Hello!" in VARCHAR(10) column. and memory consumed would of 6 characters (as Hello! = 6 characters).
What is the size of INT ?
Size of INT is 4bytes weather we write INT(1) or INT(11)  it will take 4Bytes. so then what those value inside () means ? (1) or (11) means , what does the number in the brackets mean?  It pretty much comes down to display, its called the display-width.  The display width is a number from 1 to 255. You can set the display width if you want all of your integer values to “appear”.  If you enable zerofill on the row, the field will have a default value of 0 for int(1) and 0000000000 for int(10).

     Create Table temp (col1 INT(4));
     Insert into temp values(1000000);
     Select * from temp
    will display col1 -> 1000000;  // means Display width does not have any effect on INT 
weather we write INT(1) or INT(11) it will not effect any value , just will consume 4Bytes even if we enter 100 or 124578999. any thing but between -2147483648 - 2147483647 as above value will consume more memory, then we use BIGINT 8 bytes there also () does not mean any thing
Alter table temp change col1 col1 int(8) zerofill;
Insert into temp values(11200);
select * from temp;
will display ->  00011200
so zerofill will compensate the remaining space with zeros..this can be helpful in creating IDs or in Invoice applications for ex if ID is 1 then for 4 digit field it will show as 0001
http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html
    
Can JavaScript array be associative ?
var ar = new Array();
ar['nice'] = "hello";
alert(ar.length);
keeps on giving zero why ?
associative arrays in javascript are treated as objects and not as regular arrays. Because of this, they do not have a length property because the array "elements" are now properties of an object. To get a count of the properties, you have to loop over the object and count them like this.


Is There Any Search function on Array in JavaScript ?
No, there is no regular JavaScript function for array search, we have to either loop the whole array or we can use another trick as below


var val1="hi";
var myarray = new Array();
      myarray[0]="hello";
      myarray[1]="hi";
      myarray[2]="see";
var str;
var result;
if(mynextmoves.length>0){
     //Check if array is empty or not
     str=myarray.join(" "); //convert array in to string
     result=str.search(val1); //will search for 'hi' inside the string str
    //result will have -1 if result not found else will show position of 'hi' in string
}


How to stick Footer to Bottom of page.? if page content are less.
read my Post
http://blitzphp.blogspot.com/2011/08/to-stick-footer-to-bottom-of-page.html

PHP: How to Get the Current Page URL


Sometimes, you might want to get the current page URL that is shown in the browser URL window. For example if you want to let your visitors submit a blog post to Digg you need to get that same exact URL. There are plenty of other reasons as well. Here is how you can do that.
<?php
  echo curPageURL();
?>
<?php
function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
 $pageURL .=    $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
?>


Why do some Web sites include www in the URL while others don't? 
ref:   http://computer.howstuffworks.com/internet


A "normal" Web site has a URL that looks like this: http://www.howstuffworks.com. You may have noticed that on many sites, the "www" part is not required. You can just as easily use http://howstuffworks.com to get to HowStuffWorks. There are other sites that have extra layers of naming, such as http://www.delphion.com and http://journal.iftech.com, that seem to use a different word besides "www" to reference different Web sites. Another common thing you see is a name like ftp.microsoft.com, used either with the FTP command or as a URL (ftp://ftp.microsoft.com) in a browser.


A name server translates a name to an IP address. When you type a URL like http://www.howstuffworks.com into your browser, the browser contacts its default name server and asks, "Have you ever heard of www.howstuffworks.com?" If this is the first time the name server has heard of www.howstuffworks.com, it finds the .com name server and asks if it knows of the name server handling howstuffworks.com. If so, your name server connects to the name server for howstuffworks.com and asks it about www.howstuffworks.com. If the HowStuffWorks name server has a listing for the www prefix, it returns the IP address for "www.howstuffworks.com" and your browser connects to that IP address.


The network administrator for the domain "howstuffworks.com" is in charge of mapping the names in the howstuffworks.com domain to specific machines and their IP addresses. In many large companies, there will be different machines (with different IP addresses) handling WWW, FTP, Telnet and other traffic. On smaller sites, the same machine can handle everything.
The network administrator makes a list of names and IP addresses, like this:
www.howstuffworks.com - 242.128.34.54
ftp.howstuffworks.com - 242.128.34.73
The­ administrator can put anything in that list, because the name servers don't care. The administrator could put in scooby.howstuffworks.com, scooby.doo.howstuffworks.com and scooby.dooby.doo.howstuffworks.com, and when someone types in those names the name server will return the IP addresses associated with them.
In the case of Web sites that happen to work without the "www" prefix, it simply means that the administrator has decided that if there is no prefix, the IP address returned should be the IP address for the Web server.

How Domain Name Server Work (DNS or Name Server)
If you've ever used the Internet, it's a good bet that you've used the Domain Name System, or DNS, even without realizing it. DNS is a protocol within the set of standards for how computers exchange data on the Internet and on many private networks, known as the TCP/IP protocol suite. Its basic job is to turn a user-friendly domain name like "howstuffworks.com" into an Internet Protocol (IP) address like 70.42.251.42 that computers use to identify each other on the network. It's like your computer's GPS for the Internet.
Computers and other network devices on the Internet use an IP address to route your request to the site you're trying to reach. This is similar to dialing a phone number to connect to the person you're trying to call. Thanks to DNS, though, you don't have to keep your own address book of IP addresses. Instead, you just connect through a domain name server, also called a DNS server or name server, which manages a massive database that maps domain names to IP addresses.
Whether you're accessing a Web site or sending e-mail, your computer uses a DNS server to look up the domain name you're trying to access. The proper term for this process is DNS name resolution, and you would say that the DNS server resolves the domain name to the IP address. For example, when you enter "http://www.howstuffworks.com" in your browser, part of the network connection includes resolving the domain name "howstuffworks.com" into an IP address, like 70.42.251.42, for HowStuffWorks' Web servers.
You can always bypass a DNS lookup by entering 70.42.251.42 directly in your browser (give it a try). However, you're probably more likely to remember "howstuffworks.com" when you want to return later. In addition, a Web site's IP address can change over time, and some sites associate multiple IP addresses with a single domain name.
Without DNS servers, the Internet would shut down very quickly. But how does your computer know what DNS server to use? Typically, when you connect to your home network, Internet service provider (ISP) or WiFi network, the modem or router that assigns your computer's network address also sends some important network configuration information to your computer or mobile device. That configuration includes one or more DNS servers that the device should use when translating DNS names to IP address.




What is an IP address


Every machine on the Internet­ has a unique identifying number, called an IP Address. A typical IP address looks like this:
216.27.61.137
To make it easier for us humans to remember, IP addresses are normally expressed in decimal format as a "dotted decimal number" like the one above. But computers communicate in binary form. Look at the same IP address in binary:


11011000.00011011.00111101.10001001
The four numbers in an IP address are called octets, because they each have eight positions when viewed in binary form. If you add all the positions together, you get 32, which is why IP addresses are considered 32-bit numbers. Since each of the eight positions can have two different states (1 or 0) the total number of possible combinations per octet is 28 or 256. So each octet can contain any value between 0 and 255. Combine the four octets and you get 232 or a possible 4,294,967,296 unique values!


Out of the almost 4.3 billion possible combinations, certain values are restricted from use as typical IP addresses. For example, the IP address 0.0.0.0 is reserved for the default network and the address 255.255.255.255 is used for broadcasts.


The Distributed System (How DNS works)
Every domain has a domain name server handling its requests, and there is a person or IT team maintaining the records in that DNS server's database. No other database on the planet gets as many requests as DNS servers, and they handle all those queries while also processing data updates from millions of people every day. That's one of the most amazing parts of DNS -- it is completely distributed throughout the world on millions of machines, managed by millions of people, and yet it behaves like a single, integrated database!

Because managing DNS seems like such a big job, most people tend to leave it to the IT professionals. However, by learning a little bit about how DNS works and how DNS servers are distributed across the Internet, you can manage DNS with confidence. The first thing to know is what the purpose of a DNS server is on the network where it resides. A DNS server will have one of the following as its primary task:
  • Maintain a small database of domain names and IP addresses most often used on its own network, and delegate name resolution for all other names to other DNS servers on the Internet.
  • Pair IP addresses with all hosts and sub-domains for which that DNS server has authority.
DNS servers that perform the first task are normally managed by your Internet service provider (ISP). As mentioned earlier, the ISP's DNS server is part of the network configuration you get from DHCP as soon as you go online. These servers reside in your ISP's data centers, and they handle requests as follows:
  • If it has the domain name and IP address in its database, it resolves the name itself.
  • If it doesn't have the domain name and IP address in its database, it contacts another DNS server on the Internet. It may have to do this multiple times.
  • If it has to contact another DNS server, it caches the lookup results for a limited time so it can quickly resolve subsequent requests to the same domain name.
  • If it has no luck finding the domain name after a reasonable search, it returns an error indicating that the name is invalid or doesn't exist.

The second category of DNS servers mentioned above is typically associated with Web, mail and other Internet domain hosting services. Though some hardcore IT gurus set up and manage their own DNS servers, hosting services have made DNS management much easier for the less technical audience. A DNS server that manages a specific domain is called the start of authority (SOA) for that domain. Over time, the results from looking up hosts at the SOA will propagate to other DNS servers, which in turn propagate to other DNS servers, and so on across the Internet.
This propagation is a result of each DNS server caching the lookup result for a limited time, known as its Time To Live (TTL), ranging from a few minutes to a few days. People managing a DNS server can configure its TTL, so TTL values will vary across the Internet. So, each time you look up "www.howstuffworks.com," it's possible that the DNS server for your ISP will find the lookup results "70.42.251.42" in its own cache if you or someone else using that server looked for it before within the server's TTL.
This great web of DNS servers includes the root name servers, which start at the top of the domain hierarchy for a given top-level domain. There are hundreds of root name servers to choose from for each top-level domain. Though DNS lookups don't have to start at a root name server, they can contact a root name server as a last resort to help track down the SOA for a domain.
How to Create Iframe in JavaScript Dynamically 
Below is the Javascript function to create Iframe at any click event of link or button
<script>
function makeFrame(){
   var aa = document.getElementById('pdfpath').value;
   ifrm = document.createElement("IFRAME");     //will create an Element IFrame
   ifrm.setAttribute("src", aa);
   ifrm.style.width = 200+"px";
   ifrm.style.height = 200+"px";
   ifrm.setAttribute("id", "my_iframe");
   document.body.appendChild(ifrm);
}
</script>



PHP File Open and File Read function 
The tools for reading files with PHP are

        fopen()
file_get_contents()
        fgets()
file()
readfile()



fopen() -  Fopen() is, for many, a fiendishly complex function to use. The reason for this is because it is another one of those functions lifted straight from C, and so is not as user-friendly as most PHP functions. On the flip-side, as per usual, is the fact that fopen() is an incredibly versatile function that some people come to love for its ability to manipulate files just as you want it to.
Fopen() has two key parameters: the file to open, and how you would like it opened. Parameter one is easy – it is just $filename, as with the other examples. Parameter two is what makes fopen() so special: you specify letters in a string that define whether you want to read from (“r”), write to (“w”), or append to (“a”) the file specified in parameter one. There is also a fourth option, “b”, which opens the file in binary mode. This is not necessary on Unix-based systems, but it is on Windows, so it is best to use it everywhere – it is not detrimental on Unix-based systems at all.
Fopen() returns a file handle resource, which is basically the contents of the file. You cannot output it directly, e.g. “print fopen(….)”, but fopen() -related functions all accept file handles as the file to work with, so you should store the return value of fopen() in a variable for later use. Therefore, here’s a full usage of fopen() .



$filename = "localfile.txt";  
// always put realpath for file like $filename=" /var/www/mysite/upload/localfile.txt";
//The "x" parameter can be "r","w" or "a"
$handle = fopen($filename, "x");


Once the file handle is ready, we can call other functions on the opened file, depending on how the file was opened (the second parameter to fopen() ). To read from a file, the function fread() is used, and to write to a file fwrite() is used.If the file cannot be opened, fopen() returns false. If the file is successfully opened, a file handle is returned and you can proceed.
$handle = fopen($filename, "rb");
$contents = fread($handle, filesize($filename));
fclose($handle);
print($contents);

When reading in a file, PHP uses a file pointer to determine which byte it is currently up to – kind of like the array cursor. Each time you read in a byte, PHP advances the array cursor by one place – reading in the entire file at once advances the array cursor to the end of the file.
Notice that fread() ‘s return value is the text it read in, and in above situation that is the entire file. To finish off using fread() it is simply necessary to close the file as soon as you are done with it. To close a file you have opened with fopen(), use fclose() – it takes the file handle we got from fopen(), and returns true if it was able to close the file successfully. We have now got enough to use fopen() to fully open and read in a file, then close it. 



 file_get_contents - File_get_contents () is similar to fread () in that it returns the entire contents of the file to a single string, however it can be done in a single line and performs better then fread ().
      $contents = file_get_contents($filename);



fgets - fgets () is used to read the data from a file one line at a time starting from the pointer. It defaults to only reading the first 1024 bytes of a line, however you can set this variable higher or lower if you wish. If your file is not separated with line breaks, this is not the right function to use.

$file_handle = fopen("dictionary.txt", "r");
while (!feof($file_handle)) {
   $line_of_text = fgets($file_handle);
   print $line_of_text . "<BR>";
}
   fclose($file_handle);


file()- File () is similar to fgets in that it reads the data one line at a time, however it returns it all at once into an array. The array contains the line number, and the data corresponding to each line number starting with 0. If you want to do more than simply echo the data, having it in an array will provide much more flexibility making file () more useful than fgets.
readfile() -If you want to output a file to the screen without doing any form of text processing on it whatsoever, readfile() is the easiest function to use. When passed a filename as its only parameter, readfile() will attempt to open it, read it all into memory, then output it without further question. If successful,readfile() will return an integer equal to the number of bytes read from the file.

Difference  Between CURDATE()  &  NOW()  in MYSQL
CURDATE() will give current date only
NOW() will give full  date and time
select now() , you will get '2010-12-09 17:10:18'
select CURDATE(), you will get '2010-12-09'

http://www.guru99.com/database-normalization.html