DirectorySoftwareBlog Details for "Learning Computer Programming"

Learning Computer Programming

Learning Computer Programming
I post articles mostly on Learning Computer Programming in general and specifically using C plus plus. This blogsite is created as a part of my hobby of computer programming, I also share my experiences in a teaching manner.
Articles: 1, 2, 3, 4, 5, 6

Articles

Creating a ?Contact Us? Form (E-Mail Version)
2008-05-04 08:17:00
This is a short follow-up of the last post Creating a Simple ‘Contact Us’ Form in PHP. In the last post we discussed how we can create a simple contact form for our website. That surely will give visitors an easy way to contact you. But I guess many of you would be thinking that it’d have been better if contact form could just send emails. If you are one of them, keep reading! To be true guys, PHP gives us a dead easy way of sending emails from scripts, thanks to the mail() function. mail() function in its simplest form has the following prototype: bool mail(string to, strin g subject, string msg); Here, to- email address, mail is to be sent to subject- subject of the email msg- body of the email For our contact form, we’ll have to give our own (or whoever the webmaster is) email for the ‘to’ argument (since we should get the messages sent form the form), ‘subject’ can be anythin...
More About: Mail , E-Mail
Creating a Simple ?Contact Us? Form in PHP
2008-05-03 12:00:00
If you’ve a website, giving your visitors a way to contact you is very important. The easiest way for you would be to just give your email address but for the visitors that surely won’t be an easy method. A more sophisticated method would rather be a ‘Contact Us’ form, yeah just like those you see on many websites. A contact form generally asks the visitors name, email address and message they would like to send to the webmaster of the website. In this post, we are going to create a simple contact form, which you can even integrate on your own site. For the ‘Contact Us’ form, we need to create two different files. First one will have the HTML form and some text boxes to collect the information form the visitor, second, the PHP script to receive those information and write it to a file for the webmaster to see. For this project, we’re writing the information sent by the user to a file which you should be checking...
More About: Creating , Simple , Form
Designing a Simple ?Quote of the Day? Script in PHP
2008-04-30 08:51:00
Quote of the Day” is quite an old feature, people put on their sites. And of course people like it; I mean who doesn’t like to know the sayings of great persons! In this post we’re going to design a complete quote of the day system to place on our web site. The title is a bit misleading actually, because most of these types of scripts show a new quote (randomly) each time the page is requested and not once a day. So if you incorporate this script on our web site, you’d see a different quote each time you reload the page. You may easily change it to “actually” display different quotes for each day only but people like that random one! The working of the quote scrip is pretty simple. We first store a good number of quote in an array (here we’ll just be storing a handful as an example). Generate a random number from 0 to NUM_ELEMENTS_IN_ARRAY-1 and just show the quote from the array with that index. Here ...
More About: Designing , Quote Of The Day , Script , Simple
Arrays and Array Processing in PHP
2008-04-30 08:43:00
Arrays are a set of variables of the same data type. If you’ve ever programmed before you should be knowing about it. but PHP takes arrays to the next level by providing so many useful in-built features to operate on them, let’s see some of them. Types of Arrays You should be familiar with the following type of array: $ar[0]=1; $ar[1]=10; It is an example of numerically indexed array since numerical values are used as indices to reference different elements of the array. One other type of array that PHP supports is those having string indices which sometimes may make indexing more meaningful. $temp['jan']=21; $temp['feb']=23; $temp['mar']=24; This type of array is also called Associative Arrays. As is obvious, the array above should most probably be having temperatures of different months. Had it been numerically indexed, it wouldn’t have made that much sense. So you can use these types of arrays to make indexing ...
More About: Arrays , Array
String Manipulation functions in PHP
2008-04-29 15:42:00
In the previous post Properties of String in PHP, we were discussing about the different properties of strings in PHP. String manipulation as you know, is an important part of web programming. PHP being a web programming language thus provides good set of string manipulation functions. In this post we’re going to discuss some of those which arte frequently needed. 1. trim() function Prototype: string trim (string str); This function strips white spaces from the start and end of the string supplied returning the resulting string.. When we have to take user input via form, it’d be a good idea to “trim” the variables as extra white spaces sometimes creep in. $name=trim($_GET['name']; 2. explode() function Prototype: array explode (string sepa rator, string input, int&n bsp;limit); The argument “limit” is optional. This function splits the string “input” on a speci...
More About: Functions , Strings , Manipulation
Properties of String in PHP
2008-04-28 08:25:00
1. String s in PHP can either be enclose in single quotes (‘) or double quotes (“). $str=?Strings in PHP?; $str2=?PHP?; both of the above are valid strings in PHP. 2. Two strings can be concatenated or joined together with the help of the “.” Dot operator. $str=?I Like ?.?PHP?; $str2=$str.? a lot!?; Now, $str will have the string “I Like PHP a lot!”. 3. Guess what the following code will print $str=?String?; echo ?This is $str?; I bet many of you thought that it’d print “This is $str”. But actually it is going to print “This is String” because variables inside (“) double quotes are evaluated in PHP. If we had used (‘) single quotes for the string like: $str=?String?; echo ?This is $str?; It’d have printed “This is $str” as variable inside (“) single qu...
More About: Properties
How File Processing is done in PHP?
2008-04-27 08:29:00
In the previous post’s (Designing a Simple Order Form Application in PHP) example we implemented the file I/O for storing order information without discussing about it. For those of you who were eager to know more about PHP File I/O read along, this post has it. File processing requires the following steps: Opening a file Doing the operation Closing the file Opening a file First of all we have to open the file before any operation (reading/writing) can be done. If you remember the previous post Designing a Simple Order Form Application in PHP, we had this line //open file $fp=fopen("orders.txt","a& quot;); There we’re opening a file named “orders.txt” in the “append” file mode. File modes tell PHP what we want to do with the file. Some of the commonly used files modes along with what they mean is listed below: r For reading only, reading begins from the start of the file r+ Readi...
Designing a Simple Order Form Application in PHP
2008-04-26 18:22:00
Ok guys, for this post we’re going to create a simple yet complete order form page. Order forms are used on many sites to take customers order online. Order forms should have the capability to take orders from visitors regarding what items they want to purchase and store the information for further processing. For this post’s example, we are going to create an order form for a Book Seller. The form will be designed to take order of five different items (books). Our order form application should be able to take order of five different items in any separate quantities tht user wants, it should also ask for shipping address and name of the customer. It should then store the information provided in a file along with the date and time order was placed. The application should also be able to take any number of orders and store them all linearly for further human processing. For this, we need a front end of a HTML form to which the user would inter...
More About: Designing , Simple , Application , Form
How does CMS Create Dynamic Pages II
2008-04-26 12:12:00
This is the continuation of the last post How does CMS Create Dynamic Pages . If you run the script given on that post (save it with the name “cms.php”), you’d see a site like below: As you can see, it’s a simple five page site of which all of the five pages are available (only 3 are shown in the image though). Isn’t it amazing for just one PHP script to create a five page site! If you look at the code and try to understand, you see that the script is designed to show the Homepage when no data is passed. It creates different pages from the data in the arrays when the respective page is asked for, by passing p=0 to p=4 to the script. We can create 10, 20, 100 or even a 1000 page site like this just from one script. In fact most CMS do that. Do remember however that the array storing the content was just to depict the database and real sites would store content in database. Did you notice the line $page=$_GET[‘p’]; ...
How does CMS Create Dynamic Pages
2008-04-25 19:41:00
Content Management System (CMS) gives you an easier way to manage sites. It gives you a nice front-end to write, publish and manage content while hiding the technical details like FTP, HTML and other coding work. Most of the CMSs have a web based front-end that means you can manage the whole site from within the browser. Some examples of popular CMS are Joomla, Wordpress etc. One major characteristic of CMS is the fact that it creates the whole site dynamically, it means most (if not all) of the pages that the site has, are created dynamically. Conventional way of creating site was to create different HTML pages for each article (page) the site has. Contrary to that most CMS don’t create different files for pages. They store the content in the Database and create the pages from the Database. That means the content don’t reside in pages or files but rather in the Database. In this post we’re going to create a simple system that will hel...
More About: Pages , Create , Dynamic
An Example of User Authentication System in PHP II
2008-04-25 08:38:00
This is a short follow-up of the last post An Example of User Authentication System in PHP. In this post we’ll talk about the two methods of from sending GET and POST and how thy affect the way data sending From the previous posts example, when we provided the username and password and clicked on submit, we saw something like this: If you look at the address bar, you can see the data (username and password) being sent. Now, that’s not a good thing, if we are using a password box to hide the password being entered then what its use is if it can be seen this way! The good thing is that with very few modifications, the data passed can be made invisible (not to appear on the address bar). How? By using POST method of data sending for the HTML form. It can be done like below: <html> <head> <title>Simple Uesr Authentication System</title> </head> <body> <form name="form1" method="...
An Example of User Authentication System in PHP
2008-04-24 19:05:00
In this post we’re going to create a very simple user authentication system in PHP. It’d be like the one’s you see while logging in to various sites/services (emails, forums, social networking sites etc) User authentication is a way for sites to know who you are among the other registered users and showing you relevant content (may be confidential). For example it’s only you ho is authorized to see your emails because you only know your authentication information. In this post we’re going to create two files, a HTML page which will collect the username and password in a form. These information will then be send to a PHP script, which will verify and show the required information. Below is the PHP code: <?php //define some constants define("USERNAME", "goodjoe"); define("PASSWORD", "123456"); define("REALNAME", "Joe Burns"); //have the data being passed ...
More About: System , Authentication
Taking User Inputs to Create Personalized Pages II
2008-04-24 11:57:00
HTML Forms are a method of sending information from a page to a script. Forms in HTML have the following form: <form name="form1" id="form1" method="get" action="script.php"> </form> here, name=”form1” is the name of the form, may be anything id=”form1” is usually same as the name of the form method=”get” is the method by which sending of data will take place. It can also be “post”. action=”script.php” is the name of the script to which the data is to be passed to. A form can have many child elements such as input box, password box, check box etc. a form almost always has a submit button which on clicking sends the data entered in various elements of the form to the “action” script. We’d created the script in the previous post Taking User Inputs to Create Personalized Pages , so we need not work on that, here we&#...
More About: Variables
Taking User Inputs to Create Personalized Pages
2008-04-23 16:17:00
You might probably have seen this type of URLs: http://somepage.com/index.php?name=noname &age=18 It of course is a dynamic web page. As a matter of fact the string after the ‘?’, the data, is what makes it dynamic. The page is dynamic because most pages which take data this way, create the page according to the data passed. In this post we’re going to see how pages take data, we’ll also create a simple dynamic page which can be personalized to display user’s name. First, let’s understand what is in the URL http://somepage.com/index.php?name=noname &age=18 index.php is a PHP page and everything after the ‘?’ is the data being passed, which is name=noname&age=18 here name and age are the two variables having the values noname and 18 respectively which are being passed. Each variable is separated by a ‘&’ sign. That’s it; now let’s see how we can catch these variables from...
More About: User , Variables , Pages , Create , Taking
Variables, Type Casting and Constants in PHP
2008-04-23 09:14:00
Let’s start by looking at the fundamental difference between variables in PHP and in C++: Variables in PHP need not be declared before using Variables can hold any type of values due to the fact that variable are not declared of any type, you can store any value in any variable no matter which type of value it is currently holding. So, in the previous post (Conditional Statements if...else in PHP) when we needed a variable to hold the integer (hour of the day) we just wrote $t=(int) date(“G”); and suppose we now want to have a string to be stored in $t variable, we’d just have to write $t=”PHP”; You see, in the first statement it was an integer variable but now it’s a string. Therefore we can conclude that the type of a variable is determined by the value currently assigned to it. PHP has the following types of data: Integer Float String Boolean Array Object Since PHP take...
More About: Type , Casting
Conditional Statements if...else in PHP
2008-04-21 18:29:00
Look at the following code: <?php $t=(int) date("G"); if($t<12) echo "Good Morning!"; else if($t<17) echo "Good Afternoon!"; else if($t<21) echo "Good Evening!"; else echo "Good Night!"; ?> If you are a reader of this blog (or know C++!) then the code would look familiar. As is obvious, that is a PHP code but looks similar to C++. You see, the if and else statements are all similar to that in C++. Talking about the code, it is pretty straightforward, we are taking the current time, type casting it to an integer in a variable $t (type casting is also done in the similar manner in C++). Then we are printing different messages according to what the current time is. That being clear, let’s us look at the working of date() function a bit. We’ve previously used date function in the post Writing and Running PHP Scripts. As I explained, it takes a string as an argum...
Configuring Apache Web Server and PHP
2008-04-21 12:20:00
[Update: You may download the MSI package of PHP instead of the ZIP one which would do all the set-up and configuration itself and you wouldn’t have to do the following by yourself] This is the crucial part guys, first I start off with giving the locations of the configuration files of Apache and PHP. Apache: [X:…]Apache Software FoundationApache2.2confhttpd.conf PHP: [Y:]PHPphp.ini-dist [renamed to php.ini later] Now let’s start guys: 1. Start by backing up both the configuration files, you’d need them in case you mess up the files. 2 .Rename the php.ini-dist file to php.ini 3. Look for a line like below doc_root and make it look like doc_root =[X:…]Apache Software FoundationApache2.2htdocs be sure to change ’[X:…]’ with the location you installed Apache server in. Save the file. 4. Open the folder you installed PHP in. There you’ll see lots of DLL files, select them all and click cop...
More About: Web Server , Server
Installing Apache and PHP on your PC
2008-04-20 15:35:00
So you want to install web server on your own computer and have downloaded Apache and PHP. Please read Installing Web Server on your PC first, if in doubt. Installing Apache web server Installing Apache is a no-brainer. It is just as you install any other software. Run the set-up, feed the information in each step and click finish to install. It is a 4-5 step installation and wouldn’t take much time to get installed. Be sure not install it as a Windows Sevice (default option). After installation, fire-up your favorite browser. Type in http://localhost or http://127.0.0.1 (both refer top the local server) in the address bar and press enter. You’ll see a welcome page stating that your installation was successful. If it doesn’t show up, go to Start->Programs->Apache HTTP Sever->Control Apache Sever->START. Installing PHP Installation of PHP is too, straightforward but to integrate and configure it to work with Apache is a ...
Installing Web Server on your PC
2008-04-20 08:08:00
Why install web server on your own PC? Running C++ programs or finding error (syntax) is as easy as clicking on the Compile button but that is not the case with PHP. You have to first upload the script file to the server to run it or to find any errors. As with anybody, peoples make lots of syntax mistakes in the beginning when they learn a new language. So sending back and forth scripts from your PC to the server every time you forget a ‘;’ here or a ‘,’ there via FTP is not something many would like to do. If you have a server set-up on your own PC then it’s as simple as copy and paste, there would be no need of FTP or anything of that sort. Write the script, put it in the special folder (created by the web server) and there you are. This is by far the main reason that makes people install web servers on their home PC. What does installing a web server do? Nothing, in the sense that your PC runs the way it used to. It in...
More About: Apache , Web Server , Server
Writing and Running PHP Scripts
2008-04-19 11:48:00
We’ve been talking about PHP for 2 days now; we even wrote a simple PHP script and understood its working. Now comes a big question, “How do we write and run PHP scripts?”. Do we need some special software to write PHP code? How do we run these scripts? Let’s know the answers! Writing PHP scripts You don’t need anything special; really, plain old Notepad would do just fine. PHP is an interpreted language hence code remains as it is (not compiled) thus any plain text editor is fine. Although syntax highlighted text editors would be better. If you are using a word processor instead, be sure to save the files as plain text files and not in the proprietary formats. Notepad, as I said may be used but I don’t recommend using it, instead use code editors like Programmers Notepad, Notepad++(really great, supports numerous third-party plug-ins)that have syntax highlighting feature. That would make you easily understand th...
More About: Running , Scripts , Introduction
Introduction to PHP Part III
2008-04-18 13:49:00
Please read the post Introduction to PHP, How to Insert Dynamic Content on WebPages, if you haven’t already. Below is the code snippet from the previous post. <html> <body> Date: <?php echo date("H:i A, jS F Y"); ?> </body> </html> I’d like to state the following regarding the above code: PHP code starts with a <?php and ends with a ?> tag. Though PHP supports some other tags (depending on the configuration) which signify the same but these are the most widely used and are guaranteed to work on most servers. You can have any number of <?php …?> blocks in a file. In PHP too, like C++ comments are written using // (single line) and /*…*/ (multi-line) symbols. Besides these one more symbol i.e. ‘#’ symbol can also be used for single line comments. No need to bother about the arguments passed to the date() fun...
More About: Part
Introduction to PHP, How to Insert Dynamic Content on WebPages
2008-04-18 08:32:00
In the last article Introduction To PHP, The Web Programming Language, we talked about what PHP is and what it is used for. There we talked about the Dynamic insertion of date & time on web pages. Well, in this post we’re going to ACTUALLY create page that displays current date & time. We’ll also briefly talk about how PHP pages are handled by the server and the browser (client). Let’s get started! Suppose we have the following: <html> <body> Date: 06:00 AM, 18th April 2008 </body> </html> Above is a simple HTML code (some tags are intentionally left-out) No matter when and how many times you run it, you’d see the same output (date and time), since it is a static HTML page. Now have a look at the following <html> <body> Date: <?php echo date("H:i A, jS F Y"); ?> </body> </html> This is a HTML document having embedded PHP code. As I said PHP can...
More About: Content
Introduction To PHP, The Web Programming Language
2008-04-17 16:24:00
PHP is a recursive acronym for PHP Hypertext Preprocessor, though it originally stood for Personal Home Page. It is designed specifically for the web, hence a web programming language. PHP is a server-side scripting language which can be either embedded into HTML documents or used alone. Since PHP is a interpreted language, when someone requests a page containing PHP, the code is interpreted on the server and the output (often HTML) is returned to the client web browser. As you might have guessed, PHP can help you generate different outputs depending on the conditions and generate different pages depending on conditions programmed, hence able to create what wee call “Dynamic Pages”. For example, suppose we want to put the current date and time on our web page, HTML alone won’t do any good. So a nice option would be to use PHP (in fact, any sever-sided programming language would be fine. It could also be done with JavaScript but due to ...
More About: Programming , Language , Introduction , Programming Language
Some Changes to Come...
2008-04-17 08:11:00
The name of this blog, as you know, is Learning Computer Programming but since long (actually start) we’ve only been discussing about two programming languages only (C & C++). I thought it’d be better if I discuss about other programming languages too, and since I’m deeply caught up with PHP as for now, we’ll be starting off with it. This of course doesn’t mean that we’ll leave C++ or the topic of this blog will shift to PHP rather it means that the discussion here will not be limited to just one language. This also doesn’t mean you’ll be seeing posts on all sorts of programming languages, as I said for the time being I’ll be posting articles on PHP and Web Programming.
Introduction to Microcontrollers
2008-04-06 08:29:00
This is a guest post by Avinash over at Extreme Electronics. Check out his website to learn more about electronics and microcontroller programming. Computer programming is exciting! Isn’t it. It gives you the felling of power in your hands, power to create and innovate. You can create solution for many everyday problems. Many programs you create are simple doesn’t requires much RAMs only few hundred bytes for variables, array etc. And the input outputs are simple. For example a “calculator” application. Your computer has resources many times more than what is required to run that app. The thing I want to say is that you can easily make a small computer at very cheap cost (less than Rs 300/$6.00). For any specific purpose and make it run your programs. You can make any dream device by using variety of hardware like simple led, seven segment display, switches, sensors to advance Text/graphics LCD modules, PC interface et...
More About: Introduction , Microcontrollers
How Bitwise Operators are Used, an Example Program
2008-03-15 07:52:00
Well, one-by-one we’ve discussed each of the Bitwise Operator. Starting from Operation on Bits and Bitwise Operators , we moved on to Right/Left Bit Shift Operators then discussed Decimal Number to Binary Conversion Program . and at last One's Complement and XOR Operators. After having so much theoretical it’s time now for a nice Example Program, which is the topic of today’s post. The code here is basically to show how these bitwise operator are used rather than what they are used for. // Example Program to demonstrate how // One's Complement (~) and XOR (^) // Opeartors are used. #include<stdio.h> // prototype void showbits(short int); // defined void showbits(short int dec_num) { short int loop, bit, and_mask; for(loop=15; loop>=0; loop--) { and_mask=1<<loop; bit=dec_num&and_mask; if(bit==0) printf("0"); else printf("1"); } } void m...
More About: Variables
One's Complement and XOR Operators
2008-03-15 07:44:00
Talking about Bit Operators we are left with two of them, which we’ll be discussing in this article. One’s Complement Operator (~) It takes and works only on one operand. On taking one’s complement of any variable, the 0s are changed to 1 and vice-versa from the bit structure (binary representation) of that variable. The following example will make it easier to understand: Suppose we have a short int a short int a = 16; its binary representation will be 0000000000010000 (decimal 16) on taking one’s complement like below res = ~a; res will contain 1111111111101111 (decimal 65519) It can be used as a part of algorithm to encrypt data. XOR (eXclusive OR) (^) It is derived from the OR Operator and takes two operands to work on. It compares bits like the OR bitwise operator but exclusively for OR cases. Following will clarify what it does: short int a = 46265, its binary form 1011010010111001 another short int b = 46734, binary 101101101...
More About: Variables
Decimal Number to Binary Conversion Program
2008-03-14 08:00:00
Please read Operation on Bits and Bitwise Operators and Right/Left Bit Shift Operators if you haven’t already. This post is based on those articles. We’ll be using the following operators and the respective properties for decimal to binary conversion: AND (&) Operator from the article Operation on Bits and Bitwise Operators: Its property to be able to check whether a particular bit is ON (1) or OFF (0). Left Bit Shift Operator (<<) from the article Right/Left Bit Shift Operators: Its property to shift bits (of byte(s)) to desired number of places to the left. After making you guys familiar with the two things above, the program will be easier to understand. // Example Program to convert decimal number // to binary equivalent. // -------- // Function: We have defined a function 'showbits()' // It shows the bit structure of the // Short Int(2 Bytes) passed as argument ...
More About: Conversion , Number
Right/Left Bit Shift Operators
2008-03-13 13:53:00
This is the continuation of the article Operation on Bits and Bitwise Operators . If you haven’t read that, it is strongly recommended that you do, before proceeding with this article. Bit shifting, as the name signifies, does shifting of bits in byte(s). There are basically two ways, in which bits (of a byte) can be shifted, either to the right, or to the left. Thus we have two types of bit shifting operator. If you think logically, its pretty clear that for bit shifting in a byte, we need to have two data. We need the byte(s) to shift bits on and the number of bits to be shifted. Guess what, the two operators need these to data as operands! Right Bit Shift ing Operator (>>) Syntax: res = var >> num; This would shift all bits in the variable var, num places to the right which would get stored to the variable res. So for example if var has the following bit structure: var = 00110101 (decimal 53) And we do the following operation: res = va...
More About: Introduction , Left
Electronics Hobby Shop Launched
2008-03-09 11:03:00
You may skip this post if you?r not a resident of India Microcontrollers such as AVR, PIC from Atmel and Microchip are fast becoming the choice of hobbyist for their projects. Now instead of many conventional ICs hobbyists are rather using a single MCU (MicroController Unit) for their projects due to many advantages they have. In the recent years MCUs have become cheap too. Now you may easily get a fully functional MCU from Atmel at under Rs. 70! Sadly that is only one dimension of its popularity if you don’t reside in those big cities, leaving some big cities MCUs are not that easily available let alone the remote areas. There are many resellers but they either deal in large quantities or at high prices both not being suitable for average hobbyists. Seeing this, my brother has come up with a new Online Electronics Hobby Shop for average hobbyists. He has planned to make available everything (Development Boards, MCUs, LCD Displays, Programmers, ...
More About: Personal , Launched
More articles from this author:
1, 2, 3, 4, 5, 6
82990 blogs in the directory.
Statistics resets every week.


Contact | About
© Blog Toplist 2009 - Supported by Web Catalog - SEO by FeWorks
eXTReMe Tracker