» tutorials


mod_accessibility for Apache 2

Intermediate, 9th September 2003, Nick Kew. An introduction to mod_accessibility for Apache 2 from it's author Nick Kew.

XHTML Web Design for Beginners Part Two

Basic/Beginner, 21st February 2003, Nigel Peck. This article is for those who want to learn Web Design from scratch using the latest version of HTML, XHTML. This article follows on from Part One.

PHP Search engine

Make a Search Engine For Your Website With PHP
by: Rory Canyon

This hands on PHP Programming article provides the knowledge necessary to design and develop a search engine for your website using PHP version 4.0 and above. Making a search engine for your website with PHP is really easy and provides substantial functionality required by most of the small to medium websites. This article introduces every steps of the development, including both design and PHP programming. Basic computer skills and knowledge of HTML fundamentals are required. Ok, let’s begin now.

Step 1: Design Search Box

Under your website root, make a file called search.htm or anything you like and type in the following code:

Step 2: Write search.php file. It is the core of your website search engine.

Under your website root, create a file called search.php or anything you like.

< ?php

//get keywords

$keyword=trim($_POST["keyword"]);

//check if the keyword is empty

if($keyword==""){

echo"no keywords";

exit;

}

?>

With above, you can give hints to your users when they forget to enter a keyword. Now let’s go through all the files or articles in your website.

< ?php

function listFiles($dir){

$handle=opendir($dir);

while(false!==($file=readdir($handle))){

if($file!="."&&$file!=".."){

//if it is a directory, then continue

if(is_dir("$dir/$file")){

listFiles("$dir/$file");

}

else{

//process the searching here with the following PHP script

}

}

}

}

?>

The following scripts read, process files and check whether the files contain $keyword. If $keyword is found in the file, the file address will be saved in an array-type variable.

< ?php

function listFiles($dir,$keyword,&$array){

$handle=opendir($dir);

while(false!==($file=readdir($handle))){

if($file!="."&&$file!=".."){

if(is_dir("$dir/$file")){

listFiles("$dir/$file",$keyword,$array);

}

else{

//read file

$data=fread(fopen("$dir/$file","r"),filesize("$dir/$file"));

//avoid search search.php itself

if($file!="search.php"){

//contain keyword?

if(eregi("$keyword",$data)){

$array[]="$dir/$file";

}

}

}

}

}

}

//define array $array

$array=array();

//execute function

listFiles(".","php",$array);

//echo/print search results

foreach($array as $value){

echo "$value"."
\n”;

}

?>

Now, combine the programs listed above, you will find all the related results in your websites will be found and listed. A further optimization of the search engine can be taken by adding the following,

1,list the title of all searching results

REPLACE THE FOLLOWING

if(eregi(”$keyword”,$data)){

$array[]=”$dir/$file”;

}

WITH

if(eregi(”$keyword”,$data)){

if(eregi(”(.+) </p> <p>“,$data,$m)){

$title=$m[”1″];

}

else{

$title=”no title”;

}

$array[]=”$dir/$file $title”;

}

2,Add links to searching results

CHANGE THE FOLLOWING

foreach($array as $value){

echo “$value”.”
\n”;

}

TO

foreach($array as $value){

list($filedir,$title)=split(”[ ]”,$value,”2″);

echo “$value“.”
\n”;

}

3 Set time limit for PHP execution

ADD THE FOLLOWING AT THE BEGINNING OF PHP FILES

set_time_limit(”600″);

The above unit is second,so ten minutes is the litmit.

Now, combine all the above programs and get the complete search.php file as following,

< ?php

set_time_limit("600");

$keyword=trim($_POST["keyword"]);

if($keyword==""){

echo"Please enter your keyword";

exit;

}

function listFiles($dir,$keyword,&$array){

$handle=opendir($dir);

while(false!==($file=readdir($handle))){

if($file!="."&&$file!=".."){

if(is_dir("$dir/$file")){

listFiles("$dir/$file",$keyword,$array);

}

else{

$data=fread(fopen("$dir/$file","r"),filesize("$dir/$file"));

if(eregi("]+)>(.+)”,$data,$b)){

$body=strip_tags($b[”2″]);

}

else{

$body=strip_tags($data);

}

if($file!=”search.php”){

if(eregi(”$keyword”,$body)){

if(eregi(”“,$data,$m)){

$title=$m[”1″];

}

else{

$title=”no title”;

}

$array[]=”$dir/$file $title”;

}

}

}

}

}

}

$array=array();

listFiles(”.”,”$keyword”,$array);

foreach($array as $value){

list($filedir,$title)=split(”[ ]”,$value,”2″);

echo “$title “.”
\n”;

}

?>

Now, you have made a search engine for your website, enjoy it!

About The Author

Rory Canyon is the founder of ScriptMenu.com, a free web directory for PHP, ASP, ASP.NET, PERL, XML, Java, JavaScript, Flash, CFML, Python and other web programming resources.

For more information, visit http://www.scriptmenu.com

Planning your website design

Site Planning is Crucial!
by: Werner Coetzee

If you are thinking about, or you are in the process of creating a new site, you will most definitely find this article interesting and maybe even inspiring. Actually the term ‘interesting’ is not quite what I thought as I slowly and painfully reconstructed the pages on my mother’s website several times over.

I wanted to create a site that was going to be both incredibly user friendly and informative, and at the same time earn a bit of revenue from Google Adsense! Why not?

So with this great little idea, I blindly set off and started to create what was going to be a online resource of complimentary recipes on www.mom2me.com.

This brings me to my biggest and most costly mistake ever. Lack of planning!

I cannot stress the importance of this aspect enough. I would have saved myself literally weeks, if not months, by simply sitting down with a piece of paper and planning my layout carefully.

In all fairness to myself, I must say that I am not a site designer by any stretch of the imagination, but was rather finding my way around the wonderful world of web design and pain by an uncalculated process of trial and error.

In summary: Plan, plan and then plan some more.

If you still doubt why I stress the importance of planning, I will explain in practical terms what happened to me in the creation of my site. If this doesn’t bring the message home, nothing will!

Scripts in the Header section of your site.

As I mentioned earlier, I really wanted to make the site simple and easy to navigate. All the recipes on the site should be easy to copy, paste, mail to a friend and even bookmark.

Well, this is where my first blunder crept in. I decided to make use of some great little scripts on the site to enable users to mail recipes to friends at the touch of a button and also bookmark the page rather effortlessly.

The scripts were really simple to incorporate, but after doing about 100 recipes, I read an article explaining the dangers of adding ‘full’ scripts in the header section of your pages. I learnt that by adding to many scripts in this section of the page makes it difficult for the ‘bots’ to read the content and that it could adversely effect your Page rank and Search engine placing.

This is not a good idea as you might imagine and thus I spent several days rewriting every single page and placing the scripts into separate JavaScript files. This was not the last time I did this!

Search Facility

I really wanted to make it easy for visitors to be able to search for content on my site but I decide to leave that as a phase two of my development. Mistake!

After stumbling across Google’s great ‘search my site” facility I decided to add it to my site. Great idea, but due to the fact that I didn’t add proper Meta Keywords on every page I had a small problem to overcome.

Yep you guessed it. I had to redo every single page on the site yet again. Ouch!

The base tag functionality

Deciding to make use of the base tag functionality within Dream Weaver was a great idea to simplify my designing process, but…

When finely it was time to create my sitemap I suddenly realized that I had countless (almost a hundred) broken links and although it was my own stupidity I still had to re-do almost all my links, on all my pages. Watch out for this. It is an absolute spirit crusher!

My advise, make use of the full URL in all your links on all your pages i.e. http://www.mom2me.com/promo.htm

Site Navigation

I have left the best for last. Due to a complete and utter lack of proper planning, I realized that I omitted a section of the site for people to sign up for my Newsletter.

As everybody who has probably ever done a site knows, this is a crucial part of your site. Whether you are selling directly from your site or whether you plan to do mailing campaigns at a later stage with some marketing material on them, it is crucial to collect as many e-mail addresses as possible, as often as possible.

Well, this forced me to redo the very basics of my pages and … yup redo every single page again.

Now, by now you might feel sorry for me or you might just feel that I am a complete and utter idiot. Regardless of your feelings, I think that from this very practical example it is abundantly obvious that a lack of proper planning will only lead to heart ache and countless sleepless nights. (I think I actually have even less hair!)

Plan your site carefully and live happily ever after!

About The Author

Werner Coetzee
Apprentice Site Owner and Designer
Mom2me.com