Showing posts with label and. Show all posts
Showing posts with label and. Show all posts

Tuesday, December 7, 2010

Useful link,article and source code directories

Millions of peoples are trying to get traffic to their websites and spending lots of money in this. Submit article to article directory is a good and popular way of getting SEO and traffic to website.There are lots of paid article directories available in web but a very few free. This software give you chance to submit your article to world's best free article directory article.ognilab.com totally free of cost.

Submit Your article to world's best free article directory

This softwre can help you to find your most needed C,C++ source code from the C,C++ source code directory cprogram.org.You can also submit your source code in web to spread and test your knowledge on programming.Submit C,C++ source code to this directory to make it rich with source code and welfare of other programmers.


Millions of peoples are trying to get traffic to their websites and spending lots of money in this. Submit website link to Web directory is a good and popular way of getting SEO and traffic to website.There are lots of paid web directories available in web but a very few free. This software give you chance to submit your website link to world's best free web directory dir.ognilab.com totally free of cost.

Monday, September 27, 2010

Combining HTML and PHP

The script in Listing 3.1 is pure PHP. You can incorporate this into an HTML
document simply by adding HTML outside the PHP start and end tags, as shown in

1: <html>
2: <head>
3: <title>Listing 3.2 A PHP script including HTML</title>
4: </head>
5: <body>
6: <b>
7: <?php
8: print "hello world";
9: ?>
10: </b>
11: </body>
12: </html>
As you can see, incorporating HTML into a PHP document is simply a matter of
typing in the code. The PHP interpreter ignores everything outside PHP open and
close tags. If you were to view Listing 3.2 with a browser, as shown in Figure 3.4,
you would see the string "hello world" in bold. If you were to view the document
source, as shown in Figure 3.5, the listing would look exactly like a normal HTML
document.
You can include as many blocks of PHP code as you need in a single document,
interspersing them with HTML as required. Although you can have multiple blocks of
code in a single document, they combine to form a single script. Anything defined in
the first block (variables, functions, or classes, for example) usually will be available
to subsequent blocks.

Beginning and Ending a Block of PHP Statements

When writing PHP, you need to inform the interpreter that you want it to execute
your commands. If you don't do this, the code you write will be mistaken for HTML
and will be output to the browser. Table 3.1 shows the four ways of enclosing PHP
code.

PHP Start and End Tags

Tag Style             Start Tag                                  End Tag
Standard tags        <?php                                        ?>
Short tags              <?                                             ?>
ASP tags                <%                                            %>
Script tags    <SCRIPTLANGUAGE="php">          </script>


only the standard and the script tags can be guaranteed to
work on any configuration. The short and ASP style tags must be explicitly enabled
in your php.ini. You examined the php.ini file in Hour 2.
To activate recognition for short tags, you must make sure that the short_open_tag
switch is set to "On" in php.ini:
short_open_tag = On;
Short tags are enabled by default, so you would only need to edit php.ini if you want
to disable these.
To activate recognition for the ASP style tags, you must enable the asp_tags
setting:
asp_tags = On;
After you have edited php.ini, you should be able to choose from any of the four
styles for use in your scripts. This is largely a matter of preference, although if you
intend to work with XML, you should disable the short tags (<? ?>) and work with
the standard tags (<?php ?>).
Let's run through some of the ways in which you can legally write the code in Listing
3.1. You could use any of the four PHP start and end tags that you have seen:
<?
print("Hello Web!");
?>
<?php
print("Hello Web!");
?>
<%
print("Hello Web!");
%>
<SCRIPT LANGUAGE="php">
print("Hello Web!");
</SCRIPT>
Single lines of code in PHP also can be presented on the same line as the PHP start
and end tags: <? print("Hello Web!"); ?>
Now that you know how to define a block of PHP code, take a closer look at the code
in Listing 3.1 itself.

Installing PHP4 for Linux and Apache

In this section, we will look at one way of installing PHP4 with Apache on Linux. The
process is more or less the same for any UNIX operating system. You might be able
to find prebuilt versions of PHP for your system, which are simple to install.
Compiling PHP, though, gives you greater control over the features built in to your
binary.
Before you install you should make sure that you are logged into your system as the
root user. If you are not allowed access to your system's root account, you may
need to ask your system administrator to install PHP for you.
There are two ways of compiling an Apache PHP module. You can either recompile
Apache, statically linking PHP into it, or you can compile PHP as a Dynamic Shared
Object (DSO). If your version of Apache was compiled with DSO support, it will be
capable of supporting new modules without the need for recompiling the server.This method is the easiest way to get PHP up and running, and it is the one we will
look at in this section.
In order to test that Apache supports DSOs you should launch the Apache binary
(httpd) with the -l argument.
/www/bin/httpd -l
You should see a list of modules. If you see
mod_so.c
among them, you should be able to proceed; otherwise, you may need to recompile
Apache. The Apache distribution contains full instructions for this.
If you have not already done so, you will need to download the latest distribution of
PHP4. Your distribution will be archived as a tar file and compressed with gzip, so
you will need to unpack it:
tar -xvzf php-4.0.tar.gz
After your distribution is unpacked, you should move to the PHP4 distribution
directory:
cd ../php-4.0
Within your distribution directory you will find a script called configure. This accepts
arguments that will control the features that PHP will support. For this example, we
will include some useful command line arguments, although you might want to
specify arguments of your own. We will discuss some of the configure options
available to you later in the hour.
./configure --enable-track-vars \
--with-gd \
--with-mysql \
--with-apxs=/www/bin/apxs
The path you assign to the --with-apxs argument is likely to be different on your
system. It is possible that you will find apxs in the same directory as your Apache
executable.
After the configure script has run, you can run the make program. You will need a C
compiler on your system to run this command successfully.
make make install
These commands should end the process of PHP4 compilation and installation. You
should now be able to configure and run Apache.
Some configure Options
When we ran the configure script, we included some command-line arguments
that determined the features that the PHP interpreter will include. The configure
script itself gives you a list of available options. From the PHP distribution directory
type the following:
./configure --help
The list produced is long, so you may want to add it to a file for reading at leisure:
./configure --help > configoptions.txt
Although the output from this command is very descriptive, we will look at a few
useful options— especially those that might be needed to follow this book.
--enable-track-vars
This option automatically populates associative arrays with values submitted as part
of GET, POST requests or provided in a cookie. You can read more about arrays in
Hour 7, "Arrays," and about HTTP requests in Hour 13, "Beyond the Box." It is a
good idea to include this option when running configure.
--with-gd
--with-gd enables support for the GD library, which, if installed on your system,
allows you to create dynamic GIF or PNG images from your scripts. You can read
more about creating dynamic images in Hour 14, "Working with Dynamic Images."
You can optionally specify a path to your GD library's install directory:
--with-gd=/path/to/dir
--with-mysql
--with-mysql enables support for the MySQL database. If your system has MySQL
installed in a directory other than the default location, you should specify a path:
--with-mysql=/path/to/dir
As you know, PHP provides support for other databases. Table 2.1 lists some of
them and the configure options you will need to use them.
Table 2.1: Some Database configure Options
Database configure Option
Adabas D --with-adabas
FilePro --with-filepro
msql --with-msql
informix --with-informix
iODBC --with-iodbc
OpenLink
ODBC
--with-openlink
Oracle --with-oracle
PostgreSQL --with-pgsql
Solid --with-solid
Sybase --with-sybase
Sybase-CT --with-sybase-ct
Velocis --with-velocis
LDAP --with-ldap


Configuring Apache
After you have compiled PHP and Apache, you should check Apache's configuration
file, httpd.conf, which you will find in a directory called conf in the Apache install
directory. Add the following lines to this file:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
This ensures that the PHP interpreter will parse files that end with the .php
extension. Any files with the .phps extension will be output as PHP source. That is,
the source code will be converted to HTML and color-coded. This can be useful for
debugging your scripts.
If you want to offer to your users PHP pages with extensions more familiar to them,
you can choose any extension you want. You can even ensure that files with
the .html extension are treated as PHP files with the following:
AddType application/x-httpd-php .html
Note that treating files with the .html extension as PHP scripts could slow down your
site, because every page with this extension will be parsed by the PHP interpreter
before it is served to the user.
If PHP has been preinstalled and you have no access to the Apache configuration
files, you may be able to change the extensions that will determine which files will
be treated as PHP executables by including an AddType directive in a file
called .htaccess. After you have created this file, the directive will affect the
enclosing directory, as well as any subdirectories. This technique will only work if
the AllowOverride directive for the enclosing directory is set to either FileInfo or All.
Although the filename .htaccess is the default for an access control file, it may have
been changed. Check the AccessFileName directive in httpd.conf to find out. Even if
you don't have root access, you should be able to read the Apache configuration
files.
An .htaccess file can be an excellent way of customizing your server space if you do
not have access to the root account. An additional way of controlling the behavior of
PHP, even as a non-root user, is the php.ini file.


php.ini
After you have compiled or installed PHP, you can still change its behavior with a file
called php.ini. On UNIX systems, the default location for this file is /usr/local/lib;
on a Windows system, the default location is the Windows directory. A php.ini file
in the current working directory will override one in the default location, so you can
change the behavior of PHP on a per-directory basis.
You should find a sample php.ini file in your distribution directory, which contains
factory settings. Factory settings will be used if no php.ini file is used.
The default settings should be adequate for most of the examples in this book,
although you can read about some amendments you might like to make in Hour 22,
"Debugging."
Directives in the php.ini file take the form of a directive and a value separated by an
equals sign. Whitespace is ignored.
If PHP has been preinstalled on your system, you might want to check some of the
settings in php.ini. Remember, if you are not allowed to alter this document, you
can create one in your script's directory that can override the default. You can also
set an environmental variable PHPRC that designates a php.ini file.
You can change your php.ini settings at any time, though if you are running PHP as
an Apache module, you should restart the server for the changes to take effect.
short_open_tag
The short_open_tag directive determines whether you can begin a block of PHP
code with the symbols <? and close it with ?>. If this has been disabled, you will see
one of the following:
short_open_tag = Off
short_open_tag = False
short_open_tag = No
To enable the directive you can use one of the following:
short_open_tag = On
short_open_tag = True
short_open_tag = Yes
You can read more about PHP open and close tags in Hour 3, "A First Script."


Error Reporting Directives
To diagnose bugs in your code, you should enable the directive that allows error
messages to be written to the browser. This is on by default:

Platforms, Servers, Databases, and PHP

PHP is truly cross-platform. It runs on the Windows operating system, most versions
of UNIX including Linux, and even the Macintosh. Support is provided for a range of
Web servers including Apache (itself open source and cross-platform), Microsoft
Internet Information Server, WebSite Pro, the iPlanet Web Server, and Microsoft's
Personal Web Server. The latter is useful if you want to test your scripts offline on a
Windows machine, although Apache can also be run on Windows.
You can also compile PHP as a standalone application. You can then call it from the
command line. In this book, we will concentrate on building Web applications, but
do not underestimate the power of PHP4 as a general scripting tool comparable to
Perl.
PHP is designed to integrate easily with databases. This feature is one of the factors
that make the language such a good choice for building sophisticated Web
applications. Many databases are directly supported, including Adabas D, InterBase,
Solid, dBASE, mSQL, Sybase, Empress, MySQL, Velocis, FilePro, Oracle, UNIX dbm,
Informix, and PostgreSQL. PHP also supports ODBC.
we will be using a combination of Linux, Apache, and MySQL.
All these are free to download and use, and can be installed relatively easily on a PC.
You can find out more about getting Linux for your computer at
<http://www.linux.org/help/beginner/distributions.html>. If you want to run Linux
on a Power PC, you can find information about LinuxPPC at
<http://www.linuxppc.org>.
MySQL, the database we will use, can be downloaded from
<http://www.mysql.com>. There are versions for many operating systems
including UNIX, Windows, and OS/2.
On the other hand, you can easily stick with Windows, NT, or MacOS. PHP is, after
all, a cross-platform scripting language.