![]() |
|
![]() |
Curriculum Vitae / Introduction / Tutorials and other resources for web and E-Commerce programming! |
|
If you think of working with me, contact me by an email now, and you need to fill up your project needs here. |
Certified expert level of workmanship :-)My approved qualifications for internet applications, and your business: You will need to login as a service buyer. You will find more reasons to satisfy if you work with me. Save your budget. Find an expert level solution. Instant ContactProven expertises in: MySQL Stored Procedures, Regular Expressions, Smarty Template Engine, CURL, Data processing n Sanitization, Debugging (are your projects abandoned?), and high quality programming in shorter time period. Please ask for a detailed information if you needed it. Need a support? Ask me now. Let us discuss it. Professional Community PresenceWatch my forum updates in Smarty. I frequently share my skills at the Smarty Forum. Send your business requirementsPlease post your needs here, and our team will contact you at our earliest. | Home » CV | My Tutorials | My Articles | Glossary | My Photos | Contact Me
The power of PHP for the web: Volume one Power of PHP | Database Connection | Database Class | HTML Spam Filter | Domain Name | Database based *CONFIG* variables | Synchronizing Databases | Mistakes with website dates | Random Users | URL GET Class | MySQL Class | DB to HTML Form | Link Roller Written By: I am happy to receive your PHP codes and put it into this site, under your own name. You can send them in my email. I just want to make this site rich with quality PHP tutorials. PHP fans define it as the future power of the web. Possibly it could be, because the number of users are growing so high that gives a climbing graph since the birth of the langauge. It has many reasons for its popularity. PHP's simplicity counts much more than it is in the open source. Almost all C users find it as a C's friend in many ways; like file processing techniques. PHP is a server side scripting language. Say, you are developing yourself into the website creation, it has many aspects like desseminating the information, the visual appeals that your website offers, and the way you present the contents in your website. But sometimes, you often need to protect your website with the password authentication. That is not done by the HTML or the JavaScript. You definitely require the server side scripting language; and PHP could be your best choice. You would then put a small script in the webpage that would check if the visitor has logged in into your website with the authorised password or not. The web browser like Netscape or Internet Explorer can not detect what the PHP did to protect the website. It is because the PHP does its activities only in the server, and gives something for Netscape. Server side scripting has of course its own plan, and the way it interacts, and has its own limitations and functionalities. Say, one page in your web site has been protected, and the visitor has successfully loggin into your website. But your desgin of the page should not request the visitor each time to login before they can visit the other protected pages. Just the remedy is that, you create a temporary variable common of each pages, and that records if the particular visitor (or the user) has been logged or not yet. We call them SESSIONs for PHP. Storing few information about the visitors is done through the session management, and PHP is very smart to do it. But almost all server side scripting language this feature. Your client (web browser) can never detect what values the PHP stored in its sessions. So, there are the possiblities of creation of protected websites like, checking the email, or buying something in the internet, or taking the online examinations. However, session management is not only the single aspect a server side scripting language offers. Let me talk on one of the most frequently used feature in the website; that is the link that says, "contact us" or something similar. While creating the webpages in such sections, never put only your contact address, phone number or anything else. Better, you create a smaller section in the page that would request the visitors type some message for you. Then, use PHP to send their message to you through the email. And to keep better relationships to your sites visitors, send a thank-you email back to them. That method then interacts with your visitors, without your knowledge. You thus save the time. Sending or processing email is thus another extension eased with PHP. Your "contact us" page should be able to read what the visitor has just typed for you. You should not miss their words, as they may be beneficial for you in any way. To keep their emails, you save them temporarily into some simple simple text file, or in the database, or just email that to you. Just reading the contents typed in the browser's area is another feature that PHP should be responsible off. Normally, you create the message typing area for your visitors using the <FORM> and <TEXTAREA> tags of the HTML. The visitor then sends by pushing the "Send email" button. Your PHP file then collects the visitor's information, and determines what to do, like send that content into your email or save into the server's file. In the technical language, it is called as the Form Processing. Simple HTMLed pages will just show your presence in the website. They can just give your information only. They never can collect the ideas or suggestions from your visitors. So, you MUST use some dynamic style of maintaining your website, like collecting the visitor's information throug the email, and sending them a thank-you email in response. Thus, they will not forget your site, because they have just received your email. Command the PHP to respond to your visitors. Sometimes, you may need to know at what range your web site has been visited? How do you know that? It is the statistics, or is it not? To help you, your website hosting company will let you access a log-file for your website. But this information too tedious to understand correctly. Instead, you just can create a PHP script that would recond the IP addresses used to connect to your website, time of page visit, and the particular web page in your site visited. Writing your own PHP script may be better than going thorugh the log-files that you are provided by your web hosting company. Because, only you can format the information in the way you require it. To to all of those things, PHP is a better programming toolking and HTML generator for you. It has its programming environment similar to the C program, and is very easy to master it within a short period of time. But the quality depends on what you are doing with it, and how you are doing it. No documentation of any language describes how to solve your problem. It should be your way of utilising the features provided by the PHP. To examplify you, WorldLink has a PHP interface to check your email while Amazon uses it to sell items online, and some banks use PHP for the application in transfer of money. There are no any certified institutes to train PHP, but many are traing it. But the better way could be that, you download a html-zipped documentation from www.php.net, and go yourself. Also, please visit the developers' websites for PHP, read their articles, analyse their example source codes, and use them in your own. The minimum requirement for a PHP is a webserver installed and configured to use the php files. Your page in your website contains both the HTML and PHP program code, but while you fetch the page from web browser, PHP parses the page and gives your browser (Netscape or any other, the only HTML code). I suggest the Xitami application for your web server, and will tell you why. If you use it yourself, you will know it why. In the comming issues, I will relate PHP with database handling, and then direclty creating the webpage the way you want it. Further, I will deal with the tactics in the common programming for the PHP. Wait the other print version, or just email me. Before quitting, here is a smaller discussion with the silly programming I had to optimize once, and habituated in newer kind of programming. This example is about the if/then(else) optimisation. The below program is printing two radio buttons with a marital status of a man. Generating a radio button is a work at HTML, and looks like: <INPUT TYPE="RADIO" NAME="marital" VALUE="YES"> Married Have you noticed something? First, the names of each radio buttons are similar. One is containg value "YES" and other "NO", and by default the later one is clicked (checked/selected). One man can not check the both radio buttons. So, the name is common to them, "marital". But our issue here is to determine which button to select (CHECKED status) by default, based on the value assigned to a person. First we read from the database, if a person is married or not, and then generate two radio buttons, and ONLY ONE of them has CHECKED staus. Many programmers solve it with PHP as: <?php $married="NO"; if($married=="YES") ?> # We are not capturing the last 'else' here, to shorten the example
Okay, that solves the problem correctly. And results are as expected too. But I see some toughness in the programming habit. Why? Because, the programmer has written a common thing twice in the page design, and if any futher modifications are required, it is harder to fix in 4 times. But with a better knowledge, we can shorten it to only two lines of real logic! How? Think it yourself before moving to read below. The problem is that, the above code in PHP is expressing YES and NO, and CHECKED in two places. And that is my headache too. See, the value of the YES or NO are commong from a variable named $married. A null character ( ) has or "CHECKED" is printed, and one of them at a time. Our solution to this case is now simpler to deal. Let us check the $married variable with "NO" or "YES" with if(). It gives either "true" or "false" only result, and both of them are not possible. While comaring, if($married=="YES") the result is "false", and if($married=="NO") is "true", if $married was "NO". And you should know that a false represents 0 (zero) and a true reperesents 1 (one). So, let us now make one more variable in array data type whose false (0) index contains a null character ( ), and the true part contains " CHECKED". Notice that there is a SPACE character before the word CHECKED. It is normally done as: $checked=array(); # Not required, define it to be an array Now, below is the re-coding of the above example: <?php $married="NO"; print(' <INPUT TYPE="RADIO" NAME="marital" VALUE="'.$married.'"'.$checked[$married=="YES"].'> Married' ); ?> See, how smartly this code gives the natural way of programming? Actually, we are printing only two radio buttons for selecting Married or unmaried. But in the above case, the two lines were written unnecessarily, and the later code should be better enough. There is a only logic that the variable $married can contain only value, either "YES" or "NO" only. So, only one of the line can read the value from $checked to be " CHECKED" for the radio button. Actually, the $married=="YES" or $married=="NO" just returns true (1, valuing $checked[1]=" CHECKED") or false (0, valuing $checked[0]="", a blank character). Even, we have not written the if() explicitly in the code. But be careful to use such program codes because most frequently, you will encounter errors you made them yourself, NOT BY PHP! So, learing PHP and solving your problems are two different aspects of designing the dynamic websites. This case is true even for the cometetors of the PHP. Okay, see you in the other version of my tutorial. Bimal Poudel |
| website and the contents unless speficied are owned by - Bimal Poudel.
All rights reserved. This website contains personal materials. Contact Me. Last modification: 2007-03-05 05:30:02 |