Monday, November 16, 2009

Hosting your own Web site

Hosting your own Web site
Hosting your web site on your own server is always an option. Here are some points to consider:
Hardware Expenses
To run a "real" web site, you will have to buy some powerful server hardware. Don't expect that a low cost PC will do the job. You will also need a permanent (24 hours a day ) high-speed connection.
Software Expenses
Remember that server-licenses often are higher than client-licenses. Also note that server-licenses might have limits on number of users.
Labor Expenses
Don't expect low labor expenses. You have to install your own hardware and software. You also have to deal with bugs and viruses, and keep your server constantly running in an environment where "everything could happen".

Web Hosting Providers

Using an Internet Service Provider
Renting a server from an Internet Service Provider (ISP) is a common option.
Most small companies store their web site on a server provided by an ISP. Here are some advantages:
Connection Speed
Most ISPs have very fast connections to the Internet.
Powerful Hardware
ISPs often have powerful web servers that can be shared by several companies. You can also expect them to have an effective load balancing, and necessary backup servers.
Security and Stability
ISPs are specialists on web hosting. Expect their servers to have more than 99% up time, the latest software patches, and the best virus protection.
Things to Consider with an ISP
24-hour support
Make sure your ISP offers 24-hours support. Don't put yourself in a situation where you cannot fix critical problems without having to wait until the next working day. Toll-free phone could be vital if you don't want to pay for long distance calls.
Daily Backup
Make sure your ISP runs a daily backup routine, otherwise you may lose some valuable data.
Traffic Volume
Study the ISP's traffic volume restrictions. Make sure that you don't have to pay a fortune for unexpected high traffic if your web site becomes popular.
Bandwidth or Content Restrictions
Study the ISP's bandwidth and content restrictions. If you plan to publish pictures or broadcast video or sound, make sure that you can.
E-mail Capabilities
Make sure your ISP supports the e-mail capabilities you need.
Front Page Extensions
If you use FrontPage to develop your web site, make sure your ISP supports FrontPage server extensions.
Database Access
If you plan to use data from databases on your web site, make sure your ISP supports the

What is a Web Server?

The collection of all your web pages is called your web site.
To let others view your web pages, you must publish your web site.
To publish your work, you must copy your site to a web server.
Your own PC can act as a web server if it is connected to a network.
Most common is to use an Internet Service Provider (ISP).

What is an Internet Service Provider?

ISP stands for Internet Service Provider.
An ISP provides Internet Services.
A common Internet service is web hosting.
Web hosting means storing your web site on a public server.
Web hosting normally includes email services.
Web hosting often includes domain name registration.

how create a web

Getting Started
There are basically two ways to make a web page. The first way is to create the page(s) offline and then upload them to your Internet Service Provider (ISP) via FTP. The second way is to create your web page(s) online using a Telnet program by accessing your UNIX account, if you have one.
If you are creating your web page(s) offline, do so in any text editing or word processing document. Make sure that when you save your document, you save it as a "text", "plain text" or "text only" document. Otherwise it will not be read properly by a web browser. Once you have created your page(s), you will need to contact your ISP about how to go about uploading them to your server.

Tuesday, October 6, 2009

Testing For PHP and MySQL

There is a simple test for both PHP and MySQL. Open a text editor and type in the following:and save it as phpinfo.phpNow upload this to your webspace and go to it in your browser. If you have PHP installed you will see a huge page with all the details of your PHP installation on it. Next, scroll down through all this information. If you find a section about MySQL then you will know that MySQL is installed.

What Do I Need?

You only really need three things to run PHP scripts which access MySQL databases. Firstly, you will, of course, need a webserver. This can either be on a computer of your own or on a web host. Any web server software should work with PHP and MySQL but the best to use is Apache, which is free.PHP also needs to be installed on the server. If it is not already installed you can install it (or ask your web host to install it). It can be downloaded from PHP.net and is also free. If you are not sure if you have PHP installed I will show you a way to check it later.Finally, you will also require MySQL. This is the actual database software. You can also use most other types of database (SQL, Oracle etc.) but as this is a PHP/MySQL tutorial I will deal just now with the MySQL database (although the commands used here will also work with SQL databases). As with the other software you need, MySQL is free and can be downloaded from the MySQL homepage. If you are not sure if you have MySQL installed, I will show you how to check later.If you cannot install (or your web host won't allow) PHP and MySQL you can still use another web host. Freedom2Surf are a free (banner supported) web host and support PHP and have MySQL installed. HostRocket are an excellent web host and can offer you 300MB of space with PHP, MySQL and loads of other extras for under $10 a month.

Why Would I Want A Database?

It is actually surprising how useful a database can be when used with a website. There are a huge variety of things you can do when you interact the two, from displaying simple lists to running a complete website from a database. Some examples of PHP and MySQL being used together are:
Banner Rotation. On this site, where each banner is, a PHP script is called. This opens a database and picks a random banner from it to show the visitor. It also counts the number of times the banner has been viewed and could, with a few changes, track clicks too. To add, change or edit the banners all I have to do is change the database and the script will pick the correct banners for all the pages on the site.
Forums. Hundreds of forums (message boards) on the internet are run using PHP and MySQL. These are much more efficent than other systems that create a page for each message and offer a wide variety of options. All the pages in the forum can be updated by changing one script.
Databases. One quite obvious example is sites which get all there information from a database. For example Script Avenue is run by a few scripts, which gain all their information from a large database. All the different script categories can be accessed in one script by just changing the URL to access a different part of the database.
Websites. If you have a large website and you want to change the design it can take a very long time to update and upload all the pages. With PHP and MySQL your whole website could be just one or two PHP scripts. These would access a MySQL database to get the information for the pages. To update the website's design you would just have to change one page.

Finishing and Testing Your Script

Now you have finished your script save it as phpinfo.php and upload it to your server in the normal way. Now, using your browser, go the the URL of the script. If it has worked (and if PHP is installed on your server) you should get a huge page full of the information about PHP on your server.If your script doesn't work and a blank page displays, you have either mistyped your code or your server does not support this function (although I have not yet found a server that does not). If, instead of a page being displayed, you are prompted to download the file, PHP is not installed on your server and you should either serach for a new web host or ask your current host to install PHP.It is a good idea to keep this script for future reference.

Thursday, August 20, 2009

WebDynamic

“The true PHP/MySQL bible, PHP
and MySQL Web Development by Luke
Welling and Laura Thomson, made me
realize that programming and databases are
now available to the commoners. Again, I
know 1/10000th of what there is to know,
and already I’m enthralled.”

Wright Sullivan

“I just wanted to tell you that I think the
book PHP and MySQL Web Development
rocks! It’s logically structured, just the right
difficulty level for me (intermediate),
interesting and easy to read, and, of course,
full of valuable information!”

Welling & Thomson

the Sams book by Welling &
Thomson is the only one which I have
found to be indispensable.The writing is
clear and straightforward but never wastes
my time.The book is extremely well laid
out.The chapters are the right length and
chapter titles quickly take you where you
want to go.”

Nick Landman

“I’ve never purchased a better
programming book… This book proved to
be the most informative, easiest to follow,
and had the best examples of any other
computer-related book I have ever
purchased.The text is very easy to follow!”

Monday, July 6, 2009

Overview of File Processing

There are three steps to writing data to a file:
1. Open the file. If the file doesn’t already exist, it will need to be created.
2. Write the data to the file.
3. Close the file.
Similarly, there are three steps to reading data from a file:
1. Open the file. If the file can’t be opened (for example, if it doesn’t exist), we need
to recognize this and exit gracefully.
2. Read data from the file.
3. Close the file.
When you want to read data from a file, you have choices about how much of the file to
read at a time.We’ll look at each of those choices in detail.
For now, we’ll start at the beginning by opening a file.

Saving Data for Later

There are basically two ways you can store data: in flat files or in a database.
A flat file can have many formats but, in general, when we refer to a flat file, we mean a
simple text file. In this example, we’ll write customer orders to a text file, one order per
line.
52 Chapter 2 Storing and Retrieving Data
This is very simple to do, but also pretty limiting, as we’ll see later in this chapter. If
you’re dealing with information of any reasonable volume, you’ll probably want to use a
database instead. However, flat files have their uses and there are some situations when
you’ll need to know how to use them.
Writing to and reading from files in PHP is virtually identical to the way it’s done in
C. If you’ve done any C programming or UNIX shell scripting, this will all seem pretty
familiar to you.

Storing and Retrieving Data

NOW THAT WE KNOW HOW TO access and manipulate data entered in an HTML form,
we can look at ways of storing that information for later use. In most cases, including the
example we looked at in the previous chapter, you’ll want to store this data and load it
later. In our case, we need to write customer orders to storage so that they can be filled
later.
In this chapter we’ll look at how you can write the customer’s order from the previous
example to a file and read it back.We’ll also talk about why this isn’t always a good
solution.When we have large numbers of orders, we should use a database management
system such as MySQL.
Key topics you will learn about in this chapter include
n Saving data for later
n Opening a file
n Creating and writing to a file
n Closing a file
n Reading from a file
n File locking
n Deleting files
n Other useful file functions
n Doing it a better way: database management systems
n Further reading

Saturday, June 13, 2009

Using require for Web Site Templates

If your company has a consistent look and feel to pages on the Web site, you can use
PHP to add the template and standard elements to pages using require().
For example, the Web site of fictional company TLA Consulting has a number of
pages all with the look and feel shown in Figure 5.2.When a new page is needed, the
developer can open an existing page, cut out the existing text from the middle of the
file, enter new text and save the file under a new name.

Consider this scenario:The Web site has been around for a while, and there are now
tens, hundreds, or maybe even thousands of pages all following a common style.A decision
is made to change part of the standard look—it might be something minor, like
adding an email address to the footer of each page or adding a single new entry to the
navigation menu. Do you want to make that minor change on tens, hundreds, or even
thousands of pages?
Directly reusing the sections of HTML that are common to all pages is a much better
approach than cutting and pasting on tens, hundreds, or even thousands of pages.

Thursday, June 11, 2009

The Basic Steps in Querying a Database from

In any script used to access a database from the Web, you will follow some basic steps:
1. Check and filter data coming from the user.
2. Set up a connection to the appropriate database.
3. Query the database.
4. Retrieve the results.
5. Present the results back to the user.
These are the steps we have followed in the script results.php, and we will go through
each of them in turn.

How Web Database Architectures Work

In Chapter 7,“Designing Your Web Database,” we outlined how Web database architectures
work. Just to remind you, here are the steps again:
1. A user’s Web browser issues an HTTP request for a particular Web page. For example,
the user might have requested a search for all the books written by Michael
Morgan at Book-O-Rama, using an HTML form.The search results page is called
results.php.
2. TheWeb server receives the request for results.php, retrieves the file, and passes it
to the PHP engine for processing.
3. The PHP engine begins parsing the script. Inside the script is a command to connect
to the database and execute a query (perform the search for books). PHP
opens a connection to the MySQL server and sends on the appropriate query.
4. The MySQL server receives the database query, processes it, and sends the results—
a list of books—back to the PHP engine.
5. The PHP engine finishes running the script that will usually involve formatting
the query results nicely in HTML. It then returns the resulting HTML to the Web
server.
6. The Web server passes the HTML back to the br

Wednesday, June 10, 2009

Formatting Strings for Storage: AddSlashes() and StripSlashes()

As well as using string functions to reformat a string visually, we can use some of these
functions to reformat strings for storage in a database.Although we won’t cover actually
writing to the database until Part II,“Using MySQL,” we will cover formatting strings
for database storage now.
Certain characters are perfectly valid as part of a string but can cause problems, particularly
when inserting data into a database because the database could interpret these
102 Chapter 4 String Manipulation and Regular Expressions
characters as control characters.The problematic ones are quotes (single and double),
backslashes (\), and the NUL character.
We need to find a way of marking or escaping these characters so that databases such
as MySQL can understand that we meant a literal special character rather than a control
sequence.To escape these characters, add a backslash in front of them. For example, "
(double quote) becomes \" (backslash double quote), and \ (backslash) becomes \\
(backslash backslash). (This rule applies universally to special characters, so if you have \\
in your string, you need to replace it with \\\\.)

Smart Form Mail

In this chapter, we’ll look at string and regular expression functions in the context of a
Smart Form Mail application.We’ll add these scripts to the Bob’s Auto Parts site we’ve
been looking at in the last few chapters.
This time, we’ll build a straightforward and commonly used customer feedback form
for Bob’s customers to enter their complaints and compliments, as shown in Figure 4.1.
However, our application will have one improvement over many you will find on the
Web. Instead of emailing the form to a generic email address like feedback@example.
com, we’ll attempt to put some intelligence into the process by searching the input for
96 Chapter 4 String Manipulation and Regular Expressions
key words and phrases and then sending the email to the appropriate employee at Bob’s
company. For example, if the email contains the word “advertising,” we might send the
feedback to the Marketing department. If the email is from Bob’s biggest client, it can go
straight to Bob.

Tuesday, June 9, 2009

Formatting Strings for Storage:

As well as using string functions to reformat a string visually, we can use some of these
functions to reformat strings for storage in a database.Although we won’t cover actually
writing to the database until Part II,“Using MySQL,” we will cover formatting strings
for database storage now.
Certain characters are perfectly valid as part of a string but can cause problems, particularly
when inserting data into a database because the database could interpret these
102 Chapter 4 String Manipulation and Regular Expressions
characters as control characters.

Formatting Strings

The first step in tidying up is to trim any excess whitespace from the string. Although
this is never compulsory, it can be useful if you are going to store the string in a file or
database, or if you’re going to compare it to other strings.
PHP provides three useful functions for this purpose.We’ll use the trim() function
to tidy up our input data as follows:

Smart Form Mail

In this chapter, we’ll look at string and regular expression functions in the context of a
Smart Form Mail application.We’ll add these scripts to the Bob’s Auto Parts site we’ve
been looking at in the last few chapters.
This time, we’ll build a straightforward and commonly used customer feedback form
for Bob’s customers to enter their complaints and compliments, as shown in Figure 4.1.
However, our application will have one improvement over many you will find on the
Web. Instead of emailing the form to a generic email address like feedback@example.
com, we’ll attempt to put some intelligence into the process by searching the input for
96 Chapter 4 String Manipulation and Regular Expressions
key words and phrases and then sending the email to the appropriate employee at Bob’s
company. For example, if the email contains the word “advertising,” we might send the
feedback to the Marketing department. If the email is from Bob’s biggest client, it can go
straight to Bob.
Figure 4.1 Bob’s feedback form asks customers for
their name, email address, and comments.
We’ll start with the simple script shown in Listing 4.1 and add to it as we go along.
Listing 4.1 processfeedback.php—Basic Script to Email Forms Contents

String Manipulation

IN THIS CHAPTER,WE’LL DISCUSS HOW you can use PHP’s string functions to format and
manipulate text.We’ll also discuss using string functions or regular expression functions
to search (and replace) words, phrases, or other patterns within a string.
These functions are useful in many contexts.You’ll often want to clean up or reformat
user input that is going to be stored in a database. Search functions are great when
building search engine applications (among other things).
In this chapter, we will cover
n Formatting strings
n Joining and splitting strings
n Comparing strings
n Matching and replacing substrings with string functions
n Using regular expressions

Tuesday, April 21, 2009

Tom Muck's

Tom Muck's looper extension comes in two versions—a free one that performs the basic task of looping a recordset across several rows and columns, and a commercial one ($19) that offers a number of advanced features. These revised instructions are based on the free version, but you may want to consider buying the commercial one. Tom is a well-respected member of the Dreamweaver community and has a lot of experience developing Dreamweaver extensions.

Sunday, April 19, 2009

Selecting Web listener networks (IP addresses)

The Web listener network, or networks, that you select depend on the networks from which clients will connect to the published Web server. For example, if the Web site you are publishing allows client requests from the Internet (External network), you should select the External network for the Web listener. By selecting the External network, you are selecting the IP addresses on the ISA Server computer that are associated with the External network adapter. If you do not limit the IP addresses, all the IP addresses associated with the selected network adapter will be included in the listener configuration.

Saturday, April 18, 2009

Network Basics

A host is a computer that is enabled to function on a network
any set of hosts connected in such a way that any two hosts can send and receive messages is called a network
a protocol is the method by which two computers agree to communicate
an address space is the set of names of computers that can be referenced

History of the Internet

Internet traffic grew
Businesses spent heavily to improve Internet
Better service their clients
Fierce competition among communications carriers and hardware and software suppliers
Result
Bandwidth (info carrying capacity) of Internet increased tremendously
Costs plummeted

Multidimensional Arrays

Arrays do not have to be a simple list of keys and values—each location in the array can
hold another array.This way, we can create a two-dimensional array.You can think of a
two dimensional array as a matrix, or grid, with width and height or rows and columns.
If we want to store more than one piece of data about each of Bob’s products, we
could use a two-dimensional array.
Figure 3.3 shows Bob’s products represented as a two-dimensional array with each
row representing an individual product and each column representing a stored product
attribute.

What Is an Array?

A scalar variable is a
named location in which to store a value; similarly, an array is a named place to store a
set of values, thereby allowing you to group scalars.
Bob’s product list will be the array for our example. In Figure 3.1, you can see a list
of three products stored in an array format and one variable, called products, which
stores the three values. (We’ll look at how to create a variable like this in a minute.)
After we have the information as an array, we can do a number of useful things with it.
Using the looping constructs from Chapter 1, we can save work by performing the same
actions on each value in the array.The whole set of information can be moved around as
a single unit

File Modes

The operating system on the server needs to know what you want to do with a file that
you are opening. It needs to know if the file can be opened by another script while you
have it open, and to work out if you (the owner of the script) have permission to use it
in that way. Essentially, file modes give the operating system a mechanism to determine
how to handle access requests from other people or scripts and a method to check that
you have access and permission to this particular file.
There are three choices you need to make when opening a file:
1. You might want to open a file for reading only, for writing only, or for both reading
and writing.
2. If writing to a file, you might want to overwrite any existing contents of a file or
to append new data to the end of the file.
3. If you are trying to write to a file on a system that differentiates between binary
and text files, you might want to specify this.

Overview of File Processing

There are three steps to writing data to a file:
1. Open the file. If the file doesn’t already exist, it will need to be created.
2. Write the data to the file.
3. Close the file.
Similarly, there are three steps to reading data from a file:
1. Open the file. If the file can’t be opened (for example, if it doesn’t exist), we need
to recognize this and exit gracefully.
2. Read data from the file.
3. Close the file.
When you want to read data from a file, you have choices about how much of the file to
read at a time.We’ll look at each of those choices in detail.
For now, we’ll start at the beginning by opening a file.

Using PHP

In order to work through the examples in this chapter and the rest of the book, you will
need access to a Web server with PHP installed.To get the most from the examples and
case studies, you should run them and try changing them.To do this, you’ll need a testbed
where you can experiment.
If PHP is not installed on your machine, you will need to begin by installing it, or
getting your system administrator to install it for you.You can find instructions for doing
so in Appendix A,“Installing PHP 4 and MySQL.”

php Course

In this book, you’ll learn how to use PHP by working through lots of real world
examples, taken from our experience in building e-commerce sites. Often programming
textbooks teach basic syntax with very simple examples.We have chosen not to do that.
We recognize that often what you want to do is get something up and running, to
understand how the language is used, rather than plowing through yet another syntax
and function reference that’s no better than the online manual.