Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,120 members, 7,818,360 topics. Date: Sunday, 05 May 2024 at 01:30 PM

Web Development Using PHP - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Web Development Using PHP (6967 Views)

How To Make a DESKTOP Executable Software Using PHP,MYSQL,SQLITE / How To Generate A Word File .doc/.docx Using Php / Help Pls!! How Do I Connect Oracle With Dreamweaver Using Php Server? (2) (3) (4)

(1) (2) (Reply) (Go Down)

Web Development Using PHP by skima(m): 11:01pm On Apr 08, 2006
People have been clamouring for a tutorial on PHP. I think its high time we started it.

If u will like to contribute to this tutorial let your interest be known, but for me i plan to start it right here on wednesday by the grace of God.

I assume the person to learn this tutorial would have had little programming knowledge so that we do start wasting time introducing programming  rudiments.

I will advice the read to learn Javascript to get started.

We shall go into php basics then to core development.

Re: Web Development Using PHP by kenshin(m): 11:25pm On Apr 08, 2006
thanks @Skima
Re: Web Development Using PHP by sbucareer(f): 8:45pm On Apr 09, 2006
[size=24pt]PHP basics[/size]




[size=14pt]What is PHP?[/size]


PHP means P[/b]HP [b]H[/b]ypertext [b]P[/b]reprocessor. PHP is script language and it is only used in server side processing.  The basic knowledge needed before learning PHP would be

1. HTML/XHTML
2. Some scripting knowledge i.e (DOS batch script)
3. Database design and querying (Only if you want dynamic HTML behavior)

The tools you will need are mostly free and Open Source Software (OSS).  PHP is like Microsoft ASP, ASP.NET, VB.NET, C#.NET, J#.NET, JSP, Perl, CGI, Python script and other server side scripting.

What is server side scripting? Well, it is a special API's written in many different languages that make absolutely used of the HTTP, HTTPS, FTP, GOPHER and other web communication protocol that uses the [b]request
and response mechanism to communication to a container in a remote location.

A container, is used by web protocol developers to denote a Framework that allows a web application server to have a standard and conform to the internalization of basic technology so that web servers understands each other regardless the provider. In other word a web container is a peace of software you can install in your choice of OS (Operating System) that default uses the HTTP port 80 to listen to requests on the WWW and can construct a response back to the client depending if all the security issues involves with that request is fullfiled.

We have lots of web container and most of them runs only one script language others runs many. Like Mircosoft .NET runs lots of script language i.e.

1. ASP
2. VB
3. C#
4. J#

Java is not a script language but has provided API's for people interested in using java in web development. Java uses containers like tomcat, a Jakarta project and Sun that engineered Java provides Container with more complex features to managing script language called Application Server. It runs EJB (Entity Java Bean), which is a specification for running Web Application developed for with Java.

Apache group has been an old group of computer engineer architects that researches and produce recommendations and standards to Open source Community and other government affiliate that regulates IEEE.

Apache has pioneered many project including the development of Java API's for web containers to ant, a simple build tool for easy software deployment. Ant was a former UNIX shell called make, used in building and compiling application in the Unix environment.

Because PHP is just a script language it needs a container to run with. The only container that I know of that runs PHP scripts API's is apache. Apache is a HTTP container (Web Server). The power of Apache is that it runs many script language, from Java to python and CGI. But unfortunately, it does not run all these script in one simple container. You have to download the particular container you want to develop in with i.e. say you want to write Perl script, you'd download apache and say for java you had download tomcat and so on.

For this tutorial on PHP we need apache container for PHP. We also need to download the PHP API's binary since it is another open source community that writes and maintains it.

1 Like

Re: Web Development Using PHP by sbucareer(f): 9:12pm On Apr 09, 2006

For the simplicity of the tutorial I would be providing basic tools configurations in Windows environment. If you use Unix of any flavor I'd say you are a little bit technical and would not find it challenging to get apache in you box up and running with PHP.

For window users, download [url=http://httpd.apache.org/download.cgi?Preferred=http%3A%2F%2Fapache.rmplc.co.uk]apache 2.0[/url] and save it in your c:\temp. Navigate to PHP and download PHP 5.1.2 and save it in your c:\temp directory.

If you downloaded a zipped archive you would need an unzip program to extract the files out of the cabinate. If they came in executable form, you have to follow the installation wizard, make sure that your server port is changed to port 80 from 8080, which is there by default.

When you finished extracting your PHP files or executing the installation go to the directory and copy php.ini into C:\windows

Re: Web Development Using PHP by sbucareer(f): 9:37pm On Apr 09, 2006

To understand apache server is to understand the folders directory structure. After installing apache you would see a structure like this assuming you installation was in c:\program fils\apache group\apache2

There are about 12 folders in apache 2.0 namely:

1. bin
2. conf
3. htdocs
4. include
5. logs
6. modules
7. cgin-bin
8. error
9. icons
10 lib
11 manual
12 proxy


After installation of any software, a good place to start is the README.txt file. It is usually install in the root directory of the software installed. It is important to read it. In the above directory the once to particularly be aware of  are the

1. bin
2. conf
3. htdocs
4. modules

The most important of them all is the htdocs, this is where you put your HTML files that you have patiently developed for a company that paid you money to design a website for them.

Now to configure that server from hackers and other software virus you need to explore the conf directory, which means configuration directory. The most important file there is the httpd.txt.

Use an editor or notepad to edit it. If there is an error in this file the server will NOT start. It is wise to make a back up httpd.txt before modifying it. To learn for about modifying it visit apache documentation

Modules are where you add new modules for the server and add it in the httpd.txt at line addModule

1 Like

Re: Web Development Using PHP by sbucareer(f): 10:09pm On Apr 09, 2006

I do not want to start re-inventing the wheel as many wheels have already been invented. To configure installed Apache with PHP follow this link

After the above link tutorial open your browser and type http://localhost/phpinfo.php, you will see your server php configuration list. If that is true your PHP is configured and you can start writing PHP script.

I forgot to mention this in the earlier tutorial. To access any web application, since PHP is a web application you would need a browser and to access the page you need to know the domain name. In this instance our domain name is localhost. So you'd done this http://localhost Remember if you have followed my instruction above and change the port to 80 you would NOT need to to this http://localhost:8080.

Remember in folder htdocs every folder there is a new application context. i.e if I have a folder under htdocs like

1. solicitor
2.trader

To access them I'd done this htt://localhost/solicitor and http://localhost/trader respectively. So you can have many host in one server that is how host company used in hosting many people on their server. They don't run a server per person they use virtual hosting. The way it works it to create folder for each person and allow them access it using their folder name(s)

Re: Web Development Using PHP by sbucareer(f): 10:30pm On Apr 09, 2006

You often hear PHP and MYSQL. Well, any web application development that needs to remember person or your business transaction with that web site would need a way to save your conversation with them. We use database as a storage mechanism.

In software engineering we use state to depict the conversational elements of a particular person with a web site. State has elements and behavior. A state is the elements that makes up a particular event, which could occur over and over again.

MYSQL, is a powerful transactional database management system. Engineers have employed the traditional relational schema and other database features. MYSQL is NOT free, but has a license for open source community for none profit usage and personal use. You can download and use MSQL for free as long as it is NOT for profit purposes. If you want to use it for profit you would need to get a license from MSQL website or by phoning them.

MYSQL could be downloaded from here and instruction on installation in windows here

Re: Web Development Using PHP by sbucareer(f): 10:47pm On Apr 09, 2006

When you have finished installing PHP and apache server and run the http://localhost/phpinfo.php and it return true. Then try and install MSQL, it does not need any special configuration with Apache or php.

I will show you how to connect to a database, even if the database is in a remote location (different location where you apache server is). Write a simple HelloWorld and save it into the folder htdocs and access the HelowWorld by typing http://localhost/HelloWorld.php.

Here is the HellowWorld Script

<HTML>
<HEAD>
          <TITLE>My Hello World </TITLE>
</HEAD>
<BODY>
  <?php
           echo '<p>Hello World</p>';
?>
</BODY>
</HTML>

The the file into htdocs folder as hellowWorld.php as access it from a broswer as http://localhost/hellowWorld.php. If you have any problem so far let us know

Re: Web Development Using PHP by Ynot(m): 11:02pm On Apr 09, 2006
sbucareer:


When you finished extracting your PHP files or executing the installation go to the directory and copy php.ini into C:\windows



Nice work so far SBU. There is something i need to point out from PHP documentation:

The PHP manual used to promote the copying of files into the Windows system directory, this is because this directory (C:\Windows, C:\WINNT, etc.) is by default in the systems PATH. Copying files into the Windows system directory has long since been deprecated and may cause problems.

This means you no longer need to copy php.ini into C:\Windows. With PHP 5.x, you need to insert these two lines to your Apache httpd.conf configuration file to set up the PHP module for Apache 2.0:

LoadModule php5_module "c:/php/php5apache2.dll"
AddType application/x-httpd-php .php

# configure the path to php.ini
PHPIniDir "C:/php"

That is, assuming you unzipped your php files in c:/php/ (recommended) or you can subtitute your actual path to PHP for the c:/php/.

Then add PHP directory to the PATH on Windows.

Lastly, take care to use php5apache2.dll in your LoadModule directive and not php5apache.dll as the latter is designed to run with Apache 1.3.x.
Re: Web Development Using PHP by sbucareer(f): 11:12pm On Apr 09, 2006

Ynot, thank you very much for pointing out that issue. also Ynot if you could help me co-author this tutorial please, it seems you know your stuff.

Re: Web Development Using PHP by Ynot(m): 11:25pm On Apr 09, 2006
You go ahead. I'm not much of a teacher and i hate typing. You are doing a wonderful job. Be rest assured i will be following the tutorial and will always point out issue when necessary.
Re: Web Development Using PHP by Nobody: 5:18am On Apr 10, 2006
AM new to php i have it on my computer and i have been trying to figure out how am going to go about it. Thanks for the tutorial am really enjoying it
Re: Web Development Using PHP by sbucareer(f): 9:02am On Apr 10, 2006

Because PHP is an extension of programming language and mimic C/C++ in the manner of API's calls and design paradigm. You do not need to know programming language to learn PHP.

If you have programmed before, learning PHP would be a lot easier for you. But programming language involves manipulation of memories and registers in the CPU cache memory.

Because technologies have emerge, we do not need to learn all the memory address of a computer memory. All we need is to use a variable to reference a location in the memory our compiler will handle the actual physical location and apply operation to do our tasks.

What is a variable? Well a variable is a peace of container you put things. Like women, their hand-bag is there variable because the can put lots of things in there whether they remember it or not is not really important because they can open their hang-bag and look for their lipstick and retrieve it.

In computer, we use variables to store state i.e lipstick.  Like a hang-bag, we can store many things not anything, because we canot put a car in a hand-bag, we can then store state into a variableand when we need it back we simply call the vvariablename back.

Example

In PHP we declare variablesby using $ in front of a name. Say I want to store someones age, I would say that the variable name would be called age just to let me know what type of variable I am dealing with, we write it like this $age and I would need to initial it. To do that I would need an assignment operator like = i.e. $age = 21, because is untyped language you do not need to tell the compiler the type of age i.e. iinteger char, int, byte etc. The compiler works out at compile-time what the type is, which if you ask me is very dangerous. But I am not PHP architectsthat made this decision during the birth of PHP.

Re: Web Development Using PHP by phantomcat(m): 10:18am On Apr 10, 2006
sbucareer the server in my office has apache installed how do i check if it also has php? so i dont do a double installation. thanks for the tutorial
Re: Web Development Using PHP by sbucareer(f): 11:24am On Apr 10, 2006

Create a PHP file and call it anything and put it in the htdocs folder and access it from your browser i.e. http://localhost/filename.php


<HTML>
<HEAD>
   <TITLE>Testing if PHP is installed</TITLE>
</HEAD>

<BODY>

<?php

  phpinfo();
?>

</BODY>
</HTML>

This would show you details of your PHP setting and whether PHP is installed or NOT
Re: Web Development Using PHP by sbucareer(f): 11:57am On Apr 10, 2006

Another way is to open the httpd.txt in the conf directory folder and locate the LoadModules i.e.


LoadModule access_module modules/mod_access.so
LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
LoadModule asis_module modules/mod_asis.so
LoadModule auth_module modules/mod_auth.so
#LoadModule auth_anon_module modules/mod_auth_anon.so
#LoadModule auth_dbm_module modules/mod_auth_dbm.so
#LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule autoindex_module modules/mod_autoindex.so
#LoadModule cern_meta_module modules/mod_cern_meta.so
LoadModule cgi_module modules/mod_cgi.so
#LoadModule dav_module modules/mod_dav.so
#LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
#LoadModule expires_module modules/mod_expires.so
#LoadModule file_cache_module modules/mod_file_cache.so
#LoadModule headers_module modules/mod_headers.so
LoadModule imap_module modules/mod_imap.so
LoadModule include_module modules/mod_include.so
#LoadModule info_module modules/mod_info.so
LoadModule isapi_module modules/mod_isapi.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
#LoadModule mime_magic_module modules/mod_mime_magic.so
#LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule negotiation_module modules/mod_negotiation.so
#LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
#LoadModule speling_module modules/mod_speling.so
LoadModule status_module modules/mod_status.so
#LoadModule unique_id_module modules/mod_unique_id.so
LoadModule userdir_module modules/mod_userdir.so
#LoadModule usertrack_module modules/mod_usertrack.so
#LoadModule vhost_alias_module modules/mod_vhost_alias.so
#LoadModule ssl_module modules/mod_ssl.so
LoadModule php4_module "c:/php/php4apache2.dll"

The red line is where I told apache to find php.ini, like Ynot said earlier. Also find in the conf folder

# configure the path to php.ini
PHPIniDir "C:/temp/php"

This will tell the server to look for php.ini in that folder. You can create any folder name, I chose the c:/temp/php, it is optional

Re: Web Development Using PHP by Rhodalyn(f): 11:57am On Apr 10, 2006
shocked shocked shocked shocked
Re: Web Development Using PHP by sbucareer(f): 12:05pm On Apr 10, 2006

Rhodalyn, what is the problem?

Re: Web Development Using PHP by sbucareer(f): 12:27pm On Apr 10, 2006

TYPES

PHP supports eight primitive data type

1. boolean
2. float
3. integer
4. String


Object or compound types

5. Object
6. Array

The two special types are the

7. resource
8. null

Data types are very important in programming language. Infact data types are the programming itself. If you can understand data types of any language you have already half way to learning the language.

Why is data type so important? Well, everything we do with program is, manipulation of memory address and finally storing it to a permanent storage like database. So why data type. Like in database we need to know how to represent a particular information like customer.

In database, if we want to represent customer in a database we need to know the attributes or variables of the customer i.e

name, age, address, date of birth, country, phone number, sex etc. All these attributes are not the same. Some are real numbers, some are characters, some are mixed numbers (float), some are integers, some are just yes or no

It would be wrong to categorise all data type as one data type. It would probably introduce buy in our program and curse memory leaks. Writing program language is no different from creating a database like customer table, because you have to think about its attributes and initial states.

In PHP we use data type to represent complex data structure, like customer, order, employee details and store records.

to declare a data type we use the $ sign in front to the variable name.

Example, let represent customer details in PHP program

$name="nairaland";
$age= 2;
$address="23 Lagos street";
$dob=20031983;
$country="Nigeria";
$phoneNumber="0237454090";
$sex="M";


This is how we declare and initialize variables in PHP. We will go into object and resource type later in the tutorial. So to call these variable within an application we simply write a HTML file and save it as .php extension and put it in you apache directory folder called htdocs

Re: Web Development Using PHP by sbucareer(f): 12:30pm On Apr 10, 2006


<HTML>
<HEAD>
   <TITLE>Customer Details</TITLE>
</HEAD>

<BODY>

<?php

$name="nairaland";
$age= 2;
$address="23 Lagos street";
$dob=20031983;
$country="Nigeria";
$phoneNumber="0237454090";
$sex="M";

       echo $name "\"\n";
       echo $age "\"\n";
       echo $address "\"\n";       
       echo $dob "\"\n";
       echo $country "\"\n";
       echo $phoneNumber "\"\n";
       echo $sex "\"\n";

?>

</BODY>
</HTML>

Re: Web Development Using PHP by sbucareer(f): 12:36pm On Apr 10, 2006

If you want to get a datatype you will use a PHP reserved function called gettype() We will talk about functions later in the tutorial

<HTML>
<HEAD>
   <TITLE>Printing data types</TITLE>
</HEAD>

<BODY>

<?php
  $age = 23;

  echo gettype($age);  // prints out:  interger
?>

</BODY>
</HTML>

To learn more about internal function visit here

Re: Web Development Using PHP by sbucareer(f): 12:50pm On Apr 10, 2006

Remember echo is like System.out.print() in java and printf in C/C++, it is a way of sending bits stream out from the standard input output.

Re: Web Development Using PHP by whitesoftx(m): 8:48am On Apr 11, 2006
@sbucareer!

I'm loving it! keep it up bro! now we getting somewhere!
Re: Web Development Using PHP by romeo(m): 12:00pm On Apr 11, 2006
@sbucareer

i used wamp5 and i have everything installed , so how do i start from there?
Re: Web Development Using PHP by sbucareer(f): 3:30pm On Apr 11, 2006

You can use XAMP, an open source apache and PHP. Everything is installed and configured to go. No need for that scratchy installation of PHP and apache configuration

Re: Web Development Using PHP by skima(m): 3:48pm On Apr 11, 2006
write ur first php script.

<?php
phpinfo();

?>

Then save it as index.php and access it via ur localhost in this format http://localhost/index.php

That will confirm if the installation is right.
Re: Web Development Using PHP by romeo(m): 4:20pm On Apr 11, 2006
thanks skima grin i have done that and what is the next step please
Re: Web Development Using PHP by skima(m): 10:34am On Apr 12, 2006
If you see php information on your page then you have successfully installed php.

else lets see the error msg you got.
Re: Web Development Using PHP by skima(m): 10:43am On Apr 12, 2006
I'm very glad at what have been  seeing so far.

Well i think we should go on, but i will like to post the table of content, so anyone willing to contribute can know the scope at which we want to operate.

[center]TABLE OF CONTENT[/center]

PHP Basics

Whats PHP?
What can PHP do? Installing PHP
Basic Sytax
Variables
Constants
Expression
Operators
Control Structture
OOP

User Interaction

$_POST
$-GET
$_REQUEST

Database Integration
Installing MySQL
Introduction SQL
Creating database
CReating tables
Inserting to database
Viewing/searching the database
Modifying database record
Delete from database

Security

Input filtering
SQL Injection
Securing your data

State Management
Working with COOKIE   
Working with SESSION
Login/Log out page

PHP Email
Sending Email
Sending HTML Email
Personalized Email
Mailing List

File/Image upload
Upload file
Upload image
Assigning link with database

Design Patterns

Frameworks

Applications

User Management System
Mailing List
Tracking System
Content Management System
News Feed
Re: Web Development Using PHP by romeo(m): 10:52am On Apr 12, 2006
i've just imported sql file from php-nuke to myphpadmin, i am slow but what is the next step, because i all need is to do it offline before i go online
Re: Web Development Using PHP by skima(m): 10:54am On Apr 12, 2006
Most of the PHP basics has been covered above, Its advisable for a newbie to read the section very well. If you have understood the basics, lets go on,

@sbucareer
I think you are the perfect person to handle the PHP OOP section giving your knowledge and experience with JAVA.
Re: Web Development Using PHP by skima(m): 10:56am On Apr 12, 2006
@romeo
If you have phpmyAdmin then follow the SQL link and run the sql there.

(1) (2) (Reply)

Why Software/web/mobile Application Projects Fail In Nigeria / Aptech Or University Route? Which Is Better? / Ruby On Rails Developers In Nigeria

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 82
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.