Wednesday, February 27, 2013

Non WWW to WWW redirection using htaccess File



Non WWW to WWW redirection  



This code using Htaccess, and also redirect index.html file to same directory in website. 

RewriteEngine on

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html?\ HTTP/
RewriteRule ^(.*)index\.html?$ http://www.websitename.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^websitename\.com$
RewriteRule (.*) http://www.websitename.com/$1 [R=301,L]


For Examples
1. http://websitename.com

using above code
http://www.websitename.com

2.  http://websitename.com/index.html or http://www.websitename.com/index.html


using above code
http://www.websitename.com/


Tuesday, February 26, 2013

Advantages and disadvantages of MyISAM and InnoDB


The 2 major types of table storage engines for MySQL databases are InnoDB and MyISAM. To summarize the differences of features and performance,


Following InnoDB vs. MyISAM – A Comparison of Pros and Cons
  1. InnoDB is newer while MyISAM is older.
  2. InnoDB is more complex while MyISAM is simpler.
  3. InnoDB is more strict in data integrity while MyISAM is loose.
  4. InnoDB implements row-level lock for inserting and updating while MyISAM implements table-level lock.
  5. InnoDB has transactions while MyISAM does not.
  6. InnoDB has foreign keys and relationship contraints while MyISAM does not.
  7. InnoDB has better crash recovery while MyISAM is poor at recovering data integrity at system crashes.
  8. MyISAM has full-text search index while InnoDB has not.
In light of these differences, InnoDB and MyISAM have their unique advantages and disadvantages against each other. They each are more suitable in some scenarios than the other.


Advantages of InnoDB

  1. InnoDB should be used where data integrity comes a priority because it inherently takes care of them by the help of relationship constraints and transactions.
  2. Faster in write-intensive (inserts, updates) tables because it utilizes row-level locking and only hold up changes to the same row that’s being inserted or updated.

Disadvantages of InnoDB

  1. Because InnoDB has to take care of the different relationships between tables, database administrator and scheme creators have to take more time in designing the data models which are more complex than those of MyISAM.
  2. Consumes more system resources such as RAM. As a matter of fact, it is recommended by many that InnoDB engine be turned off if there’s no substantial need for it after installation of MySQL.
  3. No full-text indexing.

Advantages of MyISAM

  1. Simpler to design and create, thus better for beginners. No worries about the foreign relationships between tables.
  2. Faster than InnoDB on the whole as a result of the simpler structure thus much less costs of server resources.
  3. Full-text indexing.
  4. Especially good for read-intensive (select) tables.

Disadvantages of MyISAM

  1. No data integrity (e.g. relationship constraints) check, which then comes a responsibility and overhead of the database administrators and application developers.
  2. Doesn’t support transactions which is essential in critical data applications such as that of banking.
  3. Slower than InnoDB for tables that are frequently being inserted to or updated, because the entire table is locked for any insert or update.
The comparison is pretty straightforward. InnoDB is more suitable for data critical situations that require frequent inserts and updates. MyISAM, on the other hand, performs better with applications that don’t quite depend on the data integrity and mostly just select and display the data.



How to change or convert MyISAM to InnoDB or vice versa?



  • MyISAM tables yield better performance results in selecting data records
  • InnoDB tables give better performance results in inserting and updating data records
To change a MyISAM table to an InnoDB table:
ALTER TABLE table_name ENGINE = InnoDB;
To convert an InnoDB table to a MyISAM table:
ALTER TABLE table_name ENGINE = MyISAM;

Friday, February 22, 2013

Sending mail with pdf attachment using php



This website provide code "User Sending mail with pdf/doc file with mail function"
<?php  
$fileatt = "/home/palaceon/public_html/pdf/pow.pdf"; //Local  Path to the file plz find document root                  
$fileatt_type = "application/pdf"; // File Type  
$fileatt_name = "pow.pdf"; // Filename that will be used for the file as the attachment  
$email_from = "abc@gmail.com"; // Who the email is from  
$email_subject = "Your attached file"; // The Subject of the email  
$email_message = "Thanks for visiting mysite.com!  Here is your free file.<br>";
$email_message .= "Thanks for visiting.<br>"; // Message that the email has in it  
$email_to = "vikash_vikku25@gmail.com"; // Who the email is to  
$headers = "From: ".$email_from;  
$file = fopen($fileatt,'rb');  
$data = fread($file,filesize($fileatt));  
fclose($file);  
$semi_rand = md5(time());  
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";  
    
$headers .= "\nMIME-Version: 1.0\n" .  
            "Content-Type: multipart/mixed;\n" .  
            " boundary=\"{$mime_boundary}\"";  
$email_message .= "This is a multi-part message in MIME format.\n\n" .  
                "--{$mime_boundary}\n" .  
                "Content-Type:text/html; charset=\"iso-8859-1\"\n" .  
               "Content-Transfer-Encoding: 7bit\n\n" .  
$email_message .= "\n\n";  
$data = chunk_split(base64_encode($data));  
$email_message .= "--{$mime_boundary}\n" .  
                  "Content-Type: {$fileatt_type};\n" .  
                  " name=\"{$fileatt_name}\"\n" .  
                  //"Content-Disposition: attachment;\n" .  
                  //" filename=\"{$fileatt_name}\"\n" .  
                  "Content-Transfer-Encoding: base64\n\n" .  
                 $data .= "\n\n" .  
                  "--{$mime_boundary}--\n";  
$ok = @mail($email_to, $email_subject, $email_message, $headers);  
if($ok) { 
echo "<font face=verdana size=2><center>You file has been sent<br> to the email address you specified.<br> 
Make sure to check your junk mail!<br>
Click <a href=\"#\" onclick=\"history.back();\">here</a> to return to http://web-tipsandtricks.blogspot.com/.</center>";
} else {  
die("Sorry but the email could not be sent. Please go back and try again!");  
}  
?>

Differences between PHP4 and PHP5


PHP5 is a lot different than PHP4. With the vastly improved Object Oriented model in PHP5, PHP is now a lot closer to a fully fledged object orientated programming language .

Following differences between PHP4 and PHP5 .

 1. Unified Constructors and Destructors:
In PHP 4 the constructor was just a method with the same name(Class) as the name of the class. So, if you changed the name of the class, you had to go and update it every time it was used. 
In PHP 5, to spare the coders this hassle, the PHP developers have created an unified name for the constructors - "__construct()".

A new addition word is the "__destruct()" keyword. When used, the code will be executed only when the object is destroyed.

In PHP5, you simply need to name your constructors as __construct(). (the word ‘construct’ prefixed by double underscores). Similarly you can name your destructors as __destruct(). (the word ‘destruct’ prefixed by double underscores.) In destructors, you can write code that will get executed when the object is destroyed.
2. Abstract Class:
PHP5 lets you declare a class as ‘Abstract’. (i.e. a class whose object cannot be created. You can only extend an abstract class) Also, a class must be defined as abstract if it contains any abstract methods. And those abstract methods must be defined within the class which extends that abstract class. You can include complete method definitions within the abstract methods of abstract class.
Here is how a normal class is defined:
class Message{

and here is how an abstract class is defined:
abstract class Message{

3. Final Keyword:
PHP5 allows you to declare a class or method as ‘Final’ now. The "final" keyword has been introduced, so that a method cannot be overridden by a child now. This keyword can also be used to finalize a class in order to prevent it from having children.
.
4. Exception Handling:
PHP5 has introduced ‘exceptions’. An exception is simply a kind of error and the ‘exception error’ can be handled in an exception object. By using an exception, one can gain more control over the simple trigger_error notices we were stuck with before.
When you are about to perform something ‘risky’ in your code, you can surround your code with a ‘try…catch’ block. First you surround your code in a ‘try {…….}’ block, then if an exception is thrown, your following ‘catch{……}’ block is there to intercept the error and handle it accordingly. You can write some PHP code in your ‘catch’ block which will get executed when an error occurs in the ‘try’ block. If there is no ‘catch’ block, a fatal error occurs.
5. E_STRICT Error Level:
PHP5 introduces new error level defined as ‘E_STRICT’ (value 2048). This error levels notifies you when you use depreciated PHP code. It is not included in E_ALL, if you wish to use this new level you must specify it explicitly.
6. Autoloading (the __autoload() function):
PHP5 introduces a special function called ‘__autoload()’ (the word ‘autoload’ prefixed by double underscores). This function allows you to avoid writing a long list of includes at the top of your script by defining them inside this function. So you can automatically load object files when PHP encounters a class that hasn’t been defined yet.
Example:
function __autoload ($class_name) {
include $class_name . '.php';
}
7. Visibility:
In PHP5, class methods and properties now have ‘visibility’. There are 3 levels of visibilities:
Public: ‘Public’ is the most visible. Methods are accessible to everyone including objects outside the classes. And properties readable and writable by everyone including objects outside the classes.
Private: ‘Private’ makes class members only available to the class itself.
Protected: ‘Protected’ makes class members accessible to the class itself and any inherited class (subclass) as well as any parent classes.
PHP4′s method of declaring a variable as ‘var’ keyword is still supported in PHP5. The ‘var’ keyword is now a synonym for the ‘public’ keyword now.

Here is an example of how members are declared
<?php
/**
  * Define ClassA
  */
class ClassA
{
     public $public = 'Public';
     protected $protected = 'Protected';
     private $private = 'Private';
    function printHello()
     {
         echo $this->public;
         echo $this->protected;
         echo $this->private;
     }
}
$bor = new ClassA();
echo $bor->public; // Will work
echo $bor->protected; // Will give you a fatal error
echo $bor->private; // Will give you a fatal error
$obj->printHello(); // Will display Public, Protected and Private
/**
  * Define ClassB
  */
class ClassB extends ClassA
{
     // we can redeclare both the public and protected method, but we can't redeclare the private one
     protected $protected = 'Protected2';
    function printHello()
     {
         echo $this->public;
         echo $this->protected;
         echo $this->private;
     }
}
$obj2 = new MyClass2();
echo $obj2->public; // Will work
echo $obj2->private; // Is now undefined
echo $obj2->protected; // Will display a fatal error
$obj2->printHello(); // Will show you Public, Protected2, Undefined
?>



8. Pass by Reference:
In PHP 4 everything, including objects, was passed by value. This has been changed in PHP 5 where everything is passed by reference.
In PHP4, everything was passed by value, including objects. Whereas in PHP5, all objects are passed by reference. Take a look at this PHP4 code for example -
$peter = new Person();
$peter->sex = ’male’;
$maria = $peter;
$maria->sex = ’female’;
echo $peter->sex; // This will output ‘female’
As you can see in the code above, if you wanted to duplicate an object in PHP4, you simply copied it by assigning it to another variable (Pass by value). But now in PHP5 you must use the new ‘clone’ keyword. So the above PHP4 code, will now look like this in PHP5 -
$peter = new Person();
$maria = new Person();
$peter->sex = ’male’;
$maria = clone $peter;
$maria->sex = ’female’;
echo $peter->sex; // This will output ‘female’
PHP Code:
$pObject1 = new Object();
$pObject1->setName('Adam');
$pObject1->setAddress('http://www.google.com/');

$pObject2 = new Object();
$pObject2->setName('Karl');
$pObject2->setAddress('http://www.google.com/');

This is a typical PHP 4 code - if you wanted to duplicate an object, you had to copy it and assign a new value to it. In PHP 5 the coder can simply use the “clone”. This also means that you no longer need to use the reference operator (&) for your code.

Here is how the same code will look in PHP 5 :
$pObject1 = new Object();
$pObject1->setName('Adam');
$pObject1->setAddress('http://www.talkphp.com/');
$pObject2 = clone $pObject1;
$pObject2->setName('Karl');
 

Since we were chaning only the name, we "cloned" the first object and simply changed the value that needed changing.
9. Interfaces:
PHP5 introduces ‘interfaces’. An interface defines the methods a class must implement. All the methods defined in an interface must be public. An interface helps you design common APIs. It is not designed as a blueprint for classes, but just a way to standardize a common API. A big advantage of using interfaces is that a class can implement any number of interfaces. You can still only ‘extend’ on parent class, but you can ‘implement’ an unlimited number of interfaces.
A big advantage of this new addition is that in a class you can implement any number of interfaces.

Here is how it all works :

an example of a simple class:
class cow {
function moo() {
echo "moo, moo, moo …";
}
}
and now we implement the interface in the class:
class cow implements animal{ 
function moo() {
echo "moo, moo, moo …";
}
function breath() { echo "cow is breathing …";}
function eat() { echo "cow is easting …";}
}
When an interface is implemented in a class, the class MUST define all methods and functions of the interface, otherwise the php parser will show a fatal error.



10. Class Constants and Static Methods/Properties
With PHP 5 you can safely create class constants that act in very much the same way as do defined constants, but are limited within a class definition and can be accessed with “::”. Have in mind that constants must have a constant expression for a value; they can't be equal to a variable or a result of a function call.

Here is how you can define a constant:

PHP Code:
const constant = 'constant value';

And here is how the constant can be accessed in a defined class:

PHP Code:
class MyClass
{
   const constant = 'constant value';

   function showConstant() {
       echo  self::constant . "\n";
   }
}

The Static Methods and Properties are also a PHP 5 innovation. When a class member is declared as static, it's accessible with "::" without an instance. 
11. Magic Methods
All methods, starting with a double underscore ("__") are defined as "Magic Methods". They are set to additional functionality to the classes. It's recommended that you don't use methods with the same naming pattern.

Some of the most used magic methods are: __call, __get, __set and __toString.

Monday, February 18, 2013

SEO RULES FOR 2013


Google is now aiming at how to determine real brands from fake sites only trying to force their way up the SERP.  Here is a list of factors Google is looking at.

  1. Social Impact of Content- Successful brands will see heavy traffic from social interaction.  By monitoring this, Google can easily adjust rankings by social activity.
  2. Keywords- Using similar, but not exact keywords can have a large impact.  However using the same exact keywords over and over is just the way to see yourself get banned.  Stop stuffing and start similating. (My verb for focusing content on similes.)
  3. Less is More.  Stop creating unique domains with exact keyword match, ie. FitnessGyminPhoenixAZ.com.  Focus on one main branded website, and build all the content on a single URL.  Stop the madness of exact match URLs.  This is a perfect way for Google to sniff out the posers from the players. Build a brand.
  4. Sharable Content- With a new commitment to writing and creating good content, you should focus on true valued tips.  If someone finds value to what you’re righting, you have a much higher chance at someone sharing it.  Stop the ambiguous content.  Chances are you get sick of writing it, and no one reads it anyway.  Show some Karma love by giving your readers something insightful, and they will share the love by promoting it to their friends.
At the end of the day, a good company will focus on high quality content, then spend their marketing efforts sharing it.  Engage. Use good media…you’ll be surprised with how well your rankings in 2013 improve.

Sunday, February 17, 2013

Web programming tips and tricks


Web programming tips and tricks


Computer programming (often shortened to programming, scripting, or coding) is the process of designing, writing, testing, debugging, and maintaining the source code of computer programs. This source code is written in one or more programming languages like as Php, C++, Java,ASP etc.). The purpose of programming is to create a set of instructions that computers use to perform specific operations or to exhibit desired behaviors. The process of writing source code often requires expertise in many different subjects, including knowledge of the application domain, specialized algorithms and formal logic.This website web Solutions, web programming technique, shorting programming, , mysql query technique, query Solutions etc