Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,154,341 members, 7,822,616 topics. Date: Thursday, 09 May 2024 at 01:53 PM

Web Development Using PHP - Programming (2) - Nairaland

Nairaland Forum / Science/Technology / Programming / Web Development Using PHP (6968 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)

Re: Web Development Using PHP by romeo(m): 10:58am On Apr 12, 2006
ok i'll do it now prof grin
Re: Web Development Using PHP by skima(m): 10:58am On Apr 12, 2006
As i said that  I will commence the tutorial on Wednesday, I hereby start the tutorial. i now know that there are "Guru" on this forum owning to what i just saw you guys demonstrating.

As our topic connote above "web development using PHP" we shall employ a strategy called " Learning by example". This strategy was employed on this forum by his eminence "sbucareer". Since our purpose here is to develop website with PHP, we shalldevelop web-application while learnign PHP, we shall cover PHP/MySQL and develop the following application;

Guestbook like the one http://unleashedsolution.com/sheriff/guest.php

A CMS like the one here http://coreturstinvestment.com  

And mailing List/User management

We will cover :
file upload
PHP Security
Input filtering
PHP Email
State Management

First and the most important is "echo" as discussed above, thats just what it is, we use echo to print the screen. as in javascript : document.write("Hell World"wink;

Any data you collect, any action you perform will need to give the user feedback, thats why is very important.

[size=20pt]User Interaction[/size]

Let's now go over to the others ones, $_POST,$_GET,$_REQUEST,$_COOKIE AND $_SESSION this are called "Global variables" thats they exist and can be reference from any where in your script (we shall discuss more on global variable in the security section). We shall look at the first three variables and later in this tutorial we will touch others.

Working  with HTML you will notice something when dealing with forms, which are form methods (i.e method="POST"wink. Now you will know the essence. The guys behind php  are highly intelligent in the sense that most functions you will be working with hav ebeen developed to be remembered while coding. The Above variables are used to retrieved data from forms. So when ever you set your form methods to POST, the variable to retrieve the form input is $_POST;

Example: save as post.php

<form method="POST" action="">

<p>Name <input type="text" name="name" size="20"><br>
<input type="submit" value="Submit" name="B1"></form>
<?php
echo "My name is ".$_POST['name'];
?>


This example prints: "My name is SHERIFF" to the screen, where SHERIFF is the data entered to the form input. You will notice that we have added braces to the $_POST variable, you wonder why uhn? I will tell you. When you are building your fomrs, you will remember that name differentiates the forms so that is why we requested for the name o fthe form variable. In this case the name for the variable is "name" (i.e name="name"wink.

So, this process is followed for $_GET variable, for you use the $_GET variable, you must set the form method to get (i.e method="GET"wink.

$_REQUEST works for either form method (ie both method="POST"  and "GET"wink. If you set your form method to GET or to POST, you can retrieve the data with $_REQUEST. When it comes to data security, the integrity of data retrieved from $_REQUEST is questionable in the send that the $_REQUEST could also retrieve data sent from COOKIE. So I will advice to always use POST when you set your form method to Post and GET  for Get method.

Note:to be continued,
Re: Web Development Using PHP by sbucareer(f): 7:49pm On Apr 12, 2006

Well done Skima, very good. Thanks for helping out. As you have enumerated on the content page I would like every chapter to have its content written in bold i.e

[size=24pt]OOP[/size]

I will modify my pages to reflect your content tables.  Nice work Skima. He who teach learn more.

Re: Web Development Using PHP by sbucareer(f): 8:10pm On Apr 12, 2006
[size=24pt]OOP (Object Oriented Programming)[/size]


What is Object? (1) A computer representation of something that a user can work with to perform a task. An object can appear as text or an icon. (2) A collection of data and member functions that operate on that data, which together represent a logical entity in the system. In object-oriented programming, objects are grouped into classes that share common data definitions and member functions. Each object in the class is said to be an instance of the class. [1]


If you study the above definition, you will deduce that Object is simply a Class. You may want to ask now, What is a Class? Well, a Class is a group of varibles, functions, and static field put together into one file called class, so that developing application would be easier.

The major problem in software development is reusing the same function over and over again without you knowing. Imagine that in your web application, you have a page that allows someone to login and in another page you want a login solution, you would have coded two different login pages without knowing it, which is a waste of time. Beside you can introduce bugs into your application.

But if you have written it in an OOP way by writing a class called Login and call it as many times as you want in the application without having to re-write it all the time. Beside it makes your application development fast.

API's in all programming language are Objects, which can also be called class. It encapsulate repeated task so that you do not need to write it all the time.





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

I will not go into teaching classes without introducing first, function(s). A function is a particular task in a program language that only that block of code knows how to carry that task(s) out. Why do we have functions. Instead of repeating yourself all the time you could write a simple task and put it into a function and call that function as many times as possible, ie.

Let say we are writing a game application and we want to tell winner a Congratulation message everytime they win. You could either do it this way all the time


<?php

     echo "Congratulation you have won the race";
?>

or

function win (  $message ){
  echo $message;
}

and use it in your application like this win("Congratulation you have won the race"wink; it is elegant and simple for maintainenace issues. But it saves your doing this every time


<?php

     echo "Congratulation you have won the race";
?>

This is just a simple example believe, you code will get big and complex, re-writing all the algorithm you have written before is not funny.

To write a function, you simply use the PHP reserved name function followed by the function name with a paranthesis and openning brace and closing brace i.e.

function functionName(parameter is optional){
}

parameter is when you want to pass the function some information within the application. Say you are designing a shopping cart. The customer select and add the books to a shopping cart object, the object would be passed probably through a function parameter into checkOut object to calculate the shopping cart .

There are two types of function

1. Accessor
2.  I can't remember the other one

But in Java it is called getters and setters. Basically Getter return information back to the calling object while setter do not, they change the behaviour of the function by changing the value of the function variable(s). We will cover this in a little while.

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

Function can contain variables and they can hold object reference and many other thing. Like I said before programming is the manipulation of variables, simply. No long sorry. If you cannot understand what is variable, then you should condiser a course on Needle work.

Variable hold states and information. Informations like age, sex, address and account balance. Now, if I can get you address from an application I can manipulate this variable that holds your address the way I like.

I can present it this way, say your address is  1 Nairaland, Lagos, Nigeria.

1. 1 Nairaland, Lagos, Nigeria.
2 1 Nairaland, Lagos, Nigeria.
3.
1 Nairaland, Lagos, Nigeria.

You get the gist. I can change it any way I like and that is programming my brother.

Because variables are little locations in the actual physical computer memory, they are volatile that is why we employ database to persist it. Variables, Objects do not live after the power or computer goes off. They die unfortunately. So if you are writing application and you want to remember somebody when they come back to you site like Nairaland, you need a database.
Now, that we know more about variables and functions, won't it be nice if we can package them together into one file and call them when we need them.
Re: Web Development Using PHP by sbucareer(f): 9:35pm On Apr 12, 2006

Now, the father of every OOP, the class. Class encapsulate all the variables and functions a particular application uses. It helps to reduce re-writing code, bug free and faster application development by employing code resubality.

To write a class we use the reserved PHP word class i.e.

<?
class NairalandWebApplication{

     Variables and function goes here


}//End NairalandWebApplication
?>

Notice something it uses class after ? not php, that is how you can tell class file from PHP file.  Let say we want to write a class that holds username and password to login to our site. We had create a variables that will hold username and password and provide a function to authenticate the user. We could add other function we want to use in that particular application.

If we were developing a shopping site we could also have a function called calculateShopping, paymentProcessor, sendInvoice etc.


<?
class ShoppingApllication{

        $username = "visitor";
        $passwd = "letmein";

        function login ($username, $password){
           if ( ( $username eq "visitor" ) &&
                ( $passwd    eq  "letmein"wink ) {
                       header("Location:http://localhost/main.php");
                        exit();
            }//End if
         }//End login function


          function calculateShopping ( $ShoppingCart ){
             
            $_tempCalculation = $ShoppingCart ; // Mind you shoppingCart is an Object
            $_quantity = $_tempCalculation.getQuantity();
            $_price      = $_tempCalculation.getPrice();

           $_total = ($_quantity * $_price );

            return ($_total );
         }//End calculateShopping



        ,  // Other function





      ,  // Other function
}//End ShoppingApplication
?>

Now we have created a class called ShoppingApplication. How do we use it in an application? When you are writing a PHP script within a web application say HTML. You can do two things.

Use <?php -----------?> to render your sturf straight away to the web UI and use this <? -------------?> to import or include your external PHP files like the class file we created. So in our php file we will have some thing like this


<?
  include "ShoppingApplication.php"
?>
<HTML>
<HEAD>
   <TITLE>OOP IN PHP</TITLE>
</HEAD>

<BODY>

<?php
             //Create new Object of ShoppingApplication.php
             $instance = &New ShoppingApplication;

              $instance.login( $_POST["username"], $_POST["passwd"] );
?>

    <FORM name=id Method=POST Action="">
     Username: <INPUT TYPE=text name=username><p />
     Password: <INPUT TYPE=password name=passwd>
    <INPUT TYPE=submit value=login>
   </FORM>

</BODY>
</HTML>

             
Re: Web Development Using PHP by sbucareer(f): 12:17pm On Apr 13, 2006
[size=24pt]DataBase Integration[/size]

[size=18pt]Installing MySQL[/size]

MYSQL is a transactional relational database management System (RDMS). Many people do not understand the license governing MYSQL. Most people think that MSQL is free. Well it is if you are using it for yourself and learning purposes. But if you plan to make money with it, you need a separate license for it.

The official MYSQL site is  here. There you can download many different version of MYSQL. But this tutorial will be using version 4.1 or else someone object.

Download the binary for windows since I have mentioned earlier that the tutorial would be for window users. Most people using some flavor of Unix are well advance and can download and install it themselves without issues.

Save the binary to a location i.e. c:\temp go back and execute it and following the default installation wizard. If you do not know anything from the wizard just leave it and click next and next to complete the installation. Remember to remember you username and password.

If you can understand the wizard change some default setting to suit yourself. When you have finished go to your start, program files, MSQL, MYSQL Server 4.1, MYSQL Command Line Client. Enter your password and you are in.

Re: Web Development Using PHP by HotCoCo2: 4:55pm On Apr 13, 2006
I am having trouble downloading tomcat. can someone send me a zipped version of theirs. i visited the link but cant get to download.
Re: Web Development Using PHP by sbucareer(f): 10:36am On Apr 14, 2006

Hot_CoCo, I have the executable binary if you want it, visit yexon, username: visitor and password: letemin. Go to Tomcat and expand the link and download it. I have about 1.3Meg upstream it should be enough for you assuming you have a fast downstream from your ISP. It will take you just 10 minutes

The most important directory in tomcat is conf, and the most important file there is the server.xml. Be careful modifying this file any xml typo will make the server not to start.

Where you put your HTML files for the server to render is webapps. Any folder you create in there i.e. school MUST have a folder called WEB-INF and within WEB-INF MUST have a web.xml file

+apache tomcat
   +webapps
       +school
           +WEB-INF
                 web.xml
         index.jsp

To access the file from a URL, you do this http://localhost/school/index.jsp assuming you are using port 80. You can change your port number from server.xml configuration file.

Find this section in your server.xml and change to any desired port number and restart the server

<!-- Define a non-SSL Coyote HTTP/1.1 Connector on port 8081 -->
    <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
               port="80"
               minProcessors="5" maxProcessors="75"
               enableLookups="true" redirectPort="8443"
               acceptCount="100" debug="0" connectionTimeout="20000"
               useURIValidationHack="false" disableUploadTimeout="true" />


A good place to start learning the Servlet engine is the server.xml configuration file. Study it and understand what is going on in the server, then you would be able to understand the folders and where to put you files and classes.

If you are creating dynamic web page you need a directory called classes under the WEB-INF i.e.

+WEB-INF
   web.xml
   +classes
    +lib

To map your classes into your application need to configure the web.xml in you application context i.e.


<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">


<web-app>

               <servlet>
<servlet-name>Controller</servlet-name>
<servlet-class>com.org.lis.Controller</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

                 <servlet-mapping>
<servlet-name>Controller</servlet-name>
<url-pattern>/controller</url-pattern>
</servlet-mapping>
</web-app>

You can see in this application I have the Controller.java mapped to /controller. So in many application I would do

<HTML>
<HEAD>
    <TITLE>WEB APPS</TITLE>
</HEAD>
<BODY>

<form name=id method=GET action="/controller">



</form>
</BODY>
</HTML>


Good luck
Re: Web Development Using PHP by sbucareer(f): 11:04am On Apr 14, 2006

Sorry folks, back to PHP tutorial.
Re: Web Development Using PHP by Papa(m): 4:08pm On Apr 15, 2006
Welldone, SBUCAREER,

Hi Folks,
Here's a quiz question to those who think they know more than their fathers. . . like this page right? When retrieveing getting data from a database,
How do you split the information into pages instead of having one endless pages for users to scroll down through. . ?

Ever Loving Papa
Re: Web Development Using PHP by skima(m): 6:53pm On Apr 18, 2006
You use limi in your SQL query.

e.g

$sql=mysql_query("SELECT * FROM my_table LIMIT 10"wink;

This will retrieve 10 record from the DB. so if u want limit and break into multiple pages u add some code to determine the offset .

see here http://unleashedsolution.com/sheriff/guest.php?view=1

and u will see ao it works there.

Gud Luck!
Re: Web Development Using PHP by Papa(m): 11:51am On Apr 19, 2006
Thanks that was quite helpful, but what I really need is the code after that limit command sent to the database.
The link you sent takes me to some funny black page that has the result, but I'm looking for the code, wink
Re: Web Development Using PHP by skima(m): 1:26pm On Apr 20, 2006
hmm,  I have the code, Iwill post it when i got to my admin panel.
Re: Web Development Using PHP by my2cents(m): 6:20pm On Apr 20, 2006
I humbly propose honorary phD degrees for the authors of this tutorial.

Well done, If one just wants to know the basics, definitely cheaper than buying a book cheesy
Re: Web Development Using PHP by smartsoft(m): 4:21am On May 24, 2006
how many lecturer do we have in here ?
Re: Web Development Using PHP by smartsoft(m): 6:03am On May 24, 2006
hummm since we have 2 lecturer's on board then i'm supose to be the Class Governor lol. My duties are to summit Materials for Lecture right now you can download tutorial on PHP, it all you what to know about PHP 6.54MB or there about,  Upto 500+Pages so better be read to crack your brains,  we more lectures, i provides some other materials please if you can get this Tutorials, just mail me uc.smartsoft@gmail.com and i will forward it to you ASAP. or better still click this link http://smartsoft-ng.com/ebook Username : free Password : ebook
Re: Web Development Using PHP by skima(m): 1:58pm On May 30, 2006
Am willing to continue this tutorial. av been quite busy.
Re: Web Development Using PHP by smartsoft(m): 11:56pm On May 31, 2006
well i'm willing to give out Materials too for free on PHP/MYSQL worth of $30 each which is the amount they bought. about 500pages on PDF closly upto 6.1MB
Re: Web Development Using PHP by skima(m): 7:21pm On Jun 01, 2006
@smartsoft make sure u protect copyright.
make sure u distribute legal material
Re: Web Development Using PHP by smartsoft(m): 8:07pm On Jun 01, 2006
skima:

hummmmmmmmmmmmmmmmmmmmmm
Re: Web Development Using PHP by LiquidMind(m): 10:55pm On Jan 23, 2007
shocked
Re: Web Development Using PHP by datoms: 9:10pm On Sep 11, 2015
Please email me to get complete php web development course and other related materials or you can as well click here
https:///pdM4wL
Re: Web Development Using PHP by 2Awesome: 1:19am On Sep 19, 2015
thank you for including OOP. that is the part i have been struggling with.
Re: Web Development Using PHP by johnpao: 7:22am On Aug 16, 2020
What is the future of PHP Language. Means there are a lot of new technologies come in market that work for both website and mobile application development. I am a starter and confused. Should i have to continue with PHP or change my field. Please help me out. Thanks

(1) (2) (Reply)

How To Build A Snakes And Ladders Game With C++ (no Gui) / Algorithm And Data Structure Study Section / Why Software/web/mobile Application Projects Fail 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. 86
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.