Category Archives: Knowledge

Keeping footer always at the Bottom of the Page

In a recent website work I had to keep footer always at the bottom regardless of the content. If there is no content or very less content then footer use to come up instead of sticking at bottom of the page. Here is the CSS solution I found for the same:

Lets say the page structure is something like this:

<html>
<head><title>TITLE</title></head><body>
<div id="page">
 <div id="header">HEADER</div>
 <div id="content">CONTENT</div>
 <div id="footer">FOOTER</div>
</div>
</body>
</html>

Then we just need to use the following CSS code for footer which we need to keep in head section or some CSS file which will linked in head section:

<!--
#page
{
 position:relative;
 height:100%;
}
#content
{
 padding-bottom:40px;   /* Height of the footer */
}
#footer
{
 position:absolute;
 bottom:0;
 width:100%;
 height:40px;   /* Height of the footer */
}
-->

and we are done. Just test in any browser 🙂

This can be quite easily done without using any CSS if we are using <table> tag with height attribute instead of <div> tag. for e.g.

<html>
<head><title>TITLE</title></head>
<body>
 <table width="100%" height="100%">
 <tr><td valign="top">HEADER</td></tr>
 <tr><td valign="middle">CONTENT</td></tr>
 <tr><td valign="bottom">FOOTER</td></tr>
</table>
</body>
</html>

Here table height is set to 100% to use whole page and valign is used for vertical alignment of .  height attribute can be avoided using style element.

This will work fantastic but might fail in W3C validation as height attribute is no more supported so better use the solution with <div> tag with CSS.

Note: I tested this in Chrome browser only.

Have Fun 😉

Advertisements

Email Validation using PHP

In one of my recent project I was required to validate email address in PHP. There are many ways to do this but I like following two approaches very much for which I created two different functions:

I created a function isEmail which will validate the email address and return true or false as per validation result.

First Approach: Using Filter functions (http://in.php.net/manual/en/function.filter-var.php)

This is quite simple and straightforward way using filter_var method and FILTER_VALIDATE_EMAIL constant which works on PHP 5.2+

Here is the function definition:
<?php
function isEmail_FirstApproach($strEmail)
{
if(filter_var($strEmail, FILTER_VALIDATE_EMAIL))
{
return true;
}
return false;
}
?>

Second Approach: Using Regular Expression (http://in3.php.net/manual/en/function.preg-match.php)
Regular expression is extremely powerful and quite confusing tool. So use it cautiously 🙂
Note: This function validates emails very well but quite not fully functional will all kind of emails. For e.g. Gmail gives option to add ‘+’ sign in emails which will fail with this functions and so on. Anyways you can easily enhance it 🙂

Here is the function definition:

<?php
function isEmail_SecondApproach($strEmail)
{
$strPattern = “/^([a-z])([a-z0-9._])+([a-z0-9])\@([a-z0-9])*([a-z])+(-[a-z])*([a-z0-9])*(\.([a-z0-9])*([a-z])+(-[a-z])*([a-z0-9])*)+$/i”;

if(preg_match($strPattern, $strEmail))
{
return true;
}
return false;
}
?>

Now simply call these functions to use it’s functionality as follows:
<?php
$email = “abc@example.com”;

if(isEmail_FirstApproach($email))
echo “Valid Email”;
else
echo “Invalid Email”;

if(isEmail_SecondApproach($email))
echo “Valid Email”;
else
echo “Invalid Email”;
?>

Note: Validation results can be different for different email addresses as filter validation is quite liberal than my Regex function.

Let me know if you find any issue with this or know any more efficient way to perform the same.


Restore Show Desktop Shortcut

I accidentally lost shortcut button “Show Desktop” from Windows XP Taskbar’s Quick Launch section. I tried various probabilities and combination but couldn’t restore it. Though Windows+D command was handy but I wanted my shortcut button back. Finally after some googling got a simple solution …

Create a file with name “Show Desktop.scf” with following contents:
[Shell]
Command=2
IconFile=explorer.exe,3
[Taskbar]
Command=ToggleDesktop

Drag this file to Quick Launch area and it works.

Another simple way:
click Start>Run and type this command: regsvr32 /n /i:U shell32 and done.

My First Experience with PHP Apache and MySQL

Finally I completed a website using PHP, MySQL and Apache web server after burning lots of candles and sleepless nights. I am normally an ASP programmer but always wanted to learn PHP from long time. So after giving much thought I started creating a website in PHP with back-end as MySQL during this vacation time. It took me two days to properly setup PHP, Apache and MySQL on windows XP machine. But after setting up I found that its quite easy, we just need to follow steps properly.

I completed this work in twenty days which i could have completed in around ten days if it was it ASP. Obviously PHP is new to me thats why it took time also I already have many previously built code by me in ASP ;-).

It was nice experience. Now I am getting more deeper into it and exploring more aspects of PHP, MySQL, Apache web server and associated technologies/tools.

and yes I’ll appreciate any guidance, suggestions or comments by you to improve my knowledge.