PHP
This is a primary topic
Dynamically load a class in PHP
Recently I visited a PHP forum where a user was asking how to "Dynamically Load A Class" in PHP using a variable.
He proceeded to make an invalid example like:
$module = new Mod_{$tmp_Name} ();
It is common in PHP to allow a PHP script to be extended just by adding extra classes. Theses classes are often found automatically and loaded from a variable in a string.
The problem is the solution that the user came up with is the most often used, but most insecure method. It was to use the eval function:
$toRun = "\$module = new Mod_{$toPass} ();";
eval ($toRun);
The eval command is a very powerful command. Used in correctly it can be a vary large security hole in your website.
The best method of dynamically loading a class in PHP that should have been used is:
$toRun = 'MyClass';
$instance = new $toRun();
Editing live sites and the power of __autoload() in PHP 5
I have always wondered how many web developers have a development server to program on and how many just edit the PHP script their site is running on. I know that I am the second and often parts of my website will seem to fall over when I am working on them. This is where the power of the __autoload function introduced in PHP 5 can be showcased.
What is __autoload
The __autoload method is a way to load classes in PHP as they are needed. This means that programs can can control:
- Which classes are loaded
- When to load classes
- Which version of classes to load
It is called when PHP can not find a class to load and fails if __autoload can not load the requested class.
From the PHP manual:
Many developers writing object-oriented applications create one PHP source file per-class definition. One of the biggest annoyances is having to write a long list of needed includes at the beginning of each script (one for each class).
In PHP 5, this is no longer necessary. You may define an __autoload function which is automatically called in case you are trying to use a class which hasn't been defined yet. By calling this function the scripting engine is given a last chance to load the class before PHP fails with an error.
It goes on to give the example of:
This example attempts to load the classes >MyClass1 and MyClass2 from the files MyClass1.php and >MyClass2.php respectively.
function __autoload($class_name) {
require_once $class_name . '.php';
}
$obj = new MyClass1();
$obj2 = new MyClass2();
?>
Editing a section of a site
I am often editing the PHP code on my site, and this means that errors may appear on parts of the site, or access to parts of the site prevented. The power of __autoload means that any errors that PHP encounters when parsing a file containing one class can be limited to whenever that class is used. The class might be only used on one page of the site, so instead of a syntax error taking down the entire site, pages only display errors when that section of the code is used.
Easy to maintain code
One of the things about PHP that used to get to me was the requirement to include so many classes separately. I have always have one PHP class in each file so 100 PHP classes means 100 files. This is a long list of paths to change. PHP code can become much more maintainable through the use of __autoload.
Speed and Performance
There is a very simple rule when it comes to loading classes: "the more you load, the longer it is going to take". As you create more and more classes, PHP will take longer parsing each one and this affects your websites speed.
Through the use of __autoload and on demand loading, the code overhead can be reduced significantly reducing the code base size with potential errors for each page and loading time decreased.
Invalid host attack on PHP websites
When you are creating a PHP script on your website, you many be unaware that there is a security flaw in many website to do with the HTTP_HOST environment variable. This variable is accessed in PHP through the variable:
$_SERVER['HTTP_HOST']
It is easy to assume that the HTTP_HOST environment variable will always be set, and with many shared, virtual webhosts this is true. The problem appears when a webhost has a static IP for each users account.
When a request comes in to that IP address, even if the HTTP_HOST is not specified in the request, the webserver knows the default website root directory to use. This means that any PHP script in the default website root directory can be accessed with an invalid HTTP_HOST (incorrect domain) environment variable.
The exploit
As my PHP programmers expect the $_SERVER['HTTP_HOST'] variable to carry a valid http_host, they do not expect it to not be set. When it is not set, it can cause the PHP script to behave unexpectedly, and may cause security holes
Solution
The solution is very easy, just do not assume that the environment variables are valid. When you need to use them, make sure that they are set to one of the values you expect.
PHP Live
PHP Live is a live support system for Web sites offered by phplivesupport.com. Its functions include unlimited operators, unlimited departments, chat initiation, click tracking, Web site traffic monitoring, and more.
PHP Live a few good features:
- Real-time chat and support;
- Multiple chat requests at a time;
- Creating different departments;
- Tracking and collecting information for visitors;
- Saving the chat transcripts;
- Rating the customer service;
- Supporting your own chat logos;
- Tracking of the referred urls;
- Multiple language support;
- Knowledge Base (FAQ) Integration;
Problems
Other than the fact that PHP Live is not free like other PHP scripts, it also has some problematic security flaws. These flaws are made worse by the fact that owners of this product have to pay yearly to fix known flaws. Some examples are:
PHPLive version 3.2.1 and prior
Vulnerability identified in PHPLive, which may be exploited by attackers to execute arbitrary commands. This flaw is due to input validation errors in the "help.php" and "setup/header.php" scripts that fail to validate the "css_path" parameter, which could be exploited by remote attackers to include malicious files and execute arbitrary commands with the privileges of the web server.
PHPLive Helper version 2.0 and prior
Vulnerability identified in PHP Live Helper, which could be exploited by attackers to execute arbitrary commands. This flaw is due to an input validation error in the "global.php" script that fails to validate the "abs_path" parameter, which could be exploited by remote attackers to include malicious files and execute arbitrary commands with the privileges of the web server.
Horde framework project
The Mission
The Horde Project is about creating high quality Open Source applications, based on PHP and the Horde Framework.
The guiding principles of the Horde Project are to create solid standards-based applications using intelligent object oriented design that, wherever possible, are designed to run on a wide range of platforms and backends.
There is great emphasis on making Horde as friendly to non-English speakers as possible. The Horde Framework currently supports many localization features such as unicode and right-to-left text and generous users have contributed many translations for the framework and applications.
Currently Horde Project boasts many applications, some already enterprise-ready and deployed in demanding environments, and some exciting new ones still in development.
The Code
The development of the framework and the applications is a community process, with contributions both from individual developers and corporations. The Core Team members are the people who are actively involved on the development in designing and coding the framework and applications.
The applications are under various Open Source licenses, mostly under the GNU Public License. The Horde Framework itself, as of version 2.0, is released under the LGPL.
The Horde applications are written in PHP, a scripting language explicitly designed to be embedded in web pages. PHP can be embedded directly into the web server, with plugins for not just Apache but also IIS, Sun Web Server, etc.
Horde Projects
This is a listing of some of the major projects going under the Horde umbrella.
The Horde Application Framework
The Horde Framework is the glue that all Horde applications have in common. It is many things, including some coding standards, common code, and inter-application communication. The shared code provides common ways of handling things like preferences, permissions, browser detection, user help, and more.
Horde Email Platform
IMP
IMP provides webmail access to any IMAP or POP3 mailbox, and handles internet standard MIME attachments, user defined filters, preferences, and more. IMP was the first Horde application, and in some respects Horde grew out of it.
Other IMP-related Projects
DIMP
DIMP is a alternate presentation view of IMP using AJAX-ish technologies to create a more dynamic user experience (DIMP stands for Dynamic IMP).
MIMP
MIMP is a stripped down version of IMP for use on mobile phones, PDAs, and anything with a small screen or limited HTML support.
Ingo
Ingo is an email filter rules manager. It can generate Sieve, procmail and IMAP scripts and upload them to or execute them on the server (using a timsieved or VFS FTP driver, or the PHP IMAP extension, respectively).
Sork
Sork is a collection of four other Horde modules: accounts, forwards, passwd, and vacation. Together they perform various account management functions such as changing passwords, setting up e-mail forwards, and setting up e-mail vacation notices (auto responder messages).
Horde Groupware Suite
Horde Groupware
Horde Groupware is a free, enterprise ready, browser based collaboration suite. Users can manage and share calendars, contacts, tasks and notes with the standards compliant components from the Horde Project. Horde Groupware bundles the separately available applications Kronolith, Turba, Nag and Mnemo.
Gollem
Gollem is a web-based File Manager, providing the ability to fully manage a hierarchical file system stored in a variety of backends such as a SQL database, as part of a real filesystem, or on an FTP server.
Kronolith
The Kronolith calendar provides a robust web-based calendar for any number of users or groups, with the ability to show any number of calendars in a single overlaid view. Users can create any number of calendars and grant read, edit, or full permissions to any user, group, or any combination thereof.
Mnemo
Mnemo is a note manager. It has the same sharing features as Kronolith and Nag, allowing workgroups to have a common notepad as well as private notes for individuals.
Nag
Nag is a multiuser task list manager. Users can create any number of "task lists", which can be shared with individual users, groups, or any combination. Any number of task lists can be viewed in a single list. Tasks have due dates, completion times, and can be imported and exported in multiple formats.
Trean
Trean is a bookmarks manager for Horde, allowing you to store your bookmarks in one place and access them from any browser. Bookmarks can be grouped into categories which can be shared with arbitrary users.
Turba
Turba is the Horde address book / contact management program. It provides a generic frontend to searching and managing LDAP, SQL, IMSP, and several other contact sources.
Horde Developer Tools
Chora
Chora is the Horde repository viewer, and it provides an advanced web-based view of any CVS, RCS, or Subversion repository. It includes annotation support, visual branch viewing capability, and human-readable diffs. It powers http://cvs.horde.org/ and hundreds of other web cvs interface sites.
Whups
The Web Horde User Problem Solver, besides being a contrived acronym, is a ticket-tracking system integrated with the rest of Horde. It runs http://bugs.horde.org/.
Automatic Keyword Generator
Content sites often use keywords to better describe the topics of published articles. The keywords may help the sites being better indexed by placing the keywords in the page META tags. Another useful application of the keywords is to build tag clouds that give a better idea of which are most popular topics of a site.
Usually the authors or moderators need to specify the article keywords. In some cases, it is not convenient to ask the contributors to enter the article keywords, as it is a tedious task that they may not be interested to do. In other cases, it may not be viable to ask the contributors to associate tags, as the articles were already submitted before keyword association was implemented.
This class provides an automated solution to suggest relevant keywords to be associated to the text of an article.It provides an alternative solution to the situations described above, on which it is not convenient or viable to ask the original contributors to associate keywords to their articles.
class.autokeyword.php
<?php
/******************************************************************
Projectname: Automatic Keyword Generator
Version: 0.3
Author: Ver Pangonilo <smp_AT_itsp.info>
Last modified: 26 July 2006
Copyright (C): 2006 Ver Pangonilo, All Rights Reserved
* GNU General Public License (Version 2, June 1991)
*
* This program is free software; you can redistribute
* it and/or modify it under the terms of the GNU
* General Public License as published by the Free
* Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
Description:
This class can generates automatically META Keywords for your
web pages based on the contents of your articles. This will
eliminate the tedious process of thinking what will be the best
keywords that suits your article. The basis of the keyword
generation is the number of iterations any word or phrase
occured within an article.
This automatic keyword generator will create single words,
two word phrase and three word phrases. Single words will be
filtered from a common words list.
Change Log:
===========
0.2 Ver Pangonilo - 22 July 2005
================================
Added user configurable parameters and commented codes
for easier end user understanding.
0.3 Vasilich (vasilich_AT_grafin.kiev.ua) - 26 July 2006
=========================================================
Added encoding parameter to work with UTF texts, min number
of the word/phrase occurrences,
******************************************************************/
class autokeyword {
//declare variables
//the site contents
var $contents;
var $encoding;
//the generated keywords
var $keywords;
//minimum word length for inclusion into the single word
//metakeys
var $wordLengthMin;
var $wordOccuredMin;
//minimum word length for inclusion into the 2 word
//phrase metakeys
var $word2WordPhraseLengthMin;
var $phrase2WordLengthMinOccur;
//minimum word length for inclusion into the 3 word
//phrase metakeys
var $word3WordPhraseLengthMin;
//minimum phrase length for inclusion into the 2 word
//phrase metakeys
var $phrase2WordLengthMin;
var $phrase3WordLengthMinOccur;
//minimum phrase length for inclusion into the 3 word
//phrase metakeys
var $phrase3WordLengthMin;
function autokeyword($params, $encoding)
{
//get parameters
$this->encoding = $encoding;
mb_internal_encoding($encoding);
$this->contents = $this->replace_chars($params['content']);
// single word
$this->wordLengthMin = $params['min_word_length'];
$this->wordOccuredMin = $params['min_word_occur'];
// 2 word phrase
$this->word2WordPhraseLengthMin = $params['min_2words_length'];
$this->phrase2WordLengthMin = $params['min_2words_phrase_length'];
$this->phrase2WordLengthMinOccur = $params['min_2words_phrase_occur'];
// 3 word phrase
$this->word3WordPhraseLengthMin = $params['min_3words_length'];
$this->phrase3WordLengthMin = $params['min_3words_phrase_length'];
$this->phrase3WordLengthMinOccur = $params['min_3words_phrase_occur'];
//parse single, two words and three words
}
function get_keywords()
{
$keywords = $this->parse_words().$this->parse_2words().$this->parse_3words();
return substr($keywords, 0, -2);
}
//turn the site contents into an array
//then replace common html tags.
function replace_chars($content)
{
//convert all characters to lower case
$content = mb_strtolower($content);
//$content = mb_strtolower($content, "UTF-8");
$content = strip_tags($content);
$punctuations = array(',', ')', '(', '.', "'", '"',
'<', '>', ';', '!', '?', '/', '-',
'_', '[', ']', ':', '+', '=', '#',
'$', '"', '©', '>', '<',
chr(10), chr(13), chr(9));
$content = str_replace($punctuations, " ", $content);
// replace multiple gaps
$content = preg_replace('/ {2,}/si', " ", $content);
return $content;
}
//single words META KEYWORDS
function parse_words()
{
//list of commonly used words
// this can be edited to suit your needs
$common = array("able", "about", "above", "act", "add", "afraid", "after", "again", "against", "age", "ago", "agree", "all", "almost", "alone", "along", "already", "also", "although", "always", "am", "amount", "an", "and", "anger", "angry", "animal", "another", "answer", "any", "appear", "apple", "are", "arrive", "arm", "arms", "around", "arrive", "as", "ask", "at", "attempt", "aunt", "away", "back", "bad", "bag", "bay", "be", "became", "because", "become", "been", "before", "began", "begin", "behind", "being", "bell", "belong", "below", "beside", "best", "better", "between", "beyond", "big", "body", "bone", "born", "borrow", "both", "bottom", "box", "boy", "break", "bring", "brought", "bug", "built", "busy", "but", "buy", "by", "call", "came", "can", "cause", "choose", "close", "close", "consider", "come", "consider", "considerable", "contain", "continue", "could", "cry", "cut", "dare", "dark", "deal", "dear", "decide", "deep", "did", "die", "do", "does", "dog", "done", "doubt", "down", "during", "each", "ear", "early", "eat", "effort", "either", "else", "end", "enjoy", "enough", "enter", "even", "ever", "every", "except", "expect", "explain", "fail", "fall", "far", "fat", "favor", "fear", "feel", "feet", "fell", "felt", "few", "fill", "find", "fit", "fly", "follow", "for", "forever", "forget", "from", "front", "gave", "get", "gives", "goes", "gone", "good", "got", "gray", "great", "green", "grew", "grow", "guess", "had", "half", "hang", "happen", "has", "hat", "have", "he", "hear", "heard", "held", "hello", "help", "her", "here", "hers", "high", "hill", "him", "his", "hit", "hold", "hot", "how", "however", "I", "if", "ill", "in", "indeed", "instead", "into", "iron", "is", "it", "its", "just", "keep", "kept", "knew", "know", "known", "late", "least", "led", "left", "lend", "less", "let", "like", "likely", "likr", "lone", "long", "look", "lot", "make", "many", "may", "me", "mean", "met", "might", "mile", "mine", "moon", "more", "most", "move", "much", "must", "my", "near", "nearly", "necessary", "neither", "never", "next", "no", "none", "nor", "not", "note", "nothing", "now", "number", "of", "off", "often", "oh", "on", "once", "only", "or", "other", "ought", "our", "out", "please", "prepare", "probable", "pull", "pure", "push", "put", "raise", "ran", "rather", "reach", "realize", "reply", "require", "rest", "run", "said", "same", "sat", "saw", "say", "see", "seem", "seen", "self", "sell", "sent", "separate", "set", "shall", "she", "should", "side", "sign", "since", "so", "sold", "some", "soon", "sorry", "stay", "step", "stick", "still", "stood", "such", "sudden", "suppose", "take", "taken", "talk", "tall", "tell", "ten", "than", "thank", "that", "the", "their", "them", "then", "there", "therefore", "these", "they", "this", "those", "though", "through", "till", "to", "today", "told", "tomorrow", "too", "took", "tore", "tought", "toward", "tried", "tries", "trust", "try", "turn", "two", "under", "until", "up", "upon", "us", "use", "usual", "various", "verb", "very", "visit", "want", "was", "we", "well", "went", "were", "what", "when", "where", "whether", "which", "while", "white", "who", "whom", "whose", "why", "will", "with", "within", "without", "would", "yes", "yet", "you", "young", "your", "br", "img", "p","lt", "gt", "quot", "copy");
//create an array out of the site contents
$s = split(" ", $this->contents);
//initialize array
$k = array();
//iterate inside the array
foreach( $s as $key=>$val ) {
//delete single or two letter words and
//Add it to the list if the word is not
//contained in the common words list.
if(mb_strlen(trim($val)) >= $this->wordLengthMin && !in_array(trim($val), $common) && !is_numeric(trim($val))) {
$k[] = trim($val);
}
}
//count the words
$k = array_count_values($k);
//sort the words from
//highest count to the
//lowest.
$occur_filtered = $this->occure_filter($k, $this->wordOccuredMin);
arsort($occur_filtered);
$imploded = $this->implode(", ", $occur_filtered);
//release unused variables
unset($k);
unset($s);
return $imploded;
}
function parse_2words()
{
//create an array out of the site contents
$x = split(" ", $this->contents);
//initilize array
//$y = array();
for ($i=0; $i < count($x)-1; $i++) {
//delete phrases lesser than 5 characters
if( (mb_strlen(trim($x[$i])) >= $this->word2WordPhraseLengthMin ) && (mb_strlen(trim($x[$i+1])) >= $this->word2WordPhraseLengthMin) )
{
$y[] = trim($x[$i])." ".trim($x[$i+1]);
}
}
//count the 2 word phrases
$y = array_count_values($y);
$occur_filtered = $this->occure_filter($y, $this->phrase2WordLengthMinOccur);
//sort the words from highest count to the lowest.
arsort($occur_filtered);
$imploded = $this->implode(", ", $occur_filtered);
//release unused variables
unset($y);
unset($x);
return $imploded;
}
function parse_3words()
{
//create an array out of the site contents
$a = split(" ", $this->contents);
//initilize array
$b = array();
for ($i=0; $i < count($a)-2; $i++) {
//delete phrases lesser than 5 characters
if( (mb_strlen(trim($a[$i])) >= $this->word3WordPhraseLengthMin) && (mb_strlen(trim($a[$i+1])) > $this->word3WordPhraseLengthMin) && (mb_strlen(trim($a[$i+2])) > $this->word3WordPhraseLengthMin) && (mb_strlen(trim($a[$i]).trim($a[$i+1]).trim($a[$i+2])) > $this->phrase3WordLengthMin) )
{
$b[] = trim($a[$i])." ".trim($a[$i+1])." ".trim($a[$i+2]);
}
}
//count the 3 word phrases
$b = array_count_values($b);
//sort the words from
//highest count to the
//lowest.
$occur_filtered = $this->occure_filter($b, $this->phrase3WordLengthMinOccur);
arsort($occur_filtered);
$imploded = $this->implode(", ", $occur_filtered);
//release unused variables
unset($a);
unset($b);
return $imploded;
}
function occure_filter($array_count_values, $min_occur)
{
$occur_filtered = array();
foreach ($array_count_values as $word => $occured) {
if ($occured >= $min_occur) {
$occur_filtered[$word] = $occured;
}
}
return $occur_filtered;
}
function implode($gule, $array)
{
$c = "";
foreach($array as $key=>$val) {
@$c .= $key.$gule;
}
return $c;
}
}
?>
example.script.php
<?php
/******************************************************************
Projectname: Automatic
Keyword Generator Application Script
Version: 0.3
Author: Ver
Pangonilo <[email protected]>
Last modified: 26 July 2006
Copyright (C): 2006 Ver Pangonilo, All
Rights Reserved
* GNU General Public License (Version 2,
June 1991)
*
* This program is free software; you can
redistribute
* it and/or modify it under the terms of
the GNU
* General Public License as published by
the Free
* Software Foundation; either version 2
of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope
that it will
* be useful, but WITHOUT ANY WARRANTY;
without even the
* implied warranty of MERCHANTABILITY or
FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General
Public License
* for more details.
Description:
This class can generates automatically
META Keywords for your
web pages based on the contents of your
articles. This will
eliminate the tedious process of thinking
what will be the best
keywords that suits your article. The
basis of the keyword
generation is the number of iterations
any word or phrase
occured within an article.
This automatic keyword generator will
create single words,
two word phrase and three word phrases.
Single words will be
filtered from a common words list.
Change Log:
===========
0.3 Ver Pangonilo 26 July 2006
==============================
Revised to show changes in class.
******************************************************************/
//assuming that your site contents is from a database.
//set the outbase of the database to $data.
$data =<<<EOF
Imagine being overseas
and your
identity being available for the taking - your nationality, your name,
your passport number. Everything.
That's the fear of privacy and security specialists now that the
State Department plans to issue "e-Passports" to American travelers
beginning in late August.
They'll have radio frequency identification (RFID) tags and are
meant to cut down on human error of immigration officials, speed the
processing of visitors and safeguard against counterfeit passports.
Yet critics are concerned that the security benefit of RFID
technology, which combines silicon chips with antennas to make data
accessible via radio waves, could be vastly outweighed by security
threats to the passport holder.
"Basically, you've given everybody a little radio-frequency doodad
that silently declares 'Hey, I'm a foreigner,'" says author and
futurist Bruce Sterling, who lectures on the future of RFID technology.
"If nobody bothers to listen, great. If people figure out they can
listen to passport IDs, there will be a lot of strange and inventive
ways to exploit that for criminal purposes."
RFID chips are used in security passes many companies issue to
employees. They don't have to be touched to a reader-machine, only
waved near it. Following initial objections by security and privacy
experts, the State Department added several security precautions.
But experts still fear the data could be "skimmed," or read remotely
without the bearer's knowledge.
Kidnappers, identity thieves and terrorists could all conceivably
commit "contactless" crimes against victims who wouldn't know they've
been violated until after the fact.
"The basic problem with RFID is surreptitious access to ID," said
Bruce Schneier security technologist, author and chief technology
officer of Counterpane Internet Security, a technology security
consultancy. "The odds are zero that RFID passport technology won't be
hackable."
The State Department argues the concerns are overstated. "We
wouldn't be issuing the passports to ourselves if we didn't think
they're secure," said Deputy Assistant Secretary of State for Passport
Services Frank Moss, who noted that RFID passports have already been
issued to core State Department personnel, including himself. "We're
our own test population.
EOF;
//this the actual
application.
include('class.autokeyword.php');
echo "<H1>Input
- text</H1>";
echo $data;
$params['content'] = $data; //page
content
//set the length of keywords you like
$params['min_word_length'] = 5; //minimum length of single words
$params['min_word_occur'] = 2; //minimum occur of single words
$params['min_2words_length'] = 3; //minimum length of words for 2 word phrases
$params['min_2words_phrase_length'] = 10; //minimum
length of 2 word phrases
$params['min_2words_phrase_occur'] = 2; //minimum
occur of 2 words phrase
$params['min_3words_length'] = 3; //minimum length of words for 3 word phrases
$params['min_3words_phrase_length'] = 10; //minimum
length of 3 word phrases
$params['min_3words_phrase_occur'] = 2; //minimum
occur of 3 words phrase
$keyword = new autokeyword($params, "iso-8859-1");
echo "<H1>Output
- keywords</H1>";
echo "<H2>words</H2>";
echo $keyword->parse_words();
echo "<H2>2
words phrase</H2>";
echo $keyword->parse_2words();
echo "<H2>2
words phrase</H2>";
echo $keyword->parse_3words();
echo "<H2>All
together</H2>";
echo $keyword->get_keywords();
?>
PHP
PHP (now a recursive acronym for "PHP Hypertext Preprocessor", but originally "Personal Home Page Tools",) is a widely used open-source programming language used primarily for server-side applications, to develop dynamic web content. It can be seen as an open source alternative to Microsoft's Active Server Pages (ASP) system and to CGI/Perl system.
Its ease of use and similarity with the most common structured programming languages, most notably C and Perl, allows most experienced programmers to start developing complex applications with a minimal learning curve. It also enables experienced developers to get involved with dynamic web content applications without having to learn a whole new set of functions and practices.
One of the more attractive parts of PHP is that it is more than just a scripting language. Thanks to its modular design, PHP can also be used to develop GUI applications, and it can be used from the command line just as Perl or Python can be.
PHP allows, among other things, easy interaction with a large number of relational database systems (Oracle, DB2, MySQL, PostgreSQL, etc.), while maintaining a simple and straightforward syntax. PHP runs on every major operating system, including Unix, Linux, Windows, and Mac OS X and can interact with all major web servers. The official PHP website contains extensive online documentation. The Linux, Apache, MySQL, PHP (LAMP) architecture has become very popular in the industry as a way of cheaply deploying reliable, scalable, and secure web applications.
History
PHP was originally designed as a wrapper around Perl by Rasmus Lerdorf in 1994 to display his resume information and collect some data, such as how many hits it was generating. Others first used "Personal Home Page Tools" in 1995, which Lerdorf had combined with his own Form Interpreter to create PHP/FI. Zeev Suraski and Andi Gutmans, two Israeli developers of the Technion - Israel Institute of Technology rewrote the parser in 1997, forming the basis of PHP 3. They also changed the name to its current recursive form. After months in beta, the development team officially released PHP/FI 2 in November 1997. Public testing of PHP 3 began immediately and the official launch came in June 1998. Suraski and Gutmans started a new rewrite of PHP's core, producing the Zend engine in 1999. In May 2000, PHP 4 powered by the Zend Engine was released. Development continues toward PHP 5 with Zend Engine 2.78.
Popularity of PHP
PHP is one of the most popular server-side scripting systems on the Web. It's been widely adopted since the release of version 4, which was the first version powered by the powerful Zend Engine from Zend Technologies.
According to Netcraft's April 2002 survey, PHP is now the most-deployed server-side scripting language, running on around 9 million of the 37 million domains in their survey. This is confirmed by PHP.net's own figures, which show PHP usage measured on a per-domain basis growing at around 5% per month. In May 2003, almost 13 million domains were using PHP, based on the same source. [1]
However, PHP is not the most commonly used tool if measurements are made on a per-page basis. Another estimate in March 2002, based on searching for Web pages by their suffix, places PHP in second place at 30% of measured pages, behind 48% using Microsoft's ASP, but also shows PHP growing rapidly in market share. However, this method is notoriously inaccurate for measuring PHP popularity as some PHP systems dispense with the file names, using only directories, while other sites tend to dispense with the .php extension.
Due to PHP's popularity, a new breed of programmers has emerged who are only familiar with PHP, which in turn forced open the door towards a command line interface for PHP, along with support for GUI functions, such as Gtk or ncurses support. This is a major step for PHP, because it represents its adoption as a genuine programming language (i.e. running autonomously on a stand-alone machine, as opposed to its original purpose of serving web pages to client machines from a server).
Parts or all of this document has been reprinted from http://www.wikipedia.org.
Web Hosting: My DreamHost Experience
I seem to have taken a step up in the world by moving my webhosting and domains from GoDaddy to DreamHost . This is an outline of what this move has taught me. As I run a small, but growing website this looks at the share web-hosting in particular.
Biased Reviews
When I first started to look at hosting with DreamHost I was impressed with the numbers of good reviews that it seemed to have. Only now do I realise that all of these reviews were biased.
All customers of DreamHost are able to become affiliates of DreamHost. What this means is that when current DreamHost customers link to DreamHost they will use an affiliate link. When someone clicks this link and signs up, DreamHost pays them between $1 and $97. The more positive a review is, the more likely people are to sign up and the more money the reviewer gets.
The affiliates (existing customers) can also offer you promo codes that you can use to get discounts or free things. These promo codes are also known as coupon codes or discount codes. The more the code gives you, the less the affiliate gets paid. To make things easier for you, I have provided the best promo code for each type of freebie.
Code | Description |
DHCHEAPEST | Provides the maximum discount possible |
DHMAXDOMAINS |
Provides the maximum number of free domains possible (5 extra domains) |
DHMAXIPS | Provides the maximum number of free IPs possible (3 extra IPs) |
System Resource Limits
People like to compare web-hosts based on:
- Disk space
- Data Transfer (Traffic/Bandwidth)
- Price
With all the cheap web-hosts around there is not much difference in these areas any more.
- They all offer unlimited disk space, as long as it is within "Fair Use",
- They all offer unlimited data transfer-, as long as it is within "Fair Use",
- They all are only $1 or $2 apart in price.
What people do not tend to warn you is that shared web-hosts like to keep your system resource usage to a minimum to maximise the number of websites hosted on each server. Such limits are:
- Web connection limits
- Database connection limits
- CPU time limits
- RAM / Memory limits
You are bound to hit one of these limits before disk space or data transfer becomes a problem and price does not have any relation to system resource limits.
GoDaddy has a large caching proxy server that will cache anything it can. This introduces another layer of complexity and another thing that can go wrong. On my GoDaddy site I was getting intermittent 500 Internal Server Errors that I finally attributed to a lack of support for the Last-Modified header.
With DreamHost I found that there are many limits. PHP had a memory limit of 100 MB, and a script would stop working if it needed more. There was also a CPU time limit that will stop and background processes that has been running too long. DreamHost also does not like to tell people this limit.
Depending on what you use to run your site will determine how much your site can handle before you hit the limits. Although many scripts like WordPress may be written to go gentle on resources, it is often 3rd party plug-ins that cause issues. A lot of ex-DreamHost customer reviews that I have read complain about issues relating to system and resource limits. People will throw more money at getting a host with more resources and not consider that it is likely their website / script that has the problem.
You many be now thinking that more system resources is better, but it is not that cut and dry. If every website on the same web-server gets higher system resource limits, that does not mean that there is more system resources to go around. It just means that when other websites have a lot of traffic it is going to cause problems on your site as well.
Static HTML cache
As I prefer to stay on a cheap web-host, I have written my website to be as easy on resources as possible. All static content is written to HTML files. These files are all updated when a page is changed. Static HTML files is the closest thing to a sure-fire way of curing any system resource limit problems.
No web-host is perfect
No web-host is perfect, no matter the price. A good web-host informs you of any problems and reduces the risk of them occurring. When comparing web-hosts, you may look at:
- Speed, but this will come with lower system resources,
- Uptime, but this will come at the expense of new software versions or the rate at which versions are updated,
- Cost, but at the expense of everything else.
I find that DreamHost is balanced on all of these which I quite like.
Software Versions
The main problem I have with DreamHost at the moment is that they are not the best at running the latest version of software. They are currently running a very old version of subversion and are not running PHP 5.3. At the time of writing PHP 5.3 has been released for 2 months, but DreamHost says they are waiting for 3rd Party PHP libraries to be updated.
Try them out
The best thing that I can suggest is to try DreamHost out.
Contribute Related
Have something to say?
We want to hear from you. Contribute now. No account required.