User-agent: *
Disallow: /folder1/
Disallow: /folder2/
Where folder1 & folder2 are the folders which should be hidden from the search engines
This website is dedicated to common, day to day programming and database related Frequently Asked Questions. Popular Programming and Database Articles under one blog
Tuesday, February 14, 2012
Wednesday, January 11, 2012
Mysql Database Backup using Cron Job
mysqldump -h [host] -u[username] -p[password] [dbname] > /[documentroot]/db-backups/dump.txt
Replace [host] with your host name mostly localhost
[username] with database username
[password] with database password
finally [documentroot] with your FTP root
Friday, December 30, 2011
HTML Printing & Page Breaks
<html> <head> <style> @page { size 8.5in 11in; margin: 2cm } div.page { page-break-after: always } </style> </head> <body> <div class="page">Page 1 Here</div> <div class="page">Page 2 Here</div> </body> </html>
Thursday, December 22, 2011
Optimize Your Site With GZIP Compression
In Apache, enabling output compression is fairly straightforward. Add the following to your .htaccess file:
If you can't change your .htaccess file, you can use PHP to return compressed content. Give your HTML file a .php extension and add this code to the top:
In PHP:
<?php if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?>
We check the "Accept-encoding" header and return a gzipped version of the file (otherwise the regular version). This is almost like building your own webserver (what fun!). But really, try to use Apache to compress your output if you can help it. You don't want to monkey with your files.
Reference: http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# Or, compress certain file types by extension:
<files *.html>
SetOutputFilter DEFLATE
</files>
Apache actually has two compression options:- mod_deflate is easier to set up and is standard.
- mod_gzip seems more powerful: you can pre-compress content.
If you can't change your .htaccess file, you can use PHP to return compressed content. Give your HTML file a .php extension and add this code to the top:
In PHP:
<?php if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?>
We check the "Accept-encoding" header and return a gzipped version of the file (otherwise the regular version). This is almost like building your own webserver (what fun!). But really, try to use Apache to compress your output if you can help it. You don't want to monkey with your files.
Verify Your Compression
Once you've configured your server, check to make sure you're actually serving up compressed content.- Online: Use the online gzip test to check whether your page is compressed.
- In your browser: Use Web Developer Toolbar > Information > View Document Size (like I did for Yahoo, above) to see whether the page is compressed.
- View the headers: Use Live HTTP Headers to examine the response. Look for a line that says "Content-encoding: gzip".
Reference: http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/
Creating image thumbnails using PHP
Sometimes restricting images size is required. Following function is very useful to create images of certain sizes on the fly
function createThumbs($source, $dest, $requiredWidth, $requiredHeight, $fileType='')
{
$size = getimagesize($source);
$givenWidth = $size[0];
$givenHeight = $size[1];
if ($givenWidth > 800)
{
$requiredRatio = $requiredWidth / $requiredHeight;
$middleWidth = ceil($givenHeight * $requiredRatio);
if($middleWidth>$givenWidth){
$requiredRatio = $requiredHeight / $requiredWidth;
$middleHeight = ceil($givenWidth * $requiredRatio);
$middleWidth = $givenWidth;
$y = ceil(($givenHeight - $middleHeight)/2);
}
else{
$middleHeight = $givenHeight;
$middleWidth = ceil($givenHeight * $requiredRatio);
$x = ceil(($givenWidth - $middleWidth)/2);
}
$new_im = imagecreatetruecolor($requiredWidth,$requiredHeight);
$extention = strtolower(substr($source, strlen($source)-3, strlen($source)));
if ($extention == "jpg" || $extention == "jpeg") { $im = imagecreatefromjpeg($source); }
elseif ($extention == "gif") { $im = imagecreatefromgif($source); }
elseif ($extention == "png") { $im = imagecreatefrompng($source); }
else
{
//echo("ERROR: Unknown image source file format");
return;
}
imagecopyresampled($new_im,$im,0,0,$x,$y,$requiredWidth,$requiredHeight,$middleWidth,$middleHeight);
imagejpeg($new_im,$dest,85);
}
}
function createThumbs($source, $dest, $requiredWidth, $requiredHeight, $fileType='')
{
$size = getimagesize($source);
$givenWidth = $size[0];
$givenHeight = $size[1];
if ($givenWidth > 800)
{
$requiredRatio = $requiredWidth / $requiredHeight;
$middleWidth = ceil($givenHeight * $requiredRatio);
if($middleWidth>$givenWidth){
$requiredRatio = $requiredHeight / $requiredWidth;
$middleHeight = ceil($givenWidth * $requiredRatio);
$middleWidth = $givenWidth;
$y = ceil(($givenHeight - $middleHeight)/2);
}
else{
$middleHeight = $givenHeight;
$middleWidth = ceil($givenHeight * $requiredRatio);
$x = ceil(($givenWidth - $middleWidth)/2);
}
$new_im = imagecreatetruecolor($requiredWidth,$requiredHeight);
$extention = strtolower(substr($source, strlen($source)-3, strlen($source)));
if ($extention == "jpg" || $extention == "jpeg") { $im = imagecreatefromjpeg($source); }
elseif ($extention == "gif") { $im = imagecreatefromgif($source); }
elseif ($extention == "png") { $im = imagecreatefrompng($source); }
else
{
//echo("ERROR: Unknown image source file format");
return;
}
imagecopyresampled($new_im,$im,0,0,$x,$y,$requiredWidth,$requiredHeight,$middleWidth,$middleHeight);
imagejpeg($new_im,$dest,85);
}
}
Thursday, November 3, 2011
Redirect to www .htaccess
Create a .htaccess file with the below code, it will ensure that all requests coming in to domain.com will get redirected to www.domain.com
The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)
The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
Please REPLACE domain.com and www.newdomain.com with your actual domain name.
Note* This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.
Tuesday, October 25, 2011
Why ASP.NET appears to be faster than Classic ASP?
Pages with the .aspx extension use compiled ASP.NET (based on Microsoft's .NET Framework), which makes them faster and more robust than server-side scripting in ASP, which is interpreted at run-time; however, ASP.NET pages may still include some ASP scripting
Reference: http://en.wikipedia.org/wiki/Active_Server_Pages
Reference: http://en.wikipedia.org/wiki/Active_Server_Pages
Subscribe to:
Posts (Atom)