Wednesday, March 27, 2013

Optimization - PHP, Mysql, Session


Optimize your PHP to Improve Performance
1. Use echo rather than print
2. Reduce variable declaration
3. Don't copy variables for no reason
4. register_globals should be disabled
5. Make sure all inputs are escaped
6. Avoid doing SQL queries within a loop
7. use regular expressions only where it is mandatory
8. Avoid using PHP function inside for()
9. Error Handling
10. Increase the memory size //@ini_set("memory_limit","16M");
11. Use MVC Architecture
12. Use Template System (smarty)
13. Use Caching [ob_start(), ob_get_clean()]
14. Use Output buffering
15. HTML optimize using ob_gzhander
16. Enable compression in php ini
                zlib.output_compression = On
                zlib.output_compression_level = (level) (where level is 1-9)


Session Optimizations
   • Don't use session.auto_start.
   • Do not enable session.use_trans_sid
   • Whenever possible set session.cache_limiter to private_no_expire
   • Assign each user (vhost) its own session’s directory.
   • For large sites consider using session.save_path = "N;/path"
   • If possible avoid automatic garbage collection.


Query Optimization:

              Don’t use “SELECT *”
              Better to use Joins rather than sub-queries
             Unoptimized joins can be VERY slow
             Use LIMIT
             use index meaningful
             confirm you escaped the string correctly
             Use EXPLAIN to find query fast
            Avoid queries in loop

PHP Securities


Security

1.Register Globals should be Off

2. Error Reporting & Exceptions

  a. display_errors to Off
b. log_errors to On
c. ini_set('error_reporting', E_ALL | E_STRICT);
d. ini_set('display_errors', 'Off');
e. ini_set('log_errors', 'On');
f. ini_set('error_log', '/usr/local/apache/logs/error_log');

3. Filter Input Data – validate the data

a. htmlentities( ) for escaping data to be sent to the client.
b. mysql_real_escape_string()

4. Escape Output

5. URL Attacks - Use POST method for dangerous action in form, use GET method if necessary

6. File upload attacks - is_uploaded_file( ) & move_uploaded_file( ).

7. Cross-Site Scripting(XSS) – use htmlentities( )

8. Protect database connection & .inc file access(db.inc) – Permission to confidential pages.

<Files ~ "\.inc$">
Order allow,deny
Deny from all
</Files>

9. SQL injection - mysql_real_escape_string( )

10. session_set_save_handler('_open', '_close', '_read', '_write', '_destroy', '_clean' ) is the best way to prevent session hijacking

11. Remote file inclusion(RFI).

12. Store passwords in an encrypted format in database or files.

13. Avoid taking confidential value in cookies

INI FILE SECURITIES

a. register_globals - should be Off
b. allow_url_fopen – should be Off
c. disable_functions - should be Off
d. display_errors - should be Off in only production server
e. error_reporting – set to E_ALL
f. enabling log_errors
g. memory_limit – 8M in most cases

HTML To XHTML conversion steps


HTML To XHTML conversion steps


To convert a Web site from HTML to XHTML, you should be familiar with the XHTML syntax rules of the previous chapters. The following steps were executed (in the order listed below):


A DOCTYPE Definition Was Added

The following DOCTYPE declaration was added as the first line of every page:
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Note that we used the transitional DTD. We could have chosen the strict DTD, but found it a little too "strict", and a little too hard to conform to.


A Note About The DOCTYPE

Your pages must have a DOCTYPE declaration if you want them to validate as correct XHTML.
Be aware however, that newer browsers (like Internet Explorer 6) might treat your document differently depending on the <!DOCTYPE> declaration. If the browser reads a document with a DOCTYPE, it might treat the document as "correct". Malformed XHTML might fall over and display differently than without a DOCTYPE.


Lower Case Tag And Attribute Names

Since XHTML is case sensitive, and since XHTML only accepts lower case HTML tags and attribute names, a general search and replace function was executed to replace all upper case tags with lowercase tags. The same was done for attribute names. We have always tried to use lower case names in our Web, so the replace function did not produce many real substitutions.


All Attributes Were Quoted

Since the W3C XHTML 1.0 Recommendation states that all attribute values must be quoted, every page in the web was checked to see that attributes values were properly quoted. This was a time-consuming job, and we will surely never again forget to put quotes around our attribute values.


Empty Tags: <hr> , <br> and <img>

Empty tags are not allowed in XHTML. The <hr> and <br> tags should be replaced with <hr /> and <br />.
This produced a problem with Netscape that misinterpreted the <br/> tag. We don't know why, but changing it to <br /> worked fine. After that discovery, a general search and replace function was executed to swap the tags.
A few other tags (like the <img> tag) were suffering from the same problem as above. We decided not to close the <img> tags with </img>, but with  /> at the end of the tag. This was done manually.

New tags added in HTML5


New tags introduced in HTML 5

section represents a generic document or application section. It can be used together with the h1, h2, h3, h4, h5, and h6 elements to indicate the document structure. 
article represents an independent piece of content of a document, such as a blog entry or newspaper article. 
aside represents a piece of content that is only slightly related to the rest of the page.
hgroup represents the header of a section. 
header represents a group of introductory or navigational aids. 
footer represents a footer for a section and can contain information about the author, copyright information, et cetera. 
nav represents a section of the document intended for navigation. 
figure represents a piece of self-contained flow content, typically referenced as a single unit from the main flow of the document.
<figure>
<video src="ogg"></video>
<figcaption>Example</figcaption>
</figure>

figcaption can be used as caption (it is optional).
video and audio for multimedia content. Both provide an API so application authors can script their own user interface, but there is also a way to trigger a user interface provided by the user agent. 
source elements are used together with these elements if there are multiple streams available of different types. 
embed is used for plugin content. 
mark represents a run of text in one document marked or highlighted for reference purposes, due to its relevance in another context. 
progress represents a completion of a task, such as downloading or when performing a series of expensive operations. 
meter represents a measurement, such as disk usage. 
time represents a date and/or time. 
bdi represents a span of text that is to be isolated from its surroundings for the purposes of bidirectional text formatting. 
wbr represents a line break opportunity. 
canvas is used for rendering dynamic bitmap graphics on the fly, such as graphs or games. 
command represents a command the user can invoke. 
details represents additional information or controls which the user can obtain on demand. The 
summary element provides its summary, legend, or caption. 
datalist together with the a new list attribute for input can be used to make combo boxes

New input elements’ type
tel , search , url , email , datetime , date , month , week , time , datetime-local , number , range , color

Below represents the HTML5 Block level and Inline Elements

HTML5 block level elements
article*,header*,aside*,hgroup*,blockquote,hr,body,li,br,map,button,Button,object,canvas*,ol,caption,
output*,col,p,colgroup,pre,dd,progress*,div,section*,dl,table,dt,tbody,embed,textarea,
fieldset,tfoot,figcaption*,th,figure*,thead,footer*,tr,form,ul,h1–h6,video*

HTML5 Inline elements
a,label,abbr,legend,address,link,area,mark*,audio*,meter*,bm,nav*,cite,optgroup,code,option,del,q,details*,
small,dfn,select,command*,source*,datalist*,span,em,strong,font,sub,i,summary*,
iframe,sup,img,tbody,input,td,ins,time*,kbd,var

Do you know the difference?

This tutorial will let you know the difference of HTML, XHML and DHTML , also HTML4 and HTML5


HTML
XHTML
DHTML
HTML (Hypertext Markup Language) is the primary technology used in the development of simple web sites.
XHTML (Extensible Hypertext Markup Language) is almost identical HTML with the exception of a stricter set of syntactic rules based on the XML standard.
technologies used to move beyond the static presentation of information to create more interactive web pages
HTML you can use an opening tag in many instances without a matching closing tag
- XHTML each opening tag must have a matching closing tag.
-Attributes must be in lowercase as XML.
-Special characters between tags need to be replaced with its code equivalent.
DHTML means a combination of XHTML , CSS and JavaScript, DOM

HTML4
HTML5
DOCTYPE is much longer as
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"
http://www.w3.org/TR/html4/strict.dtd">
DOCTYPE is required to enable standards mode for HTML documents.
<!DOCTYPE html>
Audio and Video are not part of HTML4 specification
Audio and Videos are integral part of HTML5 specifications e.g. <audio> and <video> tags
Vector Graphics is possible with the help of technologies such as VML, Silverlight, Flash etc.
Vector graphics is integral part of HTML5 e.g. SVG and canvas
Browser cache can be used as temporary storage.
Application Cache and Web storage is available as client side storage. Accessible using JavaScript interface in HTML5 compliant browsers.
Works with all old browsers
Most of modern browser have started supporting HTML5 specification e.g. Firefox, Mozilla, Opera, Chrome, Safari  etc.
Does not allow JavaScript to run in browser
Allows JavaScript to run in background.
Frames are allowed
No more frames

article, aside, audio, canvas, command, datalist, details, embed, figcaption, figure, footer, header, hgroup, keygen, mark, meter, nav, output, progress, rp, ruby, section, source, summary, time and video.
Type specification for css & scripts is must.
No More Types for Scripts and Links

Make your Content Editable
Email Inputs

Placeholders has been introduced

Header and Footer tags

Required Attribute

Autofocus Attribute

Regular Expressions

Tuesday, March 26, 2013

CSS Optimization Rules

The rules should follow to increase the performance in CSS

1. Decide whether you are using HTML4 or HTML5. Determine the DOCTYPE and CSS3 (border-radius) according to that. Dont use CSS3 in HTML4. CSS3 is especially developed for HTML5.
2. Try to write the all class property in single line instead indent code.
3. Use always lower case for both HTML and CSS
4. Use shorthand properties-each rule on a single line.
5. Use h1 to h6 for site SEO.
6. Change 0px to just ‘0’.
7. Change color code "#000000" to "#000".
8. Change font-weight from “normal" to "400".
9. Change font-weight from “bold" to "700".
10. Use CSS Sprits.
11. Use single CSS file, if more than one, combine all CSS file into single file.
12. Avoid writing inline / internal CSS.
13. Use Link instead of @import the CSS file.
14. Group the similar styles with comma separator.
15. Minimize the number of iframes.
16. Use PNG image.
17. Dont use Hack in the code, instead write separate CSS for IE.
18. Margin / Padding change from "38px 52px 59px 52px" to "38px 52px 59px".
19. Margin / Padding change from "0px 0px 0px 0px !important" to "0 !important".
20. Background (set url, color, repeat and all property in single line).
21. Font (set font family, size/line height and all property in single line).
22. Remove empty selectors.
23. Avoid using duplicates.
24. Remove unnecessary white spacing.
25. Use margin/padding instead of m/ p right, m/p left separately.
26. Font, background, margin, padding, border properties should be merged.
27. Last semicolon should be removed in every block.
28. Don’t need those extra zeros in opacity (0.5), margin (10.0em) , padding(5.3em).
29. Remove comments from production file.
30. Validate your CSS file.
31. Follow the plug-in such as Yslow, Google page speed for more optimization.
32. Always write re-usable styles in separate class, dont refer to any parent element. Eg(.button{color:#aeaeae}, dont specify .leftPan button{color:#aeaeae}

Tuesday, March 19, 2013

How to set Preview DNS on godaddy?

To Enable Preview DNS or Preview Your Site

  1. Log in to your Account Manager.
  2. Click Web Hosting.
  3. Next to the hosting account you want to use, click Launch.
  4. In the Server Details section, click Show details
  5. Click Preview to display your primary domain's DNS information.
  6. If Preview DNS is not already enabled for your account, click Enable. If it has expired, click Renew.
  7. If Preview DNS is enabled, click Preview.
NOTE: Preview DNS expires after 14 days but may be reactivated at any time by repeating these steps.