Showing posts with label Website Optimization. Show all posts
Showing posts with label Website Optimization. Show all posts

Wednesday, July 24, 2019

Full Screen iframe, frameset URL Masking


URL Masking technique with frameset, widely used method and support all modern and old browsers.

<html><head><meta name="viewport" content="width=device-width,initial-scale=1">
</head>
<frameset border="0" rows="100%,*" cols="100%" frameborder="no">
 <frame name="TopFrame" scrolling="yes" noresize src="http://www.w3lessons.com">
 <frame name="BottomFrame" scrolling="no" noresize>

 <noframes></noframes>
</frameset>
</html>

Friday, October 12, 2012

Change of Domain 301 Redirect htaccess



For SEO best practices, when you change domain name of existing website, we need to setup 301 redirect of all existing web pages exactly to a new domain name. This is very important for Search engines detect a new version of URLs

Using the following htaccess code we will redirect all the existing pages of our website to new.


RewriteEngine On
# Redirect all urls with new domain name
RewriteCond %{HTTP_HOST} ^domainone.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domainone.com$
RewriteRule ^(.*)$ http://www.domaintwo.com/$1 [r=301,nc]

# Redirect with www of new domain.
RewriteCond %{http_host} ^domaintwo.com [nc]
RewriteRule ^(.*)$ http://www.domaintwo.com/$1 [r=301,nc]

about code will redirect all the existing pages of current website to new website with same request URL.

Thursday, October 11, 2012

Protect email address in web content.


While building web content we may need to include email address. In this case spam bots are may access our web page and collect email address inside our web content. based on this email address extracting script.

The only way to protect Email address inside the content is convert all email address into image.

Here is the solution to convert email address into dynamic text images


email-to-image.php

<?php

define("F_SIZE", 10);
define("F_ANGLE", 0);
define("F_FONT", "verdana.ttf");

$text = base64_decode(base64_decode($_GET['id']));

$Leading=0;
$W=0;
$H=0;
$X=0;
$Y=0;
$_bx = imagettfbbox(F_SIZE, F_ANGLE, F_FONT, $text);
$s = preg_split("/\n]+/", $text);  // Array of lines
$nL = count($s);  // Number of lines

$W = ($W==0)?abs($_bx[2]-$_bx[0]):$W;
$H = ($H==0)?abs($_bx[5]-$_bx[3])+2+($nL>1?($nL*$Leading):0):$H;

$img = @imagecreate($W+8, $H) or die("Cannot Initialize new GD image stream");

$white = imagecolorallocate($img, 255,255,255);
$txtColor = imagecolorallocate($img, 255,50,0);

// Adjust padding right:
$W+=8;
$bgwhite = imagecolorallocatealpha($img,238,238,238,0);
imagefilledrectangle($img, 0, 0,$W,$H, $bgwhite);

$alpha = "".range("a", "z");
$alpha = $alpha.strtoupper($alpha).range(0, 9);

// Use the string to determine the height of a line
$_b = imageTTFBbox(F_SIZE, F_ANGLE, F_FONT, $alpha);
$_H = abs($_b[5]-$_b[3]);
$__H = 0;

// Use the string to determine the width of a line
$_b = imagettfbbox(F_SIZE, F_ANGLE, F_FONT, $text);
$_W = abs($_b[2]-$_b[0]);

// Final width and height
$_X = abs($W/2)-abs($_W/2);
$__H += $_H;

imagettftext($img, F_SIZE, F_ANGLE, $_X, $__H, $txtColor, F_FONT, $text);

header("Content-Type: image/png");
imagepng($img);
imagedestroy($img);
// END EMAIL IMAGE  
exit();
?>

index.php

<?php
if(isset($_POST['content']))
{
$content=$_POST['content'];
// Keep line breaks inside textarea
$content=preg_replace("/[\n]/", '<br />', $content);
// Find All email ids inside content
preg_match_all('/([\w-\.]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4})/',$content,$emails);

// Replace as image every email address
foreach($emails[0] as $email)
$content=str_replace($email,'<img src="email-to-image.php?id='.base64_encode(base64_encode($email)).'">',$content);
}
?>
<!DOCTYPE>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
body,td,th {
 font-family: Verdana, Geneva, sans-serif;
 font-size: 12px;
 color: #000;
}
body {
 margin-left: 5px;
 margin-top: 5px;
 margin-right: 5px;
 margin-bottom: 5px;
 margin:0 auto;
 width:750px;
}

textarea { width:750px; font-size:15px; font-family:Verdana, Geneva, sans-serif;}

#content
{
 font-size:13px;
 padding:10px;
 background:#EEE;
 border:1px solid #CCC; 
}

#content img
{

 position:relative;
 margin-bottom:-3px;
}

</style>
</head>
<body>

<br>
<br>
<h1>Protect Email Address inside web content</h1>
<form action="" method="post">
<textarea cols="70" rows="10" name="content">
content mixed with any email address. that email address text will be converted into as image. for example we have info@example.com mail in this text area it will be return as image after the compilation. any no of occurrence will automatically replaced as image 

For Example:
Contact
admin@example.com

Technical
tech@example.com
</textarea>
<br /><br />

<input type="submit" value="Compile" name="submit" /><br />
<br />

</form>

<div id="content">
<?php echo @$content; ?>
</div>
</body>
</html>


Download This Script     Live Demo     Download Script

Wednesday, October 10, 2012

Extract Email ID from Content PHP


In many, CMS development, We may often to check whether any email was found inside the content in this case. Here is the best solution to extract email ids from content using the power of regular expression.

Regular Expression to extract Email IDs from Content.

'/([\w-\.]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4})/'

PHP function to extract All Regular Expression Matches

preg_match_all('/([\w-\.]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4})/',$content,$output);

Sample Content.txt with email id mixed html

<p>example for extracting email id <b>example@gmail.com</b> 
from entire content it mean how many <b>email@example.com</b> 
<b>admin.connnect@example.com</b></p
<?php

//Extract Email ID from content.txt

$whois = file_get_contents("content.txt");
preg_match_all('/([\w-\.]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4})/',$whois,$emails);


echo "<pre>";
print_r($emails[0]);

?>

Output

// OUTPUT


Array
(
    [0] => example@gmail.com
    [1] => email@example.com
    [2] => admin.connnect@example.com
)



Tuesday, October 9, 2012

Optimize All MySQL Tables PHP


If you looking for optimizing MySQL database tables from PHP dynamically, here is a solution to optimize entire tables a database.

Optimizing Tables we need to get Entire table list using "SHOW TABLES" query. as this return entire table names as record, after getting executed of this command call OPTIMIZE TABLE and REPAIR TABLE as per the table needs.

Primary Optimization will failed if the table been damage or corrupt. we will apply REPAIR TABLE

<?php

mysql_connect("localhost","root","");
mysql_select_db("your_db_name");


echo "<br /> OPTIMIZING TABLES ";

$alltables = mysql_query("SHOW TABLES");

// Process all tables.
while ($table = mysql_fetch_assoc($alltables))
{
 foreach ($table as $db => $tablename)
 {
 // Optimize them!
 if(mysql_query("OPTIMIZE TABLE ".$tablename))
  echo "<br>OK Optimized : ".$tablename;
 else
 {
  echo "<br>Error Optimizing Applying Reapir... ".$tablename;
  // Apply Reapirt if Optimization Failed;
  if(mysql_query("REPAIR TABLE ".$tablename))
  echo "Repaired !";
  else
  echo "Error Repairing Table!";
 }
 }
}
mysql_close();
?>




Tuesday, September 25, 2012

Get PHP script execution time


Get PHP Script executation time with following simple php script

PHP Script Execution Time



<?php
function page_loading_time()
{
    list ($msec, $sec) = explode(' ', microtime());
    $microtime = (float)$msec + (float)$sec;
    return $microtime;
}

// Capture current time at the Begining of the file
$start=page_loading_time();

usleep(100000);  // Delaying page output 0.1 second for testing purpose.
// Your Content Goes here


echo "<br />At the End of the File
";
$end = page_loading_time();
// Print results.
echo 'Page Loading Time: <b>' . round($end - $start, 2) . '</b> seconds';   
?>

Tuesday, August 21, 2012

Alexa Rank Script PHP - Get Alexa Rank in PHP



To Find Alexa Rank in php using following function

PHP Script to get Alexa Rank

<?php

function alexaRank($domain){
    $remote_url = 'http://data.alexa.com/data?cli=10&dat=snbamz&url='.trim($domain);
    $search_for = '<POPULARITY URL';
 $part = NULL;
    if ($handle = @fopen($remote_url, "r")) {
        while (!feof($handle)) {
            $part .= fread($handle, 100);
            $pos = strpos($part, $search_for);
            if ($pos === false)
            continue;
            else
            break;
        }
        $part .= fread($handle, 100);
        fclose($handle);
    }
    $str = explode($search_for, $part);
    $str = @array_shift(explode('" SOURCE="panel"/>', $str[1]));
    $str = explode('TEXT="', $str);

    return $str[1];
}


echo alexaRank("google.co.in");

?>


Monday, March 5, 2012

Page Loading Time PHP


Execution of server side scripting need to optimize in order to get the Optimized page loading time. In this case most of the Server Side Response typically not more than 2 to 30 seconds. In this case we need to find the Exact page loading time in PHP using the following Script.


Find Page Loading Time PHP
<?php
function page_loading_time()
{
    list ($msec, $sec) = explode(' ', microtime());
    $microtime = (float)$msec + (float)$sec;
    return $microtime;
}

$start=page_loading_time();

usleep(100000);  // Delaying page output 0.1 second for testing purpose.

echo "<br />";
$end = page_loading_time();
// Print results.
echo 'Page Loading Time: <b>' . round($end - $start, 2) . '</b> seconds';   
?>

Sunday, March 4, 2012

Remove HTML comments PHP


Cleaning or Removing HTML comments is one of the main part of Optimizing web pages. Here is the solution to Remove HTML Comments with PHP.

To Remove HTML Comments in PHP, We need to use the following Technique.

Remove HTML Comments with PHP
<?php
// Start OutputBuffer
ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Remove HTML Comments</title>
</head>
<body>

<!-- // HTML Comments for code identification -->

<!-- Mutiple Closing Tags-->
<h1>Remove HTML Comments Example</h1>
<!-- Unclose End Tag-->
<p>This is an example to remove HTML Comments <p>

</body>
</html>
<?php
// Store HTML Output Buffer as variable with ob_get_clean();
$html = ob_get_clean();

// Specify configuration
$config = array(
           'indent'         => false,
     'hide-comments' => true,
           'output-xhtml'   => true,
           'wrap'           => false
     );

// Tidy
$tidy = new tidy;
$tidy->parseString($html, $config, 'utf8');
$tidy->cleanRepair();

// Output
echo $tidy;
?>

Friday, March 2, 2012

PHP Tidy - Clean HTML Tags, HTML code, HTML Source, Comments


Website Webpage Optimization part, HTML pages contain many unnecessary development usage section such as Comments, Indents, Empty Lines, Accidental Enclosed tags without End Tag, Unknown Closing Tag, These are very sensitive for Browser Compatibly Issues, Page Loading Time and Web Page Optimization



We can able to keep our Web pages keep away from Unnecessary things such Comments, Un closed Tags, Un closed End Tags using HTML Tidy Object from PHP.

Here is the Example Code for PHP tidy Object. with Examples.
With this Example We have to use tidy Object (Tidy Object need to Enabled in PHP Configuration).
Check with phpinfo() under Tidy. ob_get_clean() , parse HTML String with parseString() function from Tidy object, and Clean our HTML with cleanRepair()

Saturday, February 25, 2012

Reduce HTTP Request with Data URI in PHP


A part of website optimization technique is Reduce no of HTTP Request when user attempt to open our Web page from our website. HTTP Request count is an important factor for Traffic worthy websites to make your web pages / websites more responsive on time. In this factor of HTTP Request optimization to reduce the HTTP request count of various images in our websites by Rewriting with Data URI Scheme. Data URI is the technology which is used to Reduce and Optimize HTTP request and response.



For example If you have a gallery section in your website. Gallery images are in two Sections one is Thumbnails and another one is actual images. in this case set of 5 Images will request 10 HTTP request every time the Page opens. in this case we can use Data URI with PHP to reduce this HTTP request 0, Data URI will cheat our server and retrieve the image data as plain code along with our standard HTML code.

Wednesday, February 22, 2012

Directory Model URL Rewriting with htaccess and map content with php

Creating a dynamic content for web application, we need to consider the Search Engine Optimized web URL structure to main the quality of our web development says "SEO Friendly", Search Engines are clearly identified our web content if we have Directory Model URL structure in our websites. As a developer SEO Friendly URL is very important to any project. Let me explain How to create Directory Model URL Rewriting with htaccess and how to map your content with php.

.htaccess directory structure url rewriting



directory structure:

/index.php
/.htaccess
/include/home.php
/include/about_us.php
/include/contact_us.php