Monday, July 30, 2012

HTML/CSS - how to vertically align a website

Let's say you have a web element and you want it to be vertically aligned on the screen. It can even be an entire website.
1. In the CSS file, set the html height property to 100%
2. Place the element you want to vertically align inside of a td tablewith the following properties: 


<table cellpadding="0" cellspacing="0" border="0"
style="height:100%;width:100%">
<tr>
<td valign="middle" align="center"
style="height:100%; width:100%">
    <form id="tentoo_form" runat="server">
    <div id="website">YOUR WEBSITE GOES HERE</div>
    </form>
    </td>
</tr>
</table>

That should do the trick.


Cheers!

Wednesday, July 25, 2012

PHP - if _GET is empty check

In order not to get the "undefined parameters" message when direct open login and such pages:



if(!empty($_GET["i"]) && !empty($_GET["k"])){
      $id = $_GET["i"];
      $key = $_GET["k"];
}



Cheers!

Wednesday, July 18, 2012

HTML/JavaScript - Unselect/Deselect items in options listbox

If you have an HTML select with several options and you need to unselect everything, just do the following by a simple JavaScript function:

document.getElementById('lstbx_01).selectedIndex = -1;

Cheers!

Tuesday, July 17, 2012

AJAX/C# - enable line break in Multiline textbox protected by filter textbox

If you want to protect your Multiline textbox by AJAX FilteredTextBoxExtender, you are going to have to add this on code behind to enable line-break (the Enter as you type):



tb_filter_01.ValidChars = tb_filter_01.ValidChars + "\r\n";



Cheers!

Friday, July 13, 2012

WAMP - Hiding Apache and PHP information

To hide Apache server info open the apache/conf/httpd file and add these two lines:

ServerTokens ProductOnly
ServerSignature Off

To hid PHP info open the php.ini and change the expose_php from On to Off
Reboot the server.
Cheers

Wednesday, July 11, 2012

PHP Session expiration after 20 mins

Set this chunk of code on relevant pages

//session will be expired after 20 mins
if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1200)) {
    // last request was more than 20 minates ago
    session_destroy();   // destroy session data in storage
    session_unset();     // unset $_SESSION variable for the runtime
}
$_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp
if (!isset($_SESSION['CREATED'])) {
    $_SESSION['CREATED'] = time();
} else if (time() - $_SESSION['CREATED'] > 1200) {
    // session started more than 20 minates ago
    session_regenerate_id(true);    // change session ID for the current session an invalidate old session ID
    $_SESSION['CREATED'] = time();  // update creation time
}


Cheers!

Thursday, July 5, 2012

Monday, July 2, 2012

Format code lines in Visual Studio 2010


Ctrl+E, Ctrl+D will format the entire document.
Ctrl+E, Ctrl+F will format the selection.


The menu items for these are in Edit > Advanced.


Cheers!