Html Grammar

The rules are in alphabetical order. The starting rule for an entire document is named html_document.
a_content
::=
heading
 
|
text
a_tag
::=
<a>
   
{a_content}0
   
</a>
abbr_tag
::=
<abbr> text </abbr>
acronym_tag
::=
<acronym> text </acronym>
address_content
::=
p_tag
 
|
text
address_tag
::=
<address>
   
{address_content}0
   
</address>
applet_content
::=
{<param>}0
   
body_content
applet_tag
::=
<applet> applet_content </applet>
b_tag
::=
<b> text </b>
basefont_tag
::=
<basefont> body_content </basefont>
bdo_tag
::=
<bdo> text </bdo>
big_tag
::=
<big> text </big>
blink_tag
::=
<blink> text </blink>
block
::=
{block_content}0
block_content
::=
<isindex>
 
|
basefont_tag
 
|
blockquote_tag
 
|
center_tag
 
|
dir_tag
 
|
div_tag
 
|
dl_tag
 
|
form_tag
 
|
listing_tag
 
|
menu_tag
 
|
multicol_tag
     
 
|
nobr_tag
 
|
ol_tag
 
|
p_tag
 
|
pre_tag
 
|
table_tag
 
|
ul_tag
 
|
xmp_tag
blockquote_tag
::=
<blockquote> body_content </blockquote>
body_content
::=
<bgsound>
 
|
<hr>
 
|
address_tag
 
|
block
 
|
del_tag
 
|
heading
 
|
ins_tag
 
|
layer_tag
 
|
map_tag
 
|
marquee_tag
 
|
text
body_tag
::=
<body>
   
{body_content}0
   
</body>
caption_tag
::=
<caption> body_content </caption>
center_tag
::=
<center> body_content </center>
cite_tag
::=
<cite> text </cite>
code_tag
::=
<code> text </code>
colgroup_content
::=
{<col>}0
colgroup_tag
::=
<colgroup>
   
colgroup_content
content_style
::=
abbr_tag
 
|
acronym_tag
 
|
cite_tag
 
|
code_tag
 
|
dfn_tag
 
|
em_tag
 
|
kbd_tag
 
|
q_tag
 
|
strong_tag
 
|
var_tag
dd_tag
::=
<dd> flow </dd>
del_tag
::=
<del> flow </del>
dfn_tag
::=
<dfn> text </dfn>
dir_tag[b]
::=
<dir>
   
{li_tag}
   
</dir>
div_tag
::=
<div> body_content </div>
dl_content
::=
dt_tag dd_tag
dl_tag
::=
<dl>
   
{dl_content}
   
</dl>
dt_tag
::=
<dt>
   
text
   
</dt>
em_tag
::=
<em> text </em>
fieldset_tag
::=
<fieldset>
   
[legend_tag]
   
{form_content}0
   
</fieldset>
flow
::=
{flow_content}0
flow_content
::=
block
 
|
text
font_tag
::=
<font> style_text </font>
form_content[c]
::=
<input>
 
|
<keygen>
 
|
body_content
 
|
fieldset_tag
 
|
label_tag
 
|
select_tag
 
|
textarea_tag
form_tag
::=
<form>
   
{form_content}0
   
</form>
frameset_content
::=
<frame>
 
|
noframes_tag
frameset_tag
::=
<frameset>
   
{frameset_content}0
   
</frameset>
h1_tag
::=
<h1> text </h1>
h2_tag
::=
<h2> text </h2>
h3_tag
::=
<h3> text </h3>
h4_tag
::=
<h4> text </h4>
h5_tag
::=
<h5> text </h5>
     
h6_tag
::=
<h6> text </h6>
head_content
::=
<base>
 
|
<isindex>
 
|
<link>
 
|
<meta>
 
|
<nextid>
 
|
style_tag
 
|
title_tag
head_tag
::=
<head>
   
{head_content}0
   
</head>
heading
::=
h1_tag
 
|
h2_tag
 
|
h3_tag
 
|
h4_tag
 
|
h5_tag
 
|
h6_tag
html_content
::=
head_tag body_tag
 
|
head_tag frameset_tag
html_document
::=
html_tag
html_tag
::=
<html> html_content </html>
i_tag
::=
<i> text </i>
ilayer_tag
::=
<ilayer> body_content </ilayer>
ins_tag
::=
<ins> flow </ins>
kbd_tag
::=
<kbd> text </kbd>
label_content[d]
::=
<input>
 
|
body_content
 
|
select_tag
 
|
textarea_tag
label_tag
::=
<label>
   
{label_content}0
   
</label>
layer_tag
::=
<layer> body_content </layer>
legend_tag
::=
<legend> text </legend>
li_tag
::=
<li> flow </li>
listing_tag
::=
<listing> literal_text </listing>
map_content
::=
{<area>}0
map_tag
::=
<map> map_content </map>
marquee_tag
::=
<marquee> style_text </marquee>
menu_tag[e]
::=
<menu>
   
{li_tag}0
   
</menu>
multicol_tag
::=
<multicol> body_content </multicol>
nobr_tag
::=
<nobr> text </nobr>
noembed_tag
::=
<noembed> text </noembed>
noframes_tag
::=
<noframes>
   
{body_content}0
   
</noframes>
noscript_tag
::=
<noscript> text </noscript>
object_content
::=
{<param>}0
   
body_content
object_tag
::=
<object> object_content </object>
ol_tag
::=
<ol>
   
{li_tag}
   
</ol>
optgroup_tag
::=
<optgroup>
   
{option_tag}0
   
</optgroup>
option_tag
::=
<option> plain_text </option>
p_tag
::=
<p> text </p>
physical_style
::=
b_tag
 
|
bdo_tag
 
|
big_tag
 
|
blink_tag
 
|
font_tag
 
|
i_tag
 
|
s_tag
 
|
small_tag
 
|
span_tag
 
|
strike_tag
 
|
sub_tag
 
|
sup_tag
 
|
tt_tag
 
|
u_tag
pre_content
::=
<br>
 
|
<hr>
 
|
a_tag
 
|
style_text
pre_tag
::=
<pre>
   
{pre_content}0
   
</pre>
q_tag
::=
<q> text </q>
s_tag
::=
<s> text </s>
samp_tag
::=
<samp> text </samp>
script_tag[f]
::=
<script> plain_text </script>
select_content
::=
optgroup_tag
 
|
option_tag
select_tag
::=
<select>
   
{select_content}0
   
</select>
server_tag [g]
::=
<server> plain_text </server>
small_tag
::=
<small> text </small>
span_tag
::=
<span> text </span>
strike_tag
::=
<strike> text </strike>
strong_tag
::=
<strong> text </strong>
style_tag
::=
<style> plain_text </style>
sub_tag
::=
<sub> text </sub>
sup_tag
::=
<sup> text </sup>
table_cell
::=
td_tag
 
|
th_tag
table_content
::=
<tbody>
 
|
<tfoot>
 
|
<thead>
 
|
tr_tag
table_tag
::=
<table>
   
[caption_tag]
   
{colgroup_tag}0
   
{table_content}0
   
</table>
td_tag
::=
<td> body_content </td>
text
::=
{text_content}0
text_content
::=
<br>
 
|
<embed>
 
|
<iframe>
 
|
<img>
 
|
<spacer>
 
|
<wbr>
 
|
a_tag
 
|
applet_tag
 
|
content_style
 
|
ilayer_tag
 
|
noembed_tag
 
|
noscript_tag
     
 
|
object_tag
 
|
physical_style
 
|
plain_text
textarea_tag
::=
<textarea> plain_text </textarea>
th_tag
::=
<th> body_content </th>
title_tag
::=
<title> plain_text </title>
tr_tag
::=
<tr>
   
{table_cell}0
   
</tr>
tt_tag
::=
<tt> text </tt>
u_tag
::=
<u> text </u>
ul_tag
::=
<ul>
   
{li_tag}
   
</ul>
var_tag
::=
<var> text </var>
xmp_tag
::=
<xmp> literal_text </xmp>

six HTML heading tags

heading                  ::=      h1_tag
                         |        h2_tag
                         |        h3_tag
                         |        h4_tag
                         |        h5_tag
                         |        h6_tag

The heading rule tells us that wherever the heading nonterminal appears in a rule, you can replace it with exactly one of the actual heading tags.

text-shadow

Shadows are another common feature of modern Web designs. Shadows add an
element of depth to a page, but they can also enhance readability (if used properly)
to lift a headline from the page. The text-shadow attribute was technically
part of CSS2, but it has only recently been supported by major browsers:
h2 {
font-size: 300%;
text-shadow: 3px 3px 5px #666666;
}

Natural Link Acquisition

Nothing is better than natural link acquisition. This occurs when people who are genuinely
interested in your site link to it. Information travels fast on the Internet. As long
as your site is of great quality, you will reach a tipping point where it will no longer be
necessary to invest much effort in link building. This is something any site owner should
desire: having a site that is so infectious that it becomes the buzz.

P ARSING XML

Two techniques are used for parsing XML documents in PHP:
SAX(Simple API for XML) andDOM
(Document Object Model). By using SAX, the parser
goes through your document and fires events for every start and stop tag or
other element found in your XML document. You decide how to deal with the
generated events. By using DOM, the whole XML file is parsed into a tree that
you can walk through using functions from PHP. PHP 5 provides another way
of parsing XML: the SimpleXML extension. But first, we explore the two
mainstream methods.

We now leave the somewhat boring theory behind and start with an example.
Here, we’re parsing the example XHTML file we saw earlier. We do that by
using the XML functions available in PHP (http://php.net/xml
)
. First, we create
a parser object:
$xml = xml_parser_create('UTF-8');

xml_set_element_handler($xml, 'start_handler', 'end_handler');
xml_set_character_data_handler($xml, 'character_handler');

function start_handler ($xml, $tag, $attributes)
{
global $level;
echo "\n". str_repeat(' ', $level). ">>>$tag";
foreach ($attributes as $key => $value) {
echo " $key $value";
}
$level++;
}


DOM
Parsing a simple X(HT)ML file with a SAX parser is a lot of work. Using the
DOM (http://www.w3.org/TR/DOM-Level-3-Core/) method is much easier, but
you pay a price—memory usage. Although it might not be noticeable in our
small example, it’s definitely noticeable when you parse a 20MB XML file with
the DOM method. Rather than firing events for every element in the XML file.

<?php
 $dom = new DomDocument();
 $dom->load('test2.xml');
 $root = $dom->documentElement;

 process_children($root);

 function process_children($node)
 {
 $children = $node->childNodes;

 foreach ($children as $elem) {
 if ($elem->nodeType == XML_TEXT_NODE) {
 if (strlen(trim($elem->nodeValue))) {
 echo trim($elem->nodeValue)."\n";
 }
} else if ($elem->nodeType == XML_ELEMENT_NODE) {
process_children($elem);
     }
    }
   }
 ?>
The output is the following:
XML Example
Moved to
example.org
.
foo & bar

PEAR class: System

The System PEAR class is available as part of the basic PEAR install:
<?php
require_once "System.php";
$tmp_file = System::mktemp();
copy("http://php.net/robots.txt", $tmp_file);
$pear_command = System::which("pear");
?>
PEAR class: OS_Guess
The OS_Guess class uses the php_uname() function to determine on which
operating system it is running. It also provides ways of generalizing and comparing
OS signatures:
<?php
require_once "OS/Guess.php";
$os = new OS_Guess;
print "OS signature: " . $os->getSignature() . "\n";
if ($os->matchSignature("linux-*-i386")) {

print "Linux running on an Intel x86 CPU\n";
}
?>

Example output:
OS signature: linux-2.4-i386-glibc2.1
Linux running on an Intel x86 CPU

magic_quotes_gpc, magic_quotes_runtime

Magic quotes is the name of a PHP feature that automatically quotes input
data, by using the addslashes() function. Historically, this was used so that
form data could be used directly in SQL queries without any security or quoting
issues. Today, form data is used for much more, and magic quotes quickly
get in the way. We recommend that you disable this feature, but portable code
must be aware of these settings and deal with them appropriately by calling
stripslashes() on GPS (GET, POST, and cookie) data.

Website SWOT Analysis

A classic staple of business school is the SWOT analysis—identifying strengths, weaknesses,
opportunities, and threats faced by a business or project. By combining data from your business
asset assessment and historical tracking data (and visitor analytics), you can create some very
compelling analyses of your organization and its marketplace.
Identifying strengths is typically one of the easier objectives:

• What sources of traffic are working well for your site/business?
• Which projects/properties/partnerships are driving positive momentum toward traffic/
revenue goals?
• Which of your content sections/types produces high traffic and ROI?
• What changes have you made historically that produced significant value?
Sourcing out the weaknesses can be tougher (and takes more intellectual honesty and courage):
• What content is currently sending low levels of search/visitor traffic?
• Which changes that were intended to produce positive results have shown little/no value?
• Which traffic sources are underperforming or underdelivering?
• What projects/properties/partnerships are being leveraged poorly?

keys to getting links,

Since creating emotional reactions can result in links, building content that plays to the
emotions of potential linkers can be a powerful tool for obtaining links. Sometimes this
process is referred to as link baiting. One key decision for a business is whether such an
approach to link building is consistent with the company’s brand image, but even a
conservative brand can often find worthy link bait topics to be acceptable.

Create quality reference material. Providing unique and powerful information to users
can be a great way to get links, particularly if you can make sure the publishers of
authoritative sites in your market space learn about what you have created, including why
it would be of value to their website visitors.

 Leverage business relationships. In our example, we suggested that you might be someone
who has a network of resellers. If this is your business model, having a link back to you
as a standard term in your reseller agreement is sound business.

rel microformats

Remember the rel attribute from earlier? That attribute is often used in microformats,
and the usage is generally very simple. The rel-license format, for instance, looks like this:
<a rel="license" href="http://creativecommons.ca
/licenses/by-nc-sa/2.5/">
Creative Commons License</a>
By including a rel attribute with a value of license in the anchor tag, you can indicate
that the destination of the hyperlink is a license for the content contained on the current
page. The example I’m using is from my own design blog Unfortunately Paul, where the
content has been made available under a “Creative Commons Attribution-NonCommercial-
ShareAlike 2.5 License,” which means that people are free to copy, distribute, and display
my published entries and to make derivative works so long as I’m credited, it’s for nonprofit
purposes, and any derivations are released under the same license. Creative
Commons is an organization that provides a variety of “some rights reserved” copyright
licenses, allowing content authors to release their content into the wild but retain some
level of copyright.

Associative Arrays?

You can use string values as keys. For example, you might create an array
like this:

$myStuff = array();
$myStuff[“name”] = “andy”;
$myStuff[“email”] = “andy@fsdsd.ca”;
Print $myStuff[“name”];

Associative arrays are different than normal (numeric-indexed) arrays in
some subtle but important ways:
The order is undefined. Regular arrays are always sorted based on the
numeric index. You don’t know what order an associative array will be
because the keys aren’t numeric.

 You must specify a key. If you’re building a numeric-indexed array, PHP
can always guess what key should be next. This isn’t possible with an
associative array.

 Associative arrays are best for name-value pairs. Associative arrays are
used when you want to work with data that comes in name/value pairs.
This comes up a lot in PHP and XHTML. XHTML attributes are often in
this format, as are CSS rules and form input elements.

✦ Some of PHP’s most important values are associative arrays. The $_
REQUEST variable (described in Chapter 3 of this minibook) is an important
associative array. So are $_GET, $_POST, and several others.

Make sure to include quotation marks if you’re using a string as an array
index.

Arrays and HTML

Arrays are great because they’re used to hold lists of data in your programming
language. Of course, HTML already has other ways of working with
lists. The <ul> and <ol> tags are both used for visual representations of
lists, and the <select> object is used to let the user choose from a list. It’s
very common to build these HTML structures from arrays.

Learning the MySQL Data Types

MySQL uses many different data types, broken into three categories: numeric, date and time, and string types.

 INT—A normal-sized integer that can be signed or unsigned. If signed, the
allowable range is from –2147483648 to 2147483647. If unsigned, the allowable
range is from 0 to 4294967295. You can specify a width of up to 11 digits.

. TINYINT—A small integer that can be signed or unsigned. If signed, the allowable
range is from –128 to 127. If unsigned, the allowable range is from 0 to
255. You can specify a width of up to 4 digits.

 SMALLINT—A small integer that can be signed or unsigned. If signed, the
allowable range is from –32768 to 32767. If unsigned, the allowable range is
from 0 to 65535. You can specify a width of up to 5 digits.

 MEDIUMINT—A medium-sized integer that can be signed or unsigned. If signed,
the allowable range is from –8388608 to 8388607. If unsigned, the allowable
range is from 0 to 16777215. You can specify a width of up to 9 digits.

 BIGINT—A large integer that can be signed or unsigned. If signed, the allowable
range is from –9223372036854775808 to 9223372036854775807. If
unsigned, the allowable range is from 0 to 18446744073709551615. You can
specify a width of up to 11 digits.

FLOAT(M,D)—A floating-point number that cannot be unsigned. You can
define the display length (M) and the number of decimals (D). This is not
required and defaults to 10,2, where 2 is the number of decimals and 10 is the
total number of digits (including decimals). Decimal precision can go to 24
places for a FLOAT.

 DOUBLE(M,D)—A double-precision floating-point number that cannot be
unsigned. You can define the display length (M) and the number of decimals
(D). This is not required and will default to 16,4, where 4 is the number of
decimals. Decimal precision can go to 53 places for a DOUBLE. REAL is a synonym
for DOUBLE.


DECIMAL(M,D)—An unpacked floating-point number that cannot be unsigned.
In unpacked decimals, each decimal corresponds to 1 byte. Defining the display
length (M) and the number of decimals (D) is required. NUMERIC is a synonym
for DECIMAL.

$_GET , $_POST,$_COOKIE??

$_GET contains any variables provided to a script through the GET method.
 $_POST contains any variables provided to a script through the POST method.
 $_COOKIE contains any variables provided to a script through a cookie.

What line should you add to the Apache configuration file to ensure that the .php extension is recognized?

This line ensures that Apache will treat files ending with the .php extension as
PHP scripts:
AddType application/x-httpd-php .php

php.ini Basics

After you have compiled or installed PHP, you can still change its behavior
with the php.ini file. On Linux/UNIX systems, the default location for this file is
/usr/local/php/lib or the lib subdirectory of the PHP installation location you
used at configuration time. On a Windows system, this file should be in the PHP
directory or another directory as specified by the value of PHPIniDir in the Apache

What Is a Function?

You can think of a function as an input/output machine. This machine takes the raw
materials you feed it (input) and works with them to produce a product (output). A function
accepts values, processes them, and then performs an action (printing to the browser,
for example), returns a new value, or both.

How do you convert the while statement you created in question 3 into a for statement?

$num = 1;
while ($num <= 49) {
echo $num.”<br />”;
$num += 2;
}

JavaScript Form Validation

 JavaScript Form Validation. JavaScript can be used to validate data in HTML forms


<script type="text/javascript">
function validate_all()
    {
    var frmReg=document.manageadmin;
  
  
  
    if(frmReg.name.value.search(/\S/) == -1)
        {
            alert("Please enter name.");
            frmReg.name.focus();
            return false;
        }
  
  
    if(frmReg.textEmail.value.search(/\S/) == -1)
        {
            alert("Please enter Email.");
            frmReg.textEmail.focus();
            return false;
        }
  

Embedding Content for Plug-Ins

Although never officially a part of any HTML specification, the <<embed>> tag is most often used to include embedded objects for Netscape and Internet Explorer. A Macromedia Flash file might be embedded as follows:
 
 
<<embed id="demo" name="demo"
 src="http://www.javascriptref.com/examples/ch18/flash.swf"
 width="318" height="252" play="true" loop="false"
 pluginspage="http://www.macromedia.com/go/getflashplayer"
 swliveconnect="true">><</embed>>
 
The most important attributes of the <<embed>> tag are src, which gives the URL of the embedded object, and pluginspage, which indicates to the browser where the required plug-in is to be found if it is not installed in the browser. Plug-in vendors typically make available the embedding syntax, so check their site for the value of pluginspage.
Recall that applets embedded with <<object>> tags are passed initial parameters in <<param>> tags. The syntax of <<embed>> is different in that initial parameters are passed using attributes of the element itself. For instance, in the preceding example the play attribute tells the plug-in to immediately begin playing the specified file.
The <<object>> element is the newer, official way to include embedded objects of any kind in your pages. However, <<object>> is not supported in Netscape browsers prior to version 4, and <<embed>> continues to be supported by new browsers. So it is unlikely that <<object>> will completely supplant <<embed>> any time in the near future.
 

Remote JavaScript

The primary reason is that the round trip time required to submit a form and then download the response is often inconvenient. The user experience is much improved if, instead of clicking a Submit button and watching the screen go blank and then be replaced by the response of a server-side program, a user can click a button and have the page be updated without a visible form submission. To the user, the page would behave more like an application than a Web page. 

There are other advantages as well. If communication with a server can be done behind the scenes instead of using form submissions or clicking on links, the developer can carry out more complicated tasks requiring multiple server requests at once. The ability to use remote JavaScript also means that tasks that previously required an ActiveX object or Java applet can be implemented with script. This is a tremendous timesaver for the developer and also reduces the complexity of debugging significantly. 

The abstraction that remote JavaScript brings to life is the remote procedure call. A remote procedure call (RPC) is a function that executes on a remote machine, in this case a Web server. The client, in this case our browser using JavaScript, passes arguments to the “function” it wishes to call via an HTTP request; the server executes the specified function, often implemented as a CGI program or server-side script in PHP or a similar language, and returns the results as the body of the HTTP response. It’s important to remember that while JavaScript is used to make the function call and often to handle the return value, the function itself executes on the server, and therefore can be implemented as a CGI, PHP script, Java servlet, or using any other technology a Web server might have available.

mkdir and rmdir

You can create and remove directories using the mkdir and rmdir system calls.

#include <sys/types.h>
#include <sys/stat.h>
int mkdir(const char *path, mode_t mode);


The mkdir system call is used for creating directories and is the equivalent of the mkdir program. mkdir
makes a new directory with path as its name. The directory permissions are passed in the parameter
mode and are given as in the O_CREAT option of the open system call and, again, subject to umask.

#include <unistd.h>
int rmdir(const char *path);

The rmdir system call removes directories, but only if they are empty. The rmdir program uses this
system call to do its job.

The Shell as a Programming Language

Now that you’ve seen some basic shell operations, it’s time to move on to some actual shell programs. There
are two ways of writing shell programs. You can type a sequence of commands and allow the shell to execute
them interactively, or you can store those commands in a file that you can then invoke as a program.
Interactive Programs
Just typing the shell script on the command line is a quick and easy way of trying out small code fragments,
and is very useful while you are learning or just testing things.

What Is a Shell?

Before jumping in and discussing how to program using a shell, let’s review the shell’s function and the
different shells available for Linux. A shell is a program that acts as the interface between you and the Linux
system, enabling you to enter commands for the operating system to execute. In that respect, it resembles the
Windows command prompt, but as mentioned earlier, Linux shells are much more powerful. For example,
input and output can be redirected using < and >, data piped between simultaneously executing programs
using |, and output from a subprocess grabbed by using $(...). On Linux it’s quite feasible to have multiple
shells installed, with different users able to pick the one they prefer.

You can check the version of bash you have with the following command:
$ /bin/bash --version
GNU bash, version 3.2.9(1)-release (i686-pc-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.

RSVP

Resource Reservation protocol is used to reserve resources across a network. It is used for requesting a specific Quality of Service (QoS) from the network.


RSVP is a signalling protocol for the internet. RSVP stands for bandwidth 
reservation protocol. This protocol allows application to reserve bandwidth for their 
data flows.

What is the use of PEAR in php?

PEAR is known as PHP Extension and Application Repository. It provides structured library to the PHP users and also gives provision for package maintenance.

Create the Other Pages

Now that I have my basic page structure down, it’s time to start looking at the other
pages in my site. Working with the styles I’ve already created (and creating new ones
as I need to), I’ll create the following pages in my layout:
• Blog listing, with the sidebars as used in my two-sidebar layout
• Category page, based on the blog listing page
• Project page, with associated images and text
• Project listing, with images and a brief project description
• Contact page
• A 404 (page not found) and 403 (access denied) page
• The home page, with associated blocks and callout areas
This should cover most of the pages that I will be setting up in the Drupal implementation,
and give me more than enough to work with. Many of the pages will feed each
other—for example, my blog listing page will start with my two-sidebar layout, and
change the listing, and then the category page will follow from that. However, the
project pages, being highly image/case study focused, will require special treatment,
including putting some thought into how I’m going to organize the projects,

Single Node Pages with Sidebars

The point of starting off your template with a node page that doesn’t have sidebars is
this: you will inevitably have a page like this somewhere on your site. And many designers,
well-meaning as they are, end up forgetting this and assume there will be 1–2 sidebars
on the page. As Drupal’s default behavior reflows the text to fill the entire page when
there are no sidebars, this results in these pages having long and drastically uncomfortable
line lengths.
That said, it’s safe to assume that most pages will have at least one sidebar, and that
the sidebars will contain different types of blocks, for example:
• A list of node titles or categories
• Static text or images
• A tag cloud or something similar
• Callout boxes, like a contact form or customer testimonial
Therefore, while I’m working on my node pages, I should also take a look at how these
different types of sidebar blocks will be styled, and how I’ll set up both one- and twosidebar
layouts.

Storing Complex Data Types

You can use sessions to store complex data types such as objects and arrays simply by treating them as standard variables, as this code shows:
    $myarr["0"] = "Sunday";
    $myarr["1"] = "Monday";
    $myarr["2"] = "Tuesday";
    $myarr["3"] = "Wednesday";
    $myarr["4"] = "Thursday";
    $myarr["5"] = "Friday";
    $myarr["6"] = "Saturday";

    $_SESSION["myarr"] = $myarr;

Cookies Versus Sessions?

 Cookies

The setcookie( ) call needs to be before the HTML form because of the way the web works. HTTP operates by sending all "header" information before it sends "body" information. In the header, it sends things like server type (e.g., "Apache"), page size (e.g., "29019 bytes"), and other important data. In the body, it sends the actual HTML you see on the screen. HTTP works in such a way that header data cannot come after body datayou must send all your header data before you send any body data at all.
Cookies come into the category of header data. When you place a cookie using setcookie( ), your web server adds a line in your header data for that cookie. If you try and send a cookie after you have started sending HTML, PHP will flag serious errors and the cookie will not get placed.
There are two ways to correct this:
  • Put your cookies at the top of your page. By sending them before you send anybody data, you avoid the problem entirely.
  • Enable output buffering in PHP. This allows you to send header information such as cookies wherever you likeeven after (or in the middle of) body data. Output buffering is covered in depth in the following chapter.
The setcookie( ) function itself takes three main parameters: the name of the cookie, the value of the cookie, and the date the cookie should expire. For example:
 
setcookie("Name", $_POST['Name'], time( ) + 31536000);
 
In the example code, setcookie( ) sets a cookie called Name to the value set in a form element called Name. It uses time( ) + 31536000 as its third parameter, which is equal to the current time in seconds plus the number of seconds in a year, so that the cookie is set to expire one year from the time it was set.
Once set, the Name cookie will be sent with every subsequent page request, and PHP will make it available in $_COOKIE. Users can clear their cookies manually, either by using a special option in their web browser or just by deleting files.

print $_COOKIE["Name"];


 Sessions

Sessions store temporary data about your visitors and are particularly good when you don't want that data to be accessible from outside of your server. They are an alternative to cookies if the client has disabled cookie access on her machine, because PHP can automatically rewrite URLs to pass a session ID around for you.

 Starting a Session

A session is a combination of a server-side file containing all the data you wish to store, and a client-side cookie containing a reference to the server data. The file and the client-side cookie are created using the function session_start( ) it has no parameters but informs the server that sessions are going to be used.
When you call session_start( ), PHP will check to see whether the visitor sent a session cookie. If it did, PHP will load the session data. Otherwise, PHP will create a new session file on the server, and send an ID back to the visitor to associate the visitor with the new file. Because each visitor has his own data locked away in his unique session file, you need to call session_start( ) before you try to read session variablesfailing to do so will mean that you simply will not have access to his data. Furthermore, as session_start( ) needs to send the reference cookie to the user's computer, you need to have it before the body of your web pageeven before any spaces.

 Adding Session Data

All your session data is stored in the session superglobal array, $_SESSION, which means that each session variable is one element in that array, combined with its value. Adding variables to this array is done in the same way as adding variables to any array, with the added bonus that session variables will still be there when your user browses to another page.
To set a session variable, use syntax like this:
    $_SESSION['var'] = $val;
    $_SESSION['FirstName'] = "Jim";

Older versions of PHP used the function session_register( ); however, use of this function is strongly discouraged, as it will not work properly in default installations of PHP 5. If you have scripts that use session_register( ), you should switch them over to using the $_SESSION superglobal, as it is more portable and easier to read.
Before you can add any variables to a session, you need to have already called the session_start( ) functiondon't forget!
 

$_ENV and $_SERVER ?

PHP sets several variables for you containing information about the server, the environment, and your visitor's request. These are stored in the superglobal arrays $_ENV and $_SERVER, but their availability depends on whether the script is being run through a web server or on the command line.

Useful preset variables in the $_SERVER superglobal
Name
Value
HTTP_REFERER
If the user clicked a link to get the current page, this will contain the URL of the previous page, or it will be empty if the user entered the URL directly.
HTTP_USER_AGENT
The name reported by the visitor's web browser.
PATH_INFO
Any data passed in the URL after the script name.
PHP_SELF
The name of the current script.
REQUEST_METHOD
Either GET or POST.
QUERY_STRING
Includes everything after the question mark in a GET request. Not available on the command line.


Of those, HTTP_REFERER and HTTP_USER_AGENT are the most important, as you can use these two to find out a lot about your visitor and then take the appropriate action. For example:
 
<?php
            if (isset($_SERVER['HTTP_REFERER'])) {
          print "previously was {$_SERVER['HTTP_REFERER']}
      <br />";
            } else {
              print "You didn't click any links to get here<br />";
            }
    ?>

    <a href="refer.php">Click me!</a>

If you load that page in your browser by typing the URL in by hand, the "You didn't click any links to get here" text is shown because HTTP_REFERER has not been set. However, if once the page is loaded you follow the "Click me!" link, the page will reload itself; this time, HTTP_REFERER will be set and the other message should appear. Although it can be easily spoofed, HTTP_REFERER is generally a good way to make sure a visitor came from a certain pagewhether you want to use that to say, "You can't download my files because you came from another site" or "Welcome, Google users!" is up to you.

Install Drupal

Now that you’ve created your database, go back into your favorite browser (I use
Chrome: http://www.google.com/chrome) and go to localhost:8888/d7-demo/install.
php. Choose the “standard” installation profile for now (see Figure 1-8); it will
take care of some basic configurations for you. On the next page, select English as the
installation language. If you need to install it in another language, there’s a handy link
on that screen that will show you how to do it.

Internal link architecture

Website linking architecture is important when it comes to SEO, especially when your
site has many pages or is continuously growing. To create a sound linking structure for
your site, you will likely need to partition your site into distinct subsections (or categories),
forming a uniform (inverted) treelike structure. Sometimes creating
subdomains can help in this regard. Other times, using XML Sitemaps can help showcase
your most important links.

Long-term content

If you use Google to search for any word that appears in the English dictionary, chances
are Google will provide among its search results a result from Wikipedia. The English
dictionary does not change much over time. Sites containing English language dictionary
definitions, such as Wikipedia, are well positioned to receive steady traffic over time.
Most computer programmers use Google to find answers to their development problems.
Sites providing answers to such problems can also benefit from this, as they will
receive a steady flow of traffic.


Creating custom website widgets

Everything starts with an idea. Creating custom widgets
can be as simple or as complex as required. You can create some website widgets by
simply creating custom HTML pages. Others you can create by utilizing Atom/RSS
feeds, Java applets, and Flash. In this section, we will create a sample HTML-based
widget to illustrate the concepts of link baiting and website widgets.
Let’s suppose you own a site that sells many different brands of alarm clocks. To promote
your site, you want to create your own link bait. Specifically, you want to create
a simple digital alarm clock widget (called Wake Up Service) that any site can link to
or use. When the widget is used on other sites, you specify the condition that your link
must be present to use the widget.
On your site, you also want to ensure that your link bait is highly visible (typically
placed at a strategic location for easy recognition).

Widget promotion and distribution.
You can proliferate your widgets in many ways. You can
do it from your site, you can use a third-party site, or you can employ both methods.
Make it easy for your visitors by offering simple cut-and-paste HTML code such as the
following:
<a href="http://scripts.seowarrior.net/quickpanel/wakeup.html"
target="_new">Wake Up Service</a>
This sample code shows the link to our Wake Up Service widget, which will open in a
new window. For website widgets such as the one we created in this example, you could
also write a small article that will be syndicated along with all of your other articles.
People subscribing to your feeds will be able to read about it and propagate the information
if they find it interesting.

Web server compression?

The best way to understand web server compression is to think of sending ZIP files
instead of uncompressed files from your web server to your web user. Sending less data
over the network will minimize network latency and your web users will get the file
faster.
The same thing applies to web spiders, as the major ones support HTTP 1.1. In fact,
search engines would appreciate the fact that they will need to use a lot less network
bandwidth to do the same work.
Web server compression is a technology used on the web server where you are hosting
your pages. If you have full control of the web server, you can set up this compression
to occur automatically for all websites or pages this server is hosting.
If you do not have this luxury, you can set this up in your code. To set up web server
compression in PHP, you can use the following PHP code:
<?php
ob_start("ob_gler");
?>
<HTML>
<body>
<p>This is the content of the compressed page.</p>
</body>
</HTML>
You can enable web server compression in your code in another way that is even easier
than the approach we just discussed. You can use the php.ini file that usually sits in
your root web folder. If it does not exist, you can create it. You can also place this file
in your subfolders to override the root php.ini settings.

Website Performance Traps

Website performance is important from two perspectives: the web spider’s and the web
user’s. If your site has many thousands of pages, you will want to make sure your site
response times are reasonable.

Web spiders are busy creatures. If any of your dynamic pages are computationally
intensive, the web spiders might give up waiting on your page to finish loading. In
technical terms, this is called timing out on a request.

Dynamic pages aren’t the only issue that will cause a web spider to give up. If your
website is running on a server that is hosting many other sites, it may be slow to respond
because of the overwhelming load caused by one of the other sites. As a result, your
website might take many seconds to respond. Another problem could be with your
web host if it experiences network latency due to limited bandwidth.
You can do some things to remedy these situations. The basic idea is to speed up page
transitions to any web client, not just the web spider. Consider using the following:
• Web server compression
• Web page caching

Integrating FeedBurner with your site

Integrating FeedBurner with your site is relatively simple.
You can think of FeedBurner as your website’s feed wrapper service to make your
feed more compatible, more visible, and more easily tracked.

To redirect your existing feed(s), you can use the .htaccess redirect mechanism. The
following fragment shows an example of a permanent redirect and a temporary redirect:
RewriteEngine On
Redirect 301 /news.rss http://feeds2.feedburner.com/NewsFeed
Redirect 302 /news2.rss http://feeds2.feedburner.com/NewsFeedTemp


FeedBurner is still one of the most popular services for content publishers
who want to measure their content syndication subscriber base. After Google
acquired FeedBurner, many publishers reported bugs, including a significant drop in
their subscribed user base. Google claims to have fixed these bugs in addition to providing
more accurate reporting analytics. FeedBurner continues to be a tool of choice
for many content publishers. If you wish to use FeedBurner for statistical or marketing
purposes, you can redirect your existing feeds to FeedBurner.

Traditional Marketing

The value of using SEO is clear. Studies have shown that organic search results are more
highly trusted than PPC (SEM) advertising. SEO is about having the right knowledge,
applying proven techniques, experimenting with new ones, and letting the search engine
do the rest. Naturally, the prerequisite to all of that is to have engaging content
and a quality product (or service). Stay away from:
• Making changes to emulate the competition without knowing why the change was
made
• Applying every SEO rule in the book (overdoing it)
• Not trying different keywords, and instead stopping at only one or a few
• Making frequent SEO-related changes without realizing the effects of previous
changes
The SEO work for each website is different. What is similar, though, is the actual SEO
process. You still have to go through the same exercise, regardless of whether you are
working on a new site or an existing one.

SEO monitoring phase

Once the major SEO work is done in the implementation phase, the focus will be on
website maintenance. The maintenance phase takes care of problems (minor and major)
found in the (re)assessment phase. In many ways, the maintenance phase is similar
to the implementation phase.


The assessment phase uses the output of the monitoring phase as well as a series of
checklists (on which to base the assessment). This phase is also referred to as the
checkpoint phase. SEO checkpoints can be defined on a monthly, quarterly,
semiannual, or yearly basis. At the very least, quarterly assessments are required.
The point of the assessment phase is to see what is and isn’t working according to the
SEO plan. The assessment phase can uncover many problems.

Microblogging with Twitter

Microblogging with Twitter has its limitations. You can do only so much with a single
tweet. You have only 140 characters to describe what you are doing. Anytime you want
to share a long URL, you may run over the 140-character limit.
To create the most efficient tweets, make them even shorter than the 140-character
limit. This way, anyone wishing to retweet your tweets can do so more easily. This is
your way of ensuring that your tweets can propagate to their fullest potential.
To solve this character limitation problem, you can use URL shortening services. In
addition to Bit.ly and TinyURL, you can also use BudURL.

Important crawlers?

Google:
Crawler Description
Googlebot Crawls web pages (it’s the most important of the bunch)
Googlebot-Mobile Crawls pages specifically designed for mobile devices
Googlebot-Image Crawls images for inclusion in image search results
Mediapartners-Google Crawls AdSense content
AdsBot-Google Crawls AdWords landing pages to measure their quality

Yahoo!:
Crawler Description
Slurp Crawls web pages
Yahoo-MMAudVid Crawls video files
Yahoo-MMCrawler Crawls images

Bing:
Crawler Description
MSNBot Crawls web pages
MSNBot-Media Crawls media files
MSNBot-News Crawls news feeds

Web Directories?

Web directories are not search engines in the typical sense; they are collections of links
that have been organized by humans. The advantage of web directories over typical
search engines is that all the links are (usually) reviewed by human editors for quality,
relevance, and suitability before being posted online. Make no mistake: some web directories
are completely automated. You should avoid these types of directories.
The most famous web directory, Open Directory Project, boasts 4,576,062 URLs in its
listings at the time of this writing. Most web directories, including Dmoz.org, can also
be searched.
Not all web directories are free. Some require yearly or one-time listing fees. One such
directory is Yahoo!.

JavaScript Dynamic Links and Menus

Many sites use JavaScript to create links to other website pages. Here is some example
code with different link types that you may want to avoid:

<HTML>
<head>
<title>Link Examples ~ Things to stay away from</title>
<script type="text/javascript">
function gotoLocationX(){
window.location.href='http://www.cnn.com';
}
function gotoLocationY(){
window.location.href='http://www.yahoo.com';
}
function gotoLocationZ(){
window.location.href='http://www.google.com';
}
</script>
</head>
<body>

Example 1:
<a href="#" onClick="javascript:window.location.href=
'http://www.cnn.com'">News on CNN</a>
<br><br>
Example 2:
<a href="#" onClick="javascript:gotoLocationY()">Yahoo Portal</a>
<br><br>
Example 3:
<form>
<input name="mybtn" value="Google Search Engine" type=button
onClick="window.location.href='http://www.google.com'">
</form>
<br><br>
</body>
</html>

When you open this code in your browser, you will see a screen similar to Figure 8-2.
This is not to say that you can never use dynamic links. You obviously can, but you
need to think about tweaking your code to help web spiders see what they need to see.

Content-Sharing Sites

The big players in content sharing have made it relatively simple for anyone to leverage
their platforms in the creation of media-rich content.
YouTube
Three former employees of PayPal created YouTube in 2005. They sold YouTube to
Google in 2006. YouTube is by far the most visited video sharing site on the Internet.
In January 2009, YouTube enjoyed an audience of 100+ million people in the United
States alone (http://bit.ly/11Xxcu).
You can post a video on YouTube.com and then embed the same video on your website
by following a relatively painless process. You can simply insert the Embed code as
supplied by YouTube within your HTML page. You
can also download many custom YouTube widgets to do the same thing.
Uploading your videos to YouTube is also easy. Make sure you optimize your video
title, description, and associated tags. Also, specify in the privacy setting that you want
to make your video public.
Once you upload your video, you can share it by connecting your YouTube account
with Facebook, MySpace, and Google Reader. Take advantage of these opportunities
to spread your news.
You may also consider using YouTube’s video annotations and AudioSwap features.
Video annotations allow you to add pop-up speech bubbles, pop-up boxed notes, textual
spotlights that are shown when the mouse moves over a predefined video area, and
video pauses. The AudioSwap feature lets you add background music to spice up your
videos.

Search Engine Indexing

Google and others are indexing more pages than ever. Many of the modern search
engines now boast upward of a few billion indexed documents. Here is how Wikipedia
describes the process of search engine indexing:
Search engine indexing collects, parses, and stores data to facilitate fast and accurate
information retrieval. Index design incorporates interdisciplinary concepts from linguistics,
cognitive psychology, mathematics, informatics, physics and computer science. An
alternate name for the process in the context of search engines designed to find web pages
on the Internet is Web indexing.
Although web spiders do their best to obtain as many documents as possible for search
engines to index, not all documents get indexed. Search engine indexing is closely tied
to the associated search engine algorithms. The search engine indexing formula is a
highly secretive and intriguing concept to most SEO  enthusiasts.
Search engine indexing is not an entirely automated process.

Domain Name Keywords

If your domain name contains an exact (or partial) match to a search query, chances
are it will show up on the first page of the SERPs—at least on Google. Google gives
keyword matching domains preferential treatment.
The exception to this rule is for competitive keywords. However, the chances of acquiring
a popular keyword domain are minimal, as most, if not all, dictionary words
are taken, in addition to the most popular two- or three-keyword phrase combinations.
This has led to the recent popularity of nonsense words as business names.
For niche keywords, you already won half the battle when you purchased your domain
name. Add an index page with related keywords, and you’ll be on the first page of
Google’s search results in a relatively short period of time.
You can use the following sample formats when creating your domain name:
http://www.keyword1-keyword2.com
http://www.keyword1keyword2keyword3.com
http://www.keyword.com
http://www.keyword.somedomain.com
http://keyword.basename.com
Note that the guidelines for subdomains are the same as for domains. The benefits of
subdomains are multifold, but subdomains can also be viewed as search engine spam
if you create too many of them. With subdomains, you can pick any name you like, as
you are in control of the domain record.

Optimize Your Site for Speed

Nobody has unlimited patience these days. Not everyone has high-speed Internet. Stay
away from (Flash) splash screens. Compress your media files for faster page loading.
Use media files only when you need to. Also make sure to describe your graphics,
videos, and sound files. For sound and video content, provide text transcripts. Make
use of thumbnails for large images. Use web server compression for your HTML web
server transmissions to speed up transmission for all your clients, including search
engine web spiders.

Use Intelligent Page Formatting

Try using smaller paragraphs with mixed-case text. Use boldface, italics, uppercase,
and different text color variations for emphasis. Employ browser-safe fonts such as
Times New Roman, Georgia (serif font), Arial, Helvetica, or Verdana (sans serif font).
Strategically employ bulleted lists, headings, and subheadings for clarity and information
organization. Using these options is helpful from an SEO perspective. Furthermore,
employ sufficient alignments, whitespace, and text padding for additional clarity
and web page look and feel.
Be mindful of web-safe colors. Use high-contrast color schemes for clarity and ease of
reading. Be consistent with colors. Don’t use too many colors. Try to stay away from
image backgrounds.

What is robots.txt?

Yes, that’s right! If you are not very careful with the robots.txt file, you could be blocking
web spiders from crawling content you do want to be indexed. Most reputable web
spiders will obey your instructions within robots.txt. So, be very careful when you use
and edit the robots.txt file. Also note that Google Webmaster Tools provides a
robots.txt checker, so you can enter a URL and confirm whether a given URL will be
crawled.