<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE rss [<!ENTITY % HTMLlat1 PUBLIC "-//W3C//ENTITIES Latin 1 for XHTML//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent">]>
<rss version="2.0" xml:base="http://www.zentower.com">
<channel>
 <title>Learn PHP - Learning PHP</title>
 <link>http://www.zentower.com</link>
 <description>PHP in easy steps.</description>
 <language>en</language>
<item>
 <title>Blog Script</title>
 <link>http://www.zentower.com/node/19</link>
 <description>&lt;p&gt;The first step will be to setup a table , &quot;blog&quot;.
&lt;p&gt;You can dump the structure from blog.sql into your phpMyAdmin if you use it.
&lt;p&gt;
CREATE TABLE blog (&lt;br&gt;&lt;br /&gt;
id mediumint(5) NOT NULL auto_increment,&lt;br&gt;&lt;br /&gt;
title varchar(50) NOT NULL,&lt;br&gt;&lt;br /&gt;
name varchar(50) NOT NULL,&lt;br&gt;&lt;br /&gt;
email varchar(50) NOT NULL,&lt;br&gt;&lt;br /&gt;
date datetime NOT NULL,&lt;br&gt;&lt;br /&gt;
icon varchar(255),&lt;br&gt;&lt;br /&gt;
entry text NOT NULL,&lt;br&gt;&lt;br /&gt;
PRIMARY KEY (ID)&lt;br&gt;&lt;br /&gt;
);&lt;br&gt;&lt;/p&gt;
&lt;p&gt;&lt;br&gt; This will create the tables required in the MySQL database.
&lt;p&gt;For simplicity, the variables have been named accordingly to their usage:
&lt;p&gt;
   1. title : field that holds the entry title.&lt;br&gt;&lt;br /&gt;
   2. name : field that holds the name of the author.&lt;br&gt;&lt;br /&gt;
   3. email : email of the author.&lt;br&gt;&lt;br /&gt;
   4. date : date of entry&lt;br&gt;&lt;br /&gt;
   5. icon : field that holds path to the icon image.&lt;br&gt;&lt;br /&gt;
   6. entry : field that holds the blog entry&lt;br&gt;&lt;/p&gt;
&lt;p&gt;define.php - connection to mysql file:
&lt;p&gt;
&amp;lt;?php&lt;br&gt;&lt;br /&gt;
   $dbsrv = &quot;localhost&quot;;&lt;br&gt;&lt;br /&gt;
   $db = &quot;blog_db&quot;;&lt;br&gt;&lt;br /&gt;
   $user = &quot;root&quot;;&lt;br&gt;&lt;br /&gt;
   $user_password =&quot;root&quot;;&lt;br&gt;&lt;br /&gt;
$dblnk = mysql_connect($dbsrv,$user,$user_password);&lt;br&gt;&lt;br /&gt;
$rez = mysql_select_db($db, $dblnk);&lt;br&gt;&lt;br /&gt;
?&amp;gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;&lt;u&gt;blog_entry.html&lt;/u&gt; . Next file , is a simple html file blog_entry.html , no php code is required for it .&lt;br /&gt;
It is a form that will enable us to fill blog entries.   To minimize programming errors I named the form variables exactly as in mysql table.
&lt;p&gt;
&amp;lt;form action=&quot;submit.php&quot; method=&quot;post&quot;&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;table width=&quot;130&quot; border=&quot;0&quot; cellspacing=&quot;1&quot; cellpadding=&quot;0&quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;td height=&quot;23&quot; colspan=&quot;2&quot;&amp;gt;&amp;lt;b&amp;gt;Blog Entry Form&amp;lt;/b&amp;gt;&amp;lt;/td&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;td&amp;gt;Name:&amp;lt;/td&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;input type=&quot;text&quot; name=&quot;name&quot; size=&quot;30&quot;&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;td height=&quot;25&quot;&amp;gt;Email:&amp;lt;/td&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;td height=&quot;25&quot;&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;input type=&quot;text&quot; name=&quot;email&quot; size=&quot;30&quot;&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;td height=&quot;25&quot;&amp;gt;Title:&amp;lt;/td&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;td height=&quot;25&quot;&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;input type=&quot;text&quot; name=&quot;title&quot; size=&quot;30&quot;&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;td height=&quot;25&quot;&amp;gt;Icon:&amp;lt;/td&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;td height=&quot;25&quot;&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;input type=&quot;text&quot; name=&quot;icon&quot; size=&quot;30&quot;&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;td height=&quot;25&quot;&amp;gt;Entry:&amp;lt;/td&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;td height=&quot;25&quot;&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;textarea name=&quot;entry&quot; cols=&quot;30&quot; rows=&quot;5&quot;&amp;gt;&amp;lt;/textarea&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td colspan=2&amp;gt;&amp;lt;input type=&quot;submit&quot; value=&quot;submit&quot;&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;/form&amp;gt;&lt;br&gt;
&lt;p&gt;Even this file doesn&#039;t require php code , the action of the form will call submit.php . That means when the form is submitted all variables are sent to submit.php using  POST method.&lt;/p&gt;
&lt;p&gt;&lt;u&gt;submit.php&lt;/u&gt; . Submit.php includes &quot;define.php&quot; , database connection file . Then it parses the variables sent using POST method and it checks if the user sent&lt;br /&gt;
blank fields. If everything is ok , the values submitted are inserted into the database and a success message is displayed .&lt;/p&gt;
&lt;p&gt;
&amp;lt;?php &lt;br&gt;&lt;br /&gt;
include (&quot;define.php&quot;);&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
$name = $_POST[&quot;name&quot;];&lt;br&gt;&lt;br /&gt;
$email = $_POST[&quot;email&quot;];&lt;br&gt;&lt;br /&gt;
$entry = $_POST[&quot;entry&quot;];&lt;br&gt;&lt;br /&gt;
$title = $_POST[&quot;title&quot;];&lt;br&gt;&lt;br /&gt;
$icon = $_POST[&quot;icon&quot;];&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
// Check if user submit blank entry&lt;br&gt;&lt;br /&gt;
if ($name == &quot;&quot; || $email == &quot;&quot; || $entry == &quot;&quot; || $title == &quot;&quot;)&lt;br&gt;&lt;br /&gt;
{&lt;br&gt;&lt;br /&gt;
    die (&quot;You must fill in all fields, please click back and try again.&quot;);&lt;br&gt;&lt;br /&gt;
}&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
else {&lt;br&gt;&lt;br /&gt;
    $q=&quot;insert into blog (id,name,title,email,entry,date,icon) VALUES (&#039;&#039;,&#039;$name&#039;,&#039;$title&#039;,&#039;$email&#039;,&#039;$entry&#039;,now(),&#039;$icon&#039;)&quot;;&lt;br&gt;&lt;br /&gt;
    $result = mysql_query($q,$dblnk);&lt;br&gt;&lt;br /&gt;
    &lt;br&gt;&lt;br /&gt;
    if ($result)&lt;br&gt;&lt;br /&gt;
    {&lt;br&gt;&lt;br /&gt;
        echo &quot;thank you, blog has been submitted.&quot;;&lt;br&gt;&lt;br /&gt;
    }&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
}&lt;br&gt;&lt;br /&gt;
?&amp;gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;&lt;u&gt;display.php&lt;/u&gt; The last step is to display the blog. First we must decide how many entries to display per page and how you want them to display.
&lt;p&gt;
&amp;lt;?php&lt;br&gt;&lt;br /&gt;
include (&quot;define.php&quot;);&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
$q = &quot;select * from blog order by date desc &quot;;&lt;br&gt;&lt;br /&gt;
$result= mysql_query($q, $dblnk) or die&lt;br&gt;&lt;br /&gt;
(&quot;Could not execute query : $q.&quot; . mysql_error());&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
// dynamic navigation variables&lt;br&gt;&lt;br /&gt;
$rows_per_page=1; // adjust the number here to display number of entries per page&lt;br&gt;&lt;br /&gt;
$total_records=mysql_num_rows($result);&lt;br&gt;&lt;br /&gt;
$pages = ceil($total_records / $rows_per_page);&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
$screen = $_GET[&quot;screen&quot;];&lt;br&gt;&lt;br /&gt;
if (!isset($screen))&lt;br&gt;&lt;br /&gt;
$screen=0;&lt;br&gt;&lt;br /&gt;
$start = $screen * $rows_per_page;&lt;br&gt;&lt;br /&gt;
$q .= &quot;LIMIT $start, $rows_per_page&quot;;&lt;br&gt;&lt;br /&gt;
$result= mysql_query($q, $dblnk) or die&lt;br&gt;&lt;br /&gt;
(&quot;Could not execute query : $q.&quot; . mysql_error());&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
while ($row=mysql_fetch_array($result))&lt;br&gt;&lt;br /&gt;
{&lt;br&gt;&lt;br /&gt;
    $id=$row[&quot;id&quot;];&lt;br&gt;&lt;br /&gt;
    $name=$row[&quot;name&quot;];&lt;br&gt;&lt;br /&gt;
    $email=$row[&quot;email&quot;];&lt;br&gt;&lt;br /&gt;
    $entry=$row[&quot;entry&quot;];&lt;br&gt;&lt;br /&gt;
    $date=$row[&quot;date&quot;];&lt;br&gt;&lt;br /&gt;
    $icon=$row[&quot;icon&quot;];&lt;br&gt;&lt;br /&gt;
    $title=$row[&quot;title&quot;];&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
?&amp;gt;&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
    &amp;lt;table width=&quot;80%&quot; border=&quot;0&quot; cellspacing=&quot;1&quot; cellpadding=&quot;0&quot;&amp;gt;&lt;br&gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br&gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;?php echo &quot;$title&quot;; ?&amp;gt;&amp;lt;/td&amp;gt;&lt;br&gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br&gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br&gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&lt;br&gt;&lt;br /&gt;
    &amp;lt;p&amp;gt;&amp;lt;img src=&quot;&amp;lt;?php echo &quot;$icon&quot;; ?&amp;gt;&quot; alt=&quot;icon&quot; align=&quot;left&quot;&amp;gt;&amp;lt;?php echo &quot;$entry&quot;; ?&amp;gt;&amp;lt;/p&amp;gt;&lt;br&gt;&lt;br /&gt;
    &amp;lt;p&amp;gt;Posted by &amp;lt;a href=&quot;mailto:&amp;lt;?php echo &quot;$email&quot;; ?&amp;gt;&quot;&amp;gt;&amp;lt;?php echo &quot;$name&quot;; ?&amp;gt; on &amp;lt;?php echo &quot;$date&quot;; ?&amp;gt;.&amp;lt;/p&amp;gt;&lt;br&gt;&lt;br /&gt;
    &amp;lt;/td&amp;gt;&lt;br&gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br&gt;&lt;br /&gt;
    &amp;lt;/table&amp;gt;&lt;br&gt;&lt;br /&gt;
    &lt;br&gt;&lt;br /&gt;
    &amp;lt;div align=&quot;center&quot;&amp;gt;&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
&amp;lt;?php&lt;br&gt;&lt;br /&gt;
} #end of while&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
if ($screen &amp;gt; 0) {&lt;br&gt;&lt;br /&gt;
    $j = $screen - 1;&lt;br&gt;&lt;br /&gt;
    $url = &quot;display.php?screen=$j&quot;;&lt;br&gt;&lt;br /&gt;
    echo &quot;&amp;lt;a href=\&quot;$url\&quot;&amp;gt;Prev&amp;lt;/a&amp;gt;&quot;;&lt;br&gt;&lt;br /&gt;
}&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
// page numbering links now&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
for ($i = 0; $i &amp;lt; $pages; $i++) {&lt;br&gt;&lt;br /&gt;
    $url = &quot;display.php?screen=&quot; . $i;&lt;br&gt;&lt;br /&gt;
    $j = $i + 1;&lt;br&gt;&lt;br /&gt;
    echo &quot; | &amp;lt;a href=\&quot;$url\&quot;&amp;gt;$j&amp;lt;/a&amp;gt; | &quot;;&lt;br&gt;&lt;br /&gt;
}&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
if ($screen &amp;lt; $pages-1) {&lt;br&gt;&lt;br /&gt;
    $j = $screen + 1;&lt;br&gt;&lt;br /&gt;
    $url = &quot;display.php?screen=$j&quot;;&lt;br&gt;&lt;br /&gt;
    echo &quot;&amp;lt;a href=\&quot;$url\&quot;&amp;gt;Next&amp;lt;/a&amp;gt;&quot;;&lt;br&gt;&lt;br /&gt;
}&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
?&amp;gt;&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
&amp;lt;/div&amp;gt; &lt;br&gt;&lt;br /&gt;
&lt;br&gt;
&lt;p&gt;Code used in display.php will display 1 record per page and it will use tables to display the records.&lt;/p&gt;
&lt;p&gt;Line 4-6 , database query to obtain all existing records in database . This number will be used to obtain the number of pages  by dividing the total number of records to number of records per page (line 11). Number of records per page can be easily modified , because it is determined by the value of variable $rows_per_page from line 9.&lt;/p&gt;
&lt;p&gt;For paging control we&#039;ll use variable screen that will be sent in url and it will determine which page it is displayed.&lt;br /&gt;
&lt;br&gt;Since it is sent in url , it will be obtain using GET , $screen = $_GET[&quot;screen&quot;]; &lt;/p&gt;
&lt;p&gt;If this variable has no content it means we are on the first page so it will be assigned by default value zero.&lt;/p&gt;
&lt;p&gt;Depending on which page we are we will use sql option LIMIT using as start record  variable start calculated using page number and number of rows per page, and&lt;br /&gt;
as number of records needed variable $rows_per_page.&lt;/p&gt;
&lt;p&gt;If there is no mysql error variables corresponding to mysql fields are initialized.&lt;/p&gt;
&lt;p&gt;Then a html table is created in order to display the records in an organized style.&lt;/p&gt;
&lt;p&gt;The last part of this script is where the paging algorithm is implemented. There will be displayed links to previous and next page (if any).&lt;/p&gt;
&lt;p&gt;If variable screen has a value greater than zero it means we are not on the first page so at least one previous page must exist . So a &quot;previous&quot; link will be displayed.&lt;br /&gt;
Variable screen will be decreased by 1 when when sent in url . &lt;/p&gt;
&lt;p&gt;Then we&#039;ll use a loop to display all existing pages , and another for loop to display the &quot;next&quot; link . Note , the counter used to display&lt;br /&gt;
the &quot;next&quot; link goes only to $screen-1 since the last page won&#039;t have a &quot;next&quot; link.&lt;/p&gt;
&lt;p&gt;This a basic blog script that can be easily modified adding/removing fields from the initial blog_entry.html file . Of course, these fields should be added in a database as well.&lt;/p&gt;
</description>
 <enclosure url="http://www.zentower.com/files/blog_files.zip" length="2367" type="application/x-zip-compressed" />
 <pubDate>Thu, 07 Jul 2005 11:09:55 -0500</pubDate>
</item>
<item>
 <title>Counter files</title>
 <link>http://www.zentower.com/node/18</link>
 <description>&lt;p&gt;A counter is an essential part of a site to know how many people are coming to site.
&lt;p&gt;The first step is to create the counter table .
&lt;p&gt;You can dump the structure from counter.sql into your phpMyAdmin if you use it.This is going to create a small table to store hits for each page it counts.
&lt;p&gt;
-- Table structure for table counter&lt;br&gt;&lt;br /&gt;
-- &lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
CREATE TABLE `counter` (&lt;br&gt;&lt;br /&gt;
  `id` int(11) NOT NULL auto_increment,&lt;br&gt;&lt;br /&gt;
  `page` text NOT NULL ,&lt;br&gt;&lt;br /&gt;
   PRIMARY KEY  (`id`)&lt;br&gt;&lt;br /&gt;
) &lt;br&gt;&lt;/p&gt;
&lt;p&gt;Once your table is setup, we&#039;ll begin building the counter.&lt;/p&gt;
&lt;p&gt;code.php contains the code that needs to be place on each page that needs the counter.
&lt;p&gt;
&amp;lt;?php&lt;br&gt;&lt;br /&gt;
   $dbsrv = &quot;localhost&quot;;&lt;br&gt;&lt;br /&gt;
   $db = &quot;counter_db&quot;;&lt;br&gt;&lt;br /&gt;
   $user = &quot;root&quot;;&lt;br&gt;&lt;br /&gt;
   $user_password =&quot;root&quot;;&lt;br&gt;&lt;br /&gt;
$dblnk = mysql_connect($dbsrv,$user,$user_password);&lt;br&gt;&lt;br /&gt;
$rez = mysql_select_db($db, $dblnk);&lt;br&gt;&lt;br /&gt;
?&amp;gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;In code.php we must include &quot;define.php&quot;. &lt;p&gt;
It contains the database name, server name, username and password . A connection to the database will be established within this file.
&lt;p&gt;It will be included in all files that will use a database connection . If you modify any of these variables like username or password you won&#039;t have to modify each file where you have a database connection , only this file , define.php . Of course, it is possible to place the connection string within each file instead of using the include directive, but when you will need to modify a variable you will have to find and modify each line where you use a database connection.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;code.php&lt;/b&gt;:
&lt;p&gt;
&amp;lt;?&lt;br&gt;&lt;br /&gt;
include (&quot;define.php&quot;);&lt;br&gt;&lt;br /&gt;
$page = $_SERVER[&#039;REQUEST_URI&#039;];&lt;br&gt;&lt;br /&gt;
$sql = &quot;INSERT INTO counter(page) values (&#039;$page&#039;)&quot;;&lt;br&gt;&lt;br /&gt;
$rez =mysql_query($sql,$dblnk);&lt;br&gt;&lt;br /&gt;
$query = &quot;SELECT count(*) as page_hits FROM counter WHERE page=&#039;$page&#039;&quot;;&lt;br&gt;&lt;br /&gt;
$sql = mysql_query($query);&lt;br&gt;&lt;br /&gt;
$array = mysql_fetch_array($sql);&lt;br&gt;&lt;br /&gt;
$hits = $array[page_hits];&lt;br&gt;&lt;br /&gt;
print &quot;This Page Has Had $hits Views&quot;;&lt;br&gt;&lt;br /&gt;
?&amp;gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;Variable $page is initialized using page&#039;s URI .Then, this values is inserted into the database (line 4).
&lt;p&gt;Now we can display the counter using a simple query . The sql query will return the number of hits for the page where we are located (line 14)&lt;br /&gt;
.
&lt;p&gt;Now the number of hits can be displayed. Everytime the page is refreshed a new record will be inserted into the database and the counter is incremented.&lt;/p&gt;
</description>
 <enclosure url="http://www.zentower.com/files/counter_files.zip" length="998" type="application/x-zip-compressed" />
 <pubDate>Thu, 07 Jul 2005 11:09:13 -0500</pubDate>
</item>
<item>
 <title>Login Script</title>
 <link>http://www.zentower.com/node/17</link>
 <description>&lt;p&gt;
Login script is a very common requirement of many websites. How to create one login script ? There are three steps involved in developing a login script.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;First asking user or member to login using a form.
&lt;li&gt;Then checking the entered information with one existing table of a database.
&lt;li&gt;Allowing the member to enter into restricted area based on successful login.
&lt;/ol&gt;
&lt;p&gt;
We will assume that our data member are stored into a mysql database.
&lt;p&gt;There are 4 files define.php , func.php , logadm.php and main.php .
&lt;p&gt;Short description :&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;define.php contains the database name, server name, username and password . A connection to the database will be established within this file.
&lt;p&gt;It will be included in all files that will use a database connection . If you modify any of these variables like username or password you won&#039;t have to modify each file&lt;br /&gt;
where you have a database connection , only this file , define.php . &lt;p&gt;Of course, it is possible to place the connection string within each file instead of using the include&lt;br /&gt;
directive , but when you will need to modify a variable you will have to find and modify each line where you use a database connection.
&lt;p&gt;Usually server name it is localhost if mysql server resides on the same server as the web server . If not , your web hosting company will give you the exact details.
&lt;p&gt;Line 6 and 7 are the most important as they realise the connection to the database server and then select the actual database.
&lt;p&gt;If this operation it is successful you will be able to use the database for any needed operation like insert , update , delete .
&lt;p&gt;The variable used will be $dblnk - this is the link to the database.
&lt;p&gt;
&amp;lt;?php&lt;br&gt;&lt;br /&gt;
   $dbsrv = &quot;localhost&quot;;&lt;br&gt;&lt;br /&gt;
   $db = &quot;login&quot;;&lt;br&gt;&lt;br /&gt;
   $user = &quot;root&quot;;&lt;br&gt;&lt;br /&gt;
   $user_password =&quot;root&quot;;&lt;br&gt;&lt;br /&gt;
$dblnk = mysql_connect($dbsrv,$user,$user_password);&lt;br&gt;&lt;br /&gt;
$rez = mysql_select_db($db, $dblnk);&lt;br&gt;&lt;br /&gt;
?&amp;gt;&lt;/p&gt;
&lt;li&gt;func.php . This file will keep the functions used . It will include &quot;define.php&quot; as we need to connect to the database .&lt;br /&gt;
In this case , the application being fairly simple there will be only one function , auth_adm that will check if the information&lt;br /&gt;
entered by users exists into the database .&lt;/p&gt;
&lt;p&gt;The function auth_adm will receive to input parameters , $uname and $upass . These are the username and the password entered by user.&lt;/p&gt;
&lt;p&gt;As the function code begins variable $dblnk, the database connection , will have to be declared as global in order to be accessible inside the function. This aspect is important because it is not declared as global you will receive an error that you can&#039;t connect to mysql.&lt;/p&gt;
&lt;p&gt;As you remember variables declared outside a function are not visible inside a function unless they are declared as global or sent as function parameters.&lt;/p&gt;
&lt;p&gt;In this case we sent as function parameters the username and user password.&lt;/p&gt;
&lt;p&gt;This file will have to be included in each file that is using any of the functions from this file.
&lt;p&gt;
&amp;lt;?php&lt;br&gt;&lt;br /&gt;
include (&quot;define.php&quot;);&lt;br&gt;&lt;br /&gt;
function auth_adm($uname, $upass)&lt;br&gt;&lt;br /&gt;
{&lt;br&gt;&lt;br /&gt;
global $dblnk;&lt;br&gt;&lt;br /&gt;
$sql=&quot;select id from admin where uname=&#039;$uname&#039; and pass=&#039;$upass&#039;&quot;;&lt;br&gt;&lt;br /&gt;
$rez=mysql_query($sql,$dblnk);//echo $rez;&lt;br&gt;&lt;br /&gt;
$nr=mysql_num_rows($rez);&lt;br&gt;&lt;br /&gt;
$row=mysql_fetch_array($rez);&lt;br&gt;&lt;br /&gt;
$ok=$row[&#039;id&#039;];&lt;br&gt;&lt;br /&gt;
return $ok;&lt;br&gt;&lt;br /&gt;
} //end auth&lt;br&gt;&lt;br /&gt;
?&amp;gt;&lt;br&gt;&lt;/p&gt;
&lt;li&gt;logadm.php . This is the actual html form where users input their username and password.
&lt;p&gt; First , the script checks if the form was submitted or not (line 2) . If the form wasn&#039;t submitted the actual html form is displayed. When user clicks submit , after entering the username and password , the session variables &quot;tname&quot; and &quot;tpass&quot; are registered .Then the username and password entered by user are attributed to these variables. As stated in &lt;a href=&quot;node/16&quot;&gt;sessions&lt;/a&gt; tutorial these variables will be available in all pages where they are registered.
&lt;p&gt;
After the variables are registered the page is redirected to main_page.php . This is the main page of the script.
&lt;p&gt;&amp;lt;?php&lt;br&gt;&lt;br /&gt;
if (!isset($uname))&lt;br&gt;&lt;br /&gt;
{&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
	echo &quot;&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
	&amp;lt;FORM action=logadm.php method=post&amp;gt;&lt;br&gt;&lt;br /&gt;
	&amp;lt;title&amp;gt; Login&amp;lt;/title&amp;gt;&lt;br&gt;&lt;br /&gt;
	&amp;lt;H2 align=center&amp;gt;Administrator Login&amp;lt;/H2&amp;gt;&lt;br&gt;&lt;br /&gt;
	&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br /&gt;
	&amp;lt;TABLE align=center&amp;gt;&lt;br&gt;&lt;br /&gt;
	&amp;lt;TR&amp;gt;&lt;br&gt;&lt;br /&gt;
		&amp;lt;TD&amp;gt;Login name:&amp;lt;/TD&amp;gt;&lt;br&gt;&lt;br /&gt;
		&amp;lt;TD&amp;gt;&amp;lt;INPUT name=uname&amp;gt;&amp;lt;/TD&amp;gt;&lt;br&gt;&lt;br /&gt;
	&amp;lt;/TR&amp;gt;&lt;br&gt;&lt;br /&gt;
	&amp;lt;TR&amp;gt;&lt;br&gt;&lt;br /&gt;
		&amp;lt;TD&amp;gt;Login password:&amp;lt;/TD&amp;gt;&lt;br&gt;&lt;br /&gt;
		&amp;lt;TD&amp;gt;&amp;lt;INPUT name=upass type=password&amp;gt;&amp;lt;/TD&amp;gt;&lt;br&gt;&lt;br /&gt;
	&amp;lt;/TR&amp;gt;&lt;br&gt;&lt;br /&gt;
	&amp;lt;/TABLE&amp;gt;&lt;br&gt;&lt;br /&gt;
	&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br /&gt;
	&amp;lt;P align=center&amp;gt;&amp;lt;INPUT class=button type=submit value=Login&amp;gt;&amp;nbsp;&amp;nbsp; &amp;lt;INPUT class=button type=reset value=Reset&amp;gt;&amp;lt;/P&amp;gt;&lt;br&gt;&lt;br /&gt;
	&amp;lt;/FORM&amp;gt;&quot;;&lt;br&gt;&lt;br /&gt;
}&lt;br&gt;&lt;br /&gt;
else&lt;br&gt;&lt;br /&gt;
{&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
session_register(&quot;tname&quot;);&lt;br&gt;&lt;br /&gt;
session_register(&quot;tpass&quot;);&lt;br&gt;&lt;br /&gt;
$tname = $uname;&lt;br&gt;&lt;br /&gt;
$tpass = $upass;&lt;br&gt;&lt;br /&gt;
?&amp;gt;&lt;br&gt;&lt;br /&gt;
             &amp;lt;script language=&quot;javascript&quot;&amp;gt;location.href=&#039;./main_page.php&#039;&amp;lt;/script&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;?&lt;br&gt;&lt;br /&gt;
die (&quot; &quot;)   ;&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
}&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
?&amp;gt;&lt;br&gt;&lt;/p&gt;
&lt;li&gt;main_page.php . In this page , like in all pages that needs secure access , the username and password entered previousely are checked against the database.&lt;br /&gt;
In order to use the values entered by users and previousely saved using session variables the session_register() directive must be use.&lt;br /&gt;
This way the browser will be aware of the variable names .
&lt;p&gt; The next line includes func.php file described above. It is called using username and password entered by user (saved in session variables).
&lt;p&gt;If the function returns TRUE , the script it is executed. If it returns FALSE the script is halted and an error message is displayed.
&lt;p&gt;&amp;lt;?php&lt;br&gt;&lt;br /&gt;
session_register(&quot;tname&quot;);&lt;br&gt;&lt;br /&gt;
session_register(&quot;tpass&quot;);&lt;br&gt;&lt;br /&gt;
include(&quot;func.php&quot;);&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
if (!auth_adm($tname, $tpass))&lt;br&gt;&lt;br /&gt;
   die(&quot;Incorrect Username/Password.Please &amp;lt;a href=./logadm.php&amp;gt;login&amp;lt;/a&amp;gt;.&quot;);&lt;br&gt;&lt;br /&gt;
else&lt;br&gt;&lt;br /&gt;
{&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
?&amp;gt;&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
Main page text....&lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
&amp;lt;?&lt;br&gt;&lt;br /&gt;
}&lt;br&gt;&lt;br /&gt;
?&amp;gt;&lt;br&gt;&lt;/p&gt;
&lt;li&gt;admin.sql . In order to be completely functional , a database must be create and a username and password inserted into the table.&lt;br /&gt;
You can dump the structure from admin.sql into your phpMyAdmin if you use it.
&lt;p&gt;
-- Table structure for table `admin`&lt;br&gt;&lt;br /&gt;
-- &lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
CREATE TABLE `admin` (&lt;br&gt;&lt;br /&gt;
  `id` int(11) NOT NULL auto_increment,&lt;br&gt;&lt;br /&gt;
  `uname` text NOT NULL,&lt;br&gt;&lt;br /&gt;
  `pass` text NOT NULL,&lt;br&gt;&lt;br /&gt;
  PRIMARY KEY  (`id`)&lt;br&gt;&lt;br /&gt;
) &lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
-- &lt;br&gt;&lt;br /&gt;
-- Dumping data for table `admin`&lt;br&gt;&lt;br /&gt;
-- &lt;br&gt;&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
INSERT INTO `admin` VALUES (1, &#039;admin&#039;, &#039;admin&#039;);&lt;br&gt;&lt;/p&gt;
&lt;/ul&gt;
&lt;p&gt;Note : 1.The script to be protected should be place only inside the test if the authentication is successful.
&lt;p&gt;2.On each page that has to be protected the most important lines are session_register lines and the authentication call function.&lt;/p&gt;
</description>
 <enclosure url="http://www.zentower.com/files/login_files.zip" length="1787" type="application/x-zip-compressed" />
 <pubDate>Thu, 07 Jul 2005 11:08:41 -0500</pubDate>
</item>
<item>
 <title>Sessions</title>
 <link>http://www.zentower.com/node/16</link>
 <description>&lt;p&gt;Sessions, which were integrated into PHP in version 4 of the language, are a means to store and track data for a user while they travel through a series of pages, or page iterations, on your site.
&lt;p&gt;Session data is stored on the server , unlike cookies, stored on client&#039;s machine . Therefore sessions are secure whilst cookies can be easily altered , and no information is&lt;br /&gt;
exchanged between client and server so it can&#039;t be intercepted.
&lt;p&gt;Sessions in PHP are started by using the session_start( ) function. The session_start( ) function must come before any HTML, including blank lines, on the page.  It will look like this:
&lt;p&gt;
&amp;lt;?php &lt;br&gt;&lt;br /&gt;
session_start( );&lt;br&gt;&lt;br /&gt;
?&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br&gt;&lt;br /&gt;
&amp;lt;head&amp;gt; ....... etc&lt;br&gt;
&lt;p&gt;The session_start( ) function generates a random Session Id.Having established a session, you can now create, store and retrieve information pertaining to that session.  You might want, for example, to keep track of items in your visitor&#039;s shopping cart.  Information for sessions is stored in a special directory on the server; the path of that directory is specified in the server&#039;s PHP configuration files.
&lt;p&gt;Information to be stored for a session is kept in session variables.  Session variables are created by registering them for the session, using the session_register( ) function.  To use that information (on any page iteration in the session) you simply reference the variable just like you would any other variable. &lt;/p&gt;
</description>
 <pubDate>Thu, 07 Jul 2005 09:43:14 -0500</pubDate>
</item>
<item>
 <title>Databases</title>
 <link>http://www.zentower.com/node/15</link>
 <description>&lt;p&gt;Adding a database to a website can provide the means for great dynamic content, all kinds of user interactivity .&lt;/p&gt;
&lt;p&gt;A database is a collection of data that is stored independently of the manner in which you collect it or may wish to retrieve it.
&lt;p&gt;For example, an address book.
&lt;p&gt;Typically, databases store information in tables.  Tables organize data into rows and columns.  Each row represents a single record, such as one name and address.  Each column holds a part of the record, such as a first name, or a phone number.  With such an arrangement records could be rapidly resorted based on the values found in any column (or combination of columns) just like you can in a spreadsheet program.
&lt;p&gt;Imagine a table that holds lots of names and cities , phone number etc.
&lt;p&gt;
Now imagine another table that holds information about lots of cars, including manufacturers .
&lt;p&gt;
Now imagine that each car record is linked to the name  of the car&#039;s owner .
&lt;p&gt;
With these links in place it would be easy to use our sort/retrieve mechanism to provide a list of people in NY that own a Ford .&lt;br /&gt;
Extracting information from a database in this way is known as querying the database.
&lt;p&gt;The most widely used database with PHP is Mysql (which is also free).
&lt;p&gt; Most common database operations are  create, drop , insert , update ,select .
&lt;p&gt;The first thing you&#039;ll want to do is to create a database . That can be easily do using phpmyadmin or another similar tool.
&lt;p&gt;Then you have to establish a connection to your MySQL database server.  This is accomplished with the mysql_connect function. Here&#039;s an example:
&lt;p&gt;
$conn = mysql_connect (&#039;servername&#039; , &#039;username&#039; , &#039;password&#039;);&lt;br /&gt;
&lt;br&gt;$conn is an identifier (a positive integer, returned by the mysql_connect function) that identifies this connection and is used in subsequent function calls to tie those calls to this connection.  The mysql_connect function is provided three parameters, the name of the server (commonly &#039;localhost&#039; when the server is on the same computer as PHP), the username and password authorized to access the server.
&lt;p&gt;Next, we need to check that the connection was successfully established.  For the sake of this example we are going to print a message on the screen to let us know of whether or not the call was good.  In practice, you will probably take a different course of action .
&lt;p&gt;Another common real world practice is to use the die function to terminate the program and display a message.&lt;br /&gt;
&lt;br&gt;$conn = @mysql_connect (&#039;servername&#039; , &#039;username&#039; , &#039;password&#039;) or die(&quot;Connection to the DBMS server failed&quot;);
&lt;p&gt;to select a MySQL database in PHP use the mysql_select_db ( ) function, like this:&lt;br /&gt;
mysql_select_db (&quot;mydatabase&quot;);
&lt;p&gt;Now that we are connected to the server and selected a database we can run queries.
&lt;p&gt; Let&#039;s say we have a table named Info having the followinf fields : name, address, email and we want to display all records.
&lt;p&gt;$sql=&quot;select * from Info&quot;;
&lt;p&gt;We have stored the sql create query in a variable $query and we will pass this as a parameter to the function like below.&lt;br /&gt;
&lt;br&gt; $rez=mysql_query($sql,$conn);
&lt;p&gt;The above command will execute the query ( stored in variable $sql) and we can check the status of the query ( successful or not ) by checking the status of $rez. $rez will be true of the query is successfully executed or it will return false.
&lt;p&gt;If the result was true we must use variable $rez to populate an array with matching records. Each field can be accessed using array name and field name from database as index.
&lt;p&gt;while($row=mysql_fetch_array($rez))&lt;br&gt;&lt;br /&gt;
{&lt;br&gt;&lt;br /&gt;
	echo $row[&#039;name&#039;];&lt;br&gt;&lt;/p&gt;
&lt;p&gt;}&lt;br&gt;&lt;/p&gt;
</description>
 <pubDate>Thu, 07 Jul 2005 09:41:00 -0500</pubDate>
</item>
<item>
 <title>PHP FORMS</title>
 <link>http://www.zentower.com/node/14</link>
 <description>&lt;p&gt;Setting up a form for use with a PHP script is exactly the same as normal in HTML. Most forms are used to gather information like in a signup form, survey or guestbook.
&lt;p&gt;The most important thing to notice when dealing with HTML forms and PHP is that any form element in an HTML page will automatically be available to your PHP scripts.
&lt;p&gt; All the elements for your form must be enclosed in the&lt;br /&gt;
&lt;form&gt; tags. A form can have the method set as post or get. When using a form with method=&quot;post&quot; you can use $_POST to access the form values. And when the form is using method=&quot;get&quot; you can use $_GET to access the values. The $_REQUEST superglobal can be used to to access form values with method=&quot;post&quot; and method=&quot;get&quot; but it is recommended to use $_POST or $_GET instead so you will know from what method did the values come from.&lt;/p&gt;
&lt;p&gt;Here is an example of HTML form :&lt;br /&gt;
&lt;form action=&quot;process.php&quot; method=&quot;post&quot;&gt;&lt;br&gt;&lt;br /&gt;
&lt;input type=&quot;text&quot; name=&quot;thebox&quot; value=&quot;Your Name&quot;&gt;&lt;br&gt;&lt;br /&gt;
&lt;textarea name=&quot;message&quot;&gt;&lt;br /&gt;
Please write your message here.&lt;/textarea&gt;&lt;br&gt;&lt;br /&gt;
&lt;input type=&quot;submit&quot; value=&quot;Submit&quot;&gt;&lt;br /&gt;
&lt;/form&gt;
&lt;p&gt; Note : It really makes no difference if you use POST or GET as method but it is normally better to use POST if you are using passwords or sensitive information as they should not be shown in the browser&#039;s address bar.
&lt;p&gt; We used the following line to define the action file (process.php) and action method (post)
&lt;p&gt;
&amp;lt;form action=&quot;process.php&quot; method=&quot;post&quot;&amp;gt;
&lt;p&gt;After submitting the form the  next step is to get the data the form has submitted into your script so that you can do something with it.
&lt;p&gt;To get a variable which has been sent to a script using the POST method you use the following code:
&lt;p&gt;$variablename=$_POST[&#039;variable&#039;];&lt;br /&gt;
&lt;br&gt;which basically takes the variable from the POST (the name of a form field) and assigns it to the variable $variablename.&lt;/p&gt;
&lt;p&gt;&lt;br&gt;Similarly, if you are using the GET method you should use the form:&lt;br /&gt;
&lt;br&gt;$variablename=$_GET[&#039;variable&#039;];&lt;/p&gt;
&lt;p&gt;This should be done for each variable you wish to use from your form (or URL).&lt;/p&gt;
</description>
 <pubDate>Thu, 07 Jul 2005 09:37:22 -0500</pubDate>
</item>
<item>
 <title>Strings</title>
 <link>http://www.zentower.com/node/13</link>
 <description>&lt;p&gt;
The management of strings is very important in any programming language;&lt;br /&gt;
there are several functions to manage strings, following is an explanation of the most widely used.
&lt;p&gt;
Strings can be created using single-quotes and double-quotes .&lt;br /&gt;
&lt;br&gt;For example , both versions are correct and they produce the same result : &lt;br&gt;&lt;/p&gt;
&lt;p&gt;$string1 = &quot;This is a test&quot;;&lt;br&gt;&lt;br /&gt;
$string2 =  &#039;This is a test&#039;;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;A string can be displayed using echo : &lt;br&gt;&lt;/p&gt;
&lt;p&gt;echo $string1 ; &lt;/p&gt;
&lt;p&gt; will display&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
&lt;i&gt;This is a test&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;To concat two strings you need the dot ( . ) operator so in case you have a long string and for the sake of readability you have to cut it into two you can do it just like the example below.&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
$string=&quot; this is &quot;.&quot; a test &quot;;
&lt;p&gt;Most important string functions :&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;strlen(string). returns number of characters inside the string including blank space. If you want blank space to be removed then you can apply string replace function str_replace to the string before applying strlen.
&lt;li&gt;split(separator,string). Divides a string into several, using a separation character.
&lt;li&gt;substr($string, $start, $end) : get a chunk of $string&lt;br /&gt;
&lt;br&gt;&lt;i&gt; echo substr(&#039;123456789&#039;, 0, 2); &lt;/i&gt;&lt;br /&gt;
&lt;br&gt; Print 12&lt;/p&gt;
&lt;li&gt;str_repeat($string, $n) : repeat $string $n times&lt;br /&gt;
&lt;br&gt; echo str_repeat(&#039;a&#039;, 10); does the same thing as  for ($i = 0; $i &lt; 10; $i++) {&lt;br /&gt;
   echo &#039;a&#039;;&lt;br /&gt;
} &lt;/p&gt;
&lt;li&gt;strrchr($string, $char) : find the last occurence of the character $char in $string&lt;br /&gt;
&lt;br&gt;You can get the file extension from a file name. You can use this function in conjunction with substr().&lt;br /&gt;
&lt;br&gt; $ext = substr(strrchr($filename, &#039;.&#039;), 1);&lt;br /&gt;
&lt;br&gt; For example , we have test.php . strrchr($filename, &#039;.&#039;) returns .php and substr(&quot;.php&quot;,1) returns &lt;i&gt;php&lt;/i&gt;&lt;/p&gt;
&lt;li&gt;trim($string) : remove extra spaces at the beginning and end of $string
&lt;li&gt;explode($separator, $string) : Split $string by $separator&lt;br /&gt;
&lt;br&gt;This function is commonly used to extract values in a string which are separated by a a certain separator string. For example, suppose we have some information stored as comma separated values.&lt;br /&gt;
&lt;br&gt;$string = &#039;Test1, 3 , 2005&#039;; &lt;br&gt;&lt;br /&gt;
$info = explode(&#039;,&#039;, $string);&lt;br /&gt;
&lt;br&gt; Variable $info is an array so we can access the values using $info[0], info[1] etc. For example $info[0]=&quot;Test1&quot;.&lt;/p&gt;
&lt;li&gt;implode($string, $array) : Join the values of $array using $string &lt;br&gt;&lt;br /&gt;
This one do the opposite than the previous function. &lt;/p&gt;
&lt;li&gt;number_format($number): display a number with grouped thousands&lt;br /&gt;
&lt;br&gt; echo number_format(15120777); displays display 15,120,777
&lt;/ul&gt;
</description>
 <pubDate>Thu, 07 Jul 2005 07:15:54 -0500</pubDate>
</item>
<item>
 <title>Switch Statement</title>
 <link>http://www.zentower.com/node/12</link>
 <description>&lt;p&gt;
The Switch statement it is used if you want to select one of many blocks of code to be executed .
&lt;p&gt;&lt;b&gt;Basic structure &lt;/b&gt;
&lt;p&gt;
switch (expression)&lt;br&gt;&lt;br /&gt;
{&lt;br&gt;&lt;br /&gt;
case label1:&lt;br&gt;&lt;br /&gt;
  code to be executed if expression = label1;&lt;br&gt;&lt;br /&gt;
  break;  &lt;br&gt;&lt;br /&gt;
case label2:&lt;br&gt;&lt;br /&gt;
  code to be executed if expression = label2;&lt;br&gt;&lt;br /&gt;
  break;&lt;br&gt;&lt;br /&gt;
default:&lt;br&gt;&lt;br /&gt;
  code to be executed&lt;br&gt;&lt;br /&gt;
  if expression is different &lt;br&gt;&lt;br /&gt;
  from both label1 and label2;&lt;br&gt;&lt;br /&gt;
}&lt;p&gt;
The switch statement executes line by line (actually, statement by statement). In the beginning, no code is executed.
&lt;p&gt;
First we have a single expression (most often a variable), that is evaluated once.&lt;p&gt;
The value of the expression is then compared with the values for each case in the structure. &lt;p&gt;
If there is a match, the block of code associated with that case is executed. Use break to prevent the code from running into the next case automatically. The default statement is used if none of the cases are true.
&lt;p&gt;
Also default statement it is optional . If none of the cases are true and there is no default statement no action will take place.&lt;/p&gt;
</description>
 <pubDate>Thu, 07 Jul 2005 07:15:07 -0500</pubDate>
</item>
<item>
 <title>IF STATEMENTS</title>
 <link>http://www.zentower.com/node/11</link>
 <description>&lt;p&gt;&lt;b&gt;Basic form &lt;/b&gt;
&lt;p&gt;
IF (something == something else)&lt;br&gt;&lt;br /&gt;
{&lt;br&gt;&lt;br /&gt;
THEN Statement&lt;br&gt;&lt;br /&gt;
} else {&lt;br&gt;&lt;br /&gt;
ELSE Statement&lt;br&gt;&lt;br /&gt;
}&lt;br&gt;
&lt;p&gt;
If statements are used to compare two values and carry out different actions based on the results of the test. If statements take the form IF, THEN, ELSE. Basically the IF part checks for a condition. If it is true, the then statement is executed. If not, the else statement is executed.
&lt;p&gt;
Another way to extend an if statement is using “elseif”. Similar to “if”, “elseif” requires an expression to evaluate. On the other hand, unlike “else”, “elseif” will execute a statement if the “if” expression evaluates to FALSE, and only if the “elseif” expression evaluates to TRUE.
&lt;p&gt;You can use several “elseif” structures in the same if statement, but remember that an “elseif” statement will only be executed if the previous expressions were all evaluated to “FALSE”, and the current “elseif” expression evaluates to “TRUE”. In other words, once the “if” structure evaluates an expression to “TRUE”, it executes the corresponding statement, then it exits the structure.
&lt;p&gt;Sample code :
&lt;p&gt;&lt;i&gt;if ($num1 &gt; $num2) //is “$num1” bigger than “$num2”?
&lt;p&gt;
{&lt;br&gt;&lt;/p&gt;
&lt;p&gt;print &quot;The first number is bigger than the second number&quot;; //if it is, do this&lt;br&gt;&lt;/p&gt;
&lt;p&gt;$bigger = $num1; //assigning the value of $num1 to $bigger&lt;br&gt;&lt;/p&gt;
&lt;p&gt;}&lt;br&gt;&lt;/p&gt;
&lt;p&gt;elseif ($num1 == $num2) //the first expression is FALSE, so try this one&lt;br&gt;&lt;/p&gt;
&lt;p&gt;{&lt;br&gt;&lt;/p&gt;
&lt;p&gt;print “Both numbers are equal”; &lt;br&gt;&lt;/p&gt;
&lt;p&gt;}&lt;br&gt;&lt;/p&gt;
&lt;p&gt;else //if the previous if/elseif expressions are FALSE, do this...&lt;br&gt;&lt;/p&gt;
&lt;p&gt;{&lt;br&gt;&lt;/p&gt;
&lt;p&gt;print &quot;The second number is bigger than the first number&quot;; //the only option left&lt;br&gt;&lt;/p&gt;
&lt;p&gt;$bigger = $num2; //assigning the value of $num1 to $bigger&lt;br&gt;&lt;/p&gt;
&lt;p&gt;}&lt;br&gt;&lt;/p&gt;
&lt;p&gt;&lt;/i&gt;&lt;/p&gt;
</description>
 <pubDate>Thu, 07 Jul 2005 07:10:31 -0500</pubDate>
</item>
<item>
 <title>Loops</title>
 <link>http://www.zentower.com/node/10</link>
 <description>&lt;p&gt;&lt;b&gt;The WHILE Loop&lt;/b&gt;
&lt;p&gt;The WHILE loop is one of the most useful and simple commands in PHP.
&lt;p&gt;It is composed of a body containing some instructions and an exit condition. At the beginning of the cycle and each successive iteration, all the instructions in the body are executed, the exit condition consisting of a boolean expression, is checked up. The loop ends when the exit condition returns a false value.
&lt;p&gt;So it executes a piece of code until a certain condition is met.
&lt;p&gt;If you have a piece of code which you want to repeat several times without retyping it, you can use a while loop.
&lt;p&gt;&lt;b&gt; Basic form &lt;/b&gt;:
&lt;p&gt;
while (expr)&lt;br&gt;&lt;br /&gt;
    statement
    &lt;p&gt;
    or, if need to execute multiple statements you could use :
    &lt;p&gt;
while (expr):&lt;br&gt;&lt;br /&gt;
    statement&lt;br&gt;&lt;br /&gt;
    ...&lt;br&gt;&lt;br /&gt;
endwhile;
&lt;p&gt;Sample code:&lt;p&gt;
&lt;i&gt;$no = 10;&lt;br&gt;&lt;br /&gt;
$x = 0;&lt;br&gt;&lt;br /&gt;
while ($x &lt; $no) {&lt;br&gt;&lt;br /&gt;
echo &quot;Test script&quot;;&lt;br&gt;&lt;br /&gt;
++$x;&lt;br&gt;&lt;br /&gt;
}&lt;/i&gt;
&lt;p&gt;The variable $no holds the number of times you need to execute the code and $x (variable x) will count how many times code has been executed.
&lt;p&gt;After a line is printed variable x is incremented by 1 and the test $x&gt;$no is performed again.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;do-while &lt;/b&gt;
&lt;p&gt;do-while loops are very similar to while loops, except the truth expression is checked at the end of each iteration instead of in the beginning. Therefore the statement will be run at least once if you will use do-while instead of while.
&lt;p&gt;&lt;b&gt; Basic form &lt;/b&gt;:&lt;/p&gt;
&lt;p&gt; do  &lt;br&gt;&lt;br /&gt;
{&lt;br /&gt;
	statement...&lt;br&gt;&lt;br /&gt;
} while (condition)&lt;br&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;for loops &lt;/b&gt;
&lt;p&gt;&lt;b&gt; Basic form &lt;/b&gt;:
&lt;p&gt;
for (expr1; expr2; expr3)&lt;br&gt;&lt;br /&gt;
    statement&lt;br&gt;
&lt;p&gt;
The first expression (expr1) is executed once unconditionally at the beginning of the loop.
&lt;p&gt;
In the beginning of each iteration, expr2 is evaluated. If it evaluates to TRUE, the loop continues and the nested statement(s) are executed. If it evaluates to FALSE, the execution of the loop ends.
&lt;p&gt;
At the end of each iteration, expr3 is evaluated (executed).
&lt;p&gt;
&lt;table width=&quot;600&quot; border=&quot;1&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; align=&quot;center&quot; bordercolor=&quot;#ECECEC&quot;&gt;
                  &lt;tr bgcolor=&quot;#EBEBEB&quot;&gt;
                    &lt;td colspan=&quot;4&quot; height=&quot;24&quot;&gt;
                      &lt;div align=&quot;center&quot;&gt;&lt;font face=&quot;Verdana, Arial, Helvetica, sans-serif&quot; size=&quot;-1&quot;&gt;&lt;b&gt;Comparisons&lt;br /&gt;
                        of &lt;i&gt;for&lt;/i&gt; and &lt;i&gt;while&lt;/i&gt; loops&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;
&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr bgcolor=&quot;#EBEBEB&quot;&gt;
                    &lt;td colspan=&quot;2&quot;&gt;
                      &lt;div align=&quot;center&quot;&gt;&lt;font face=&quot;Verdana, Arial, Helvetica, sans-serif&quot; size=&quot;-1&quot;&gt;&lt;b&gt;&lt;i&gt;for&lt;/i&gt;&lt;br /&gt;
                        Loop&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;
                    &lt;/td&gt;
                    &lt;td colspan=&quot;2&quot; width=&quot;288&quot;&gt;
                      &lt;div align=&quot;center&quot;&gt;&lt;font face=&quot;Verdana, Arial, Helvetica, sans-serif&quot; size=&quot;-1&quot;&gt;&lt;b&gt;&lt;i&gt;while&lt;/i&gt;&lt;br /&gt;
                        loop &lt;/b&gt;&lt;/font&gt;&lt;/div&gt;
&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                    &lt;td colspan=&quot;2&quot;&gt;
                      &lt;div align=&quot;left&quot;&gt;&lt;font face=&quot;Verdana, Arial, Helvetica, sans-serif&quot; size=&quot;-1&quot;&gt;for&lt;br /&gt;
                        ($i=0; $i&amp;lt;=10; $i++) { &lt;/font&gt;&lt;/div&gt;
                      &lt;dir&gt;&lt;br /&gt;
                        &lt;div align=&quot;left&quot;&gt;&lt;font face=&quot;Verdana, Arial, Helvetica, sans-serif&quot; size=&quot;-1&quot;&gt;echo(&quot;Iteration&lt;br /&gt;
                          no. $i&amp;lt;BR&amp;gt;&quot;);&lt;/font&gt;&lt;/div&gt;
                      &lt;/dir&gt;&lt;/p&gt;
&lt;div align=&quot;left&quot;&gt;&lt;font face=&quot;Verdana, Arial, Helvetica, sans-serif&quot; size=&quot;-1&quot;&gt;}&lt;/font&gt;&lt;/div&gt;
                    &lt;/td&gt;
                    &lt;td colspan=&quot;2&quot; width=&quot;288&quot;&gt;&lt;font face=&quot;Verdana, Arial, Helvetica, sans-serif&quot; size=&quot;-1&quot;&gt;$i=0;&lt;br&gt;&lt;br /&gt;
                      while ($i&amp;lt;=10) { &lt;/font&gt;&lt;br /&gt;
                      &lt;dir&gt;&lt;font face=&quot;Verdana, Arial, Helvetica, sans-serif&quot; size=&quot;-1&quot;&gt;echo&lt;br /&gt;
                        (&quot;Iteration no. $i&amp;lt;BR&amp;gt;&quot;);&lt;br&gt;&lt;br /&gt;
                        $i++;&lt;/font&gt;&lt;/dir&gt;&lt;/p&gt;
&lt;p&gt;                      &lt;font face=&quot;Verdana, Arial, Helvetica, sans-serif&quot; size=&quot;-1&quot;&gt;}&lt;/font&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                &lt;/table&gt;
</description>
 <pubDate>Thu, 07 Jul 2005 07:02:07 -0500</pubDate>
</item>
<item>
 <title>Functions</title>
 <link>http://www.zentower.com/node/9</link>
 <description>&lt;p&gt; If programs are large or you must copy-paste the same code several times within the same file the best way is to use functions.
&lt;p&gt;Defining a function is really simple , there is the keyword &lt;b&gt;function&lt;/b&gt; , the function name (your choice) , follow it with ( ),&lt;br /&gt;
and specify the instructions it contains . The () can contain a list of parameters (optional).
&lt;p&gt;A function returns a result to the calling code by using the &quot;return: keyword, like this:
&lt;p&gt;return $result;
&lt;p&gt;
Example:&lt;p&gt;
 function addition($val1, $val2)&lt;br /&gt;
{&lt;br /&gt;
    $sum = $val1 + $val2;&lt;br /&gt;
    return $sum;&lt;br /&gt;
} &lt;/p&gt;
&lt;p&gt;Function names are case sensitive, meaning that addition() is not the same as AddiTion().&lt;/p&gt;
&lt;p&gt;The instructions contained within a function are not processed (executed) until the function is called, regardless or where within your program the function is defined.  This means that theoretically, your functions could be defined anywhere within the program.&lt;br /&gt;
Best practice, however, is to define all your functions at the beginning of your program script.
&lt;p&gt;A function is called by its name followed by a set of parentheses, like this:
&lt;p&gt;
$var1=4;&lt;br&gt;&lt;br /&gt;
$var2=5;&lt;br&gt;&lt;br /&gt;
$sum=addition($var1,$var2);&lt;br&gt;&lt;br /&gt;
After the function is executed $sum=9;
&lt;p&gt;
It is important to note that if you define a variable within a function, that variable is only available within that function; it cannot be referenced in another function or in the main body of your program code.  This is known as a variable&#039;s scope.  The scope of a variable defined within a function is confined to that function -- in other words, it&#039;s local to that function.
&lt;p&gt;
If a function needs to use a variable that is defined in the main body of the program, it must reference it using the &quot;global keyword, like this:
&lt;p&gt;function addition($val1, $val2)&lt;br&gt;&lt;br /&gt;
{&lt;br&gt;&lt;br /&gt;
		global sum;&lt;br&gt;&lt;br /&gt;
	    $sum = $val1 + $val2;&lt;br&gt;&lt;br /&gt;
}
&lt;p&gt;
$var1=4;&lt;br&gt;&lt;br /&gt;
$var2=5;&lt;br&gt;&lt;br /&gt;
$sum=0;&lt;br&gt;&lt;br /&gt;
addition($var1,$var2);&lt;br&gt;&lt;br /&gt;
echo $sum &lt;br&gt;
&lt;p&gt;While the scope of a variable defined in a function is local to that function, a variable defined in the main body of code has a global scope.  The &quot;global&quot; keyword tells PHP to look for a variable that has been defined outside the function.
&lt;p&gt;That is because a variable defined within a function exists only while that function is being processed; when the function ends, the variable ceases to exist.&lt;/p&gt;
</description>
 <pubDate>Thu, 07 Jul 2005 06:34:40 -0500</pubDate>
</item>
<item>
 <title>PHP Email</title>
 <link>http://www.zentower.com/node/8</link>
 <description>&lt;p&gt;We can use PHP mail function to send mail to different address. This function is required for sending newsletters, designing feedback forms, signup welcome messages and in many more uses.
&lt;p&gt;&lt;b&gt;Description :&lt;/b&gt;
&lt;p&gt;&lt;i&gt;bool mail ( string to, string subject, string message [, string additional_headers [, string additional_parameters]] )&lt;/i&gt;
&lt;p&gt;The mail() function&lt;br /&gt;
requires three strings representing the recipient of the mail, the mail subject, and&lt;br /&gt;
the message.
&lt;p&gt;
mail() returns false if it encounters an error and true if operation was successful.
&lt;p&gt;
If you are running PHP on a UNIX system, mail() will use Sendmail. On other&lt;br /&gt;
systems, the function will connect to a local or remote SMTP mail server. You should&lt;br /&gt;
set this using the SMTP directive in the php.ini file.
&lt;p&gt;Besides the 3 main parameters , there are also 2 optional parameters.
&lt;p&gt;If a fourth string argument is passed, this string is inserted at the end of the header.
&lt;p&gt;This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (\r\n).
&lt;p&gt; With the fifth parameter you can set additional command line parameters to the actual mailer.
&lt;p&gt;The &lt;i&gt;&lt;u&gt;additional_parameters&lt;/i&gt;&lt;/u&gt; parameter can be used to pass an additional parameter to the program configured to use when sending mail using the sendmail_path  configuration setting.
&lt;p&gt;This option is rarely used.
&lt;p&gt;Important :  When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini.
&lt;p&gt;
Sample code :
&lt;p&gt;$recipient .= &quot;camelia@aisoftware.ro&quot;;&lt;br /&gt;
&lt;br&gt;$subject = &quot;Test PHP mail&quot;;&lt;br /&gt;
&lt;br&gt;$message .= &quot;This is a test mail \n&quot;;&lt;br /&gt;
&lt;br&gt;/* additional header pieces for errors, From cc&#039;s, bcc&#039;s, etc */&lt;br /&gt;
&lt;br&gt;$headers .= &quot;From: Camelia \n&quot;;&lt;br /&gt;
&lt;br&gt;$headers .= &quot;To-Sender: \n&quot;;&lt;br /&gt;
&lt;br&gt;$headers .= &quot;X-Mailer: PHP\n&quot;; // mailer&lt;br /&gt;
&lt;br&gt;$headers .= &quot;X-Priority: 1\n&quot;; // Urgent message!&lt;br /&gt;
&lt;br&gt;$headers .= &quot;Return-Path: \n&quot;; // Return path for errors&lt;/p&gt;
&lt;p&gt;&lt;br&gt;$headers .= &quot;Content-Type: text/html; charset=iso-8859-1\n&quot;; // Mime type&lt;br /&gt;
&lt;br&gt;$headers .= &quot;cc:ccemail@yahoo.com\n&quot;; // CC to&lt;br /&gt;
&lt;br&gt;$headers .= &quot;bcc:bccemail@yahoo.com\n&quot;; // BCCs to&lt;/p&gt;
&lt;p&gt;&lt;br&gt;mail($recipient, $subject, $message, $headers);
&lt;p&gt;
&lt;b&gt;Note:&lt;/b&gt;
&lt;p&gt;
Something you may have noticed from the example is that the From line ended with \n. This is acutally a very important character when sending e-mail. It is the new line character and tells PHP to take a new line in an e-mail. It is very important that this is put in after each header you add so that your e-mail will follow the international standards and will be delivered.&lt;/p&gt;
</description>
 <pubDate>Thu, 07 Jul 2005 06:32:14 -0500</pubDate>
</item>
<item>
 <title>Files</title>
 <link>http://www.zentower.com/node/7</link>
 <description>&lt;p&gt;One of the most useful features of a server side language is its ability to interface with the file system on the server that hosts the website.  This feature clearly distinguishes the language from a client side language such as JavaScript.
&lt;p&gt;It is because of this fact that the language has the ability to interface with the files on the server.
&lt;p&gt;To access a file you first have to establish a connection to that file.  This is done by opening the file with the fopen function.  To use the fopen function you provide it two parameters.  The first is the name of the file you wish to use and the second says how you want to use the file (for reading or writing, etc.)  Using the fopen function establishes a pointer to the file.  Here&#039;s an example:
&lt;p&gt;$myfilepointer = fopen(&quot;myfilename.txt&quot;, &quot;w&quot;);
&lt;p&gt;here, we&#039;re opening a file called &quot;myfilename.txt&quot; and saying that we wish to write to it.  The &quot;w&quot;, which is what tells PHP we want to write to the file, is called the Access Mode.  Other values that can be used, and their meanings are:
&lt;p&gt;
r 	read only&lt;br&gt;&lt;br /&gt;
r+ 	reading and writing&lt;br&gt;&lt;br /&gt;
w 	write only &amp;#038; create the file if it doesn&#039;t exist&lt;br&gt;&lt;br /&gt;
w+ 	reading and writing &amp;#038; create the file if it doesn&#039;t exist&lt;br&gt;&lt;br /&gt;
&lt;br&gt;a 	writing only, create if it doesn&#039;t exist, and place a file position pointer at the end of the file (appends records to an existing file)&lt;br /&gt;
&lt;br&gt;a+ 	reading and writing, create if it doesn&#039;t exist and place file position pointer at the end of the file
&lt;p&gt;These parameters have introduced the idea of a file position pointer.  As you read a file, something has to keep track of where you are in the file so that you can read the next record.  That something is the file position pointer.  This pointer gets interesting when you think about writing to the file.  If you are writing to a new file it&#039;s pretty straight forward -- you write a record, the pointer points at the end of that record and you write another record, and so on.
&lt;p&gt;If, however, the file already exists and contains some records, the value of the pointer when you first open the file becomes very important!  If the file is opened with the pointer at the beginning of the file (like r+, w or w+), when you write to that file you will overwrite the existing records in the file, replacing them with your new records.  On the other hand, if you open it with the pointer pointing at the end of the file (like a or a+), you will append records to the file, adding them to the existing records.
&lt;p&gt;Reading and Writing Records is accomplished with the fgets and fputs functions.
&lt;p&gt;Example:
&lt;p&gt;
$handle = fopen(&quot;/tmp/inputfile.txt&quot;, &quot;r&quot;);&lt;br&gt;&lt;br /&gt;
while (!feof($handle)) {&lt;br&gt;&lt;br /&gt;
   $buffer = fgets($handle, 4096);&lt;br&gt;&lt;br /&gt;
   echo $buffer;&lt;br&gt;&lt;br /&gt;
}&lt;br&gt;&lt;br /&gt;
fclose($handle);&lt;/p&gt;
</description>
 <pubDate>Thu, 07 Jul 2005 06:29:04 -0500</pubDate>
</item>
<item>
 <title>Array</title>
 <link>http://www.zentower.com/node/4</link>
 <description>&lt;p&gt;PHP array are useful to store multiple data using a single variable.
&lt;p&gt;Arrays are common to many programing languages. They are special variables which can hold more than one value, each stored in its own numbered &#039;space&#039; in the array. Arrays are extremely useful, especially when using WHILE loops.
&lt;p&gt;We can access the stored variables using index of the PHP array .
&lt;p&gt; Indexes to an array element can either a number or a string.
&lt;p&gt; Each item in an array is commonly known as element of the array and can be accessed directly via its index.
&lt;p&gt; Simple and multi-dimensional arrays are supported, and may be either user created or created by another function.
&lt;p&gt;Setting up an array is slightly different to setting up a normal variable. In this example I will set up an array with 3 names in it:
&lt;p&gt;
$names[0] = &#039;name1&#039;;&lt;br&gt;&lt;br /&gt;
$names[1] = &#039;name2&#039;;&lt;br&gt;&lt;br /&gt;
$names[2] = &#039;name3&#039;;&lt;br&gt;
&lt;p&gt;As you can see, the parts of an array are all numbered, starting from 0. To add a value to an array you must specify the location in the array by putting a number in [ ].
&lt;p&gt;Reading from an array is just the same as putting information in. All you have to do is to refer to the array and the number of the piece of data in the array. So if I wanted to print out the third name I could use the code:
&lt;p&gt; echo $names[2];
&lt;p&gt;Main array functions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;sizeof($array)   count elements in an array
&lt;li&gt;current($array)  Return the current element in an array
&lt;li&gt;sort($array, [, int sort_flags] )  sorts an array. Elements will be arranged from lowest to highest when this function has completed.
&lt;li&gt;key() returns the index element of the current array position.
&lt;p&gt; Example :&lt;br /&gt;
$array = array(&lt;br&gt;&lt;br /&gt;
   &#039;elem1&#039; =&gt; &#039;apple&#039;,&lt;br&gt;&lt;br /&gt;
   &#039;elem2&#039; =&gt; &#039;orange&#039;,&lt;br&gt;&lt;br /&gt;
   &#039;elem3&#039; =&gt; &#039;grape&#039;};&lt;br&gt;&lt;/p&gt;
&lt;p&gt;// this cycle echoes all associative array&lt;br&gt;&lt;br /&gt;
// key where value equals &quot;apple&quot;&lt;br&gt;&lt;br /&gt;
while ($elem = current($array)) {&lt;br&gt;&lt;br /&gt;
   if ($elem == &#039;apple&#039;) {&lt;br&gt;&lt;br /&gt;
       echo key($array).&#039;&lt;br /&gt;&#039;;&lt;br&gt;&lt;br /&gt;
   }&lt;br&gt;&lt;br /&gt;
   next($array);&lt;br&gt;&lt;br /&gt;
}&lt;p&gt; The result displayed would be &quot;elem1&quot;&lt;/p&gt;
&lt;/ul&gt;
</description>
 <pubDate>Thu, 07 Jul 2005 06:18:37 -0500</pubDate>
</item>
<item>
 <title>PHP Include Files</title>
 <link>http://www.zentower.com/node/3</link>
 <description>&lt;p&gt;You can insert the content of one file into another file before the server executes it, with the require() or include () function. The require() function is used to create functions, headers, footers, or elements that will be reused on multiple pages.
&lt;p&gt;This can save the developer a considerable amount of time. If all of the pages on your site have a similar header, you can include a single file containing the header into your pages. When the header needs updating, you only update the one page, which is included in all of the pages that use the header.
&lt;p&gt;include() and require()are identical in every way except how they handle failure. include() produces a Warning while require()  results in a Fatal Error.
&lt;p&gt; When a file is included, the code it contains inherits the variable scope of the line on which the include occurs. Any variables available at that line in the calling file will be available within the called file, from that point forward.
&lt;p&gt;Example :
&lt;p&gt;
&amp;lt;? include (&quot;external_file.php&quot;);?&amp;gt;&lt;/p&gt;
</description>
 <pubDate>Sun, 10 Jul 2005 11:00:24 -0500</pubDate>
</item>
</channel>
</rss>
