Sunday, 17 March 2013
What is Http Protocol And Its Role In Client Server RelationShip ?
What Is Http protocol ?
Ip Address :
![]() |
| Ip Address |
You might have heard about IP address. It is a protocol which is given to computers on a network in form of address like (127.0.0.1). Because Of this address computers can communicate with each other. IP address and computers communication with each is a different and detailed topic. IP address is an internet protocol.We will discuss it in our coming tutorials.
Http Protocol :
Just like IP there is another Protocol named HTTP " Hyper text Transfer Protocol " . Http is a protocol which is used to transfer data worldwide from one computer to another computer globally. When we type the address of a website then we first add http:// in start of address. Sometimes it is automatically added by the browser in the start of the address of website. Server and Client communicate with each other using this protocol.
What Is Http Request And Http Response :
![]() |
| Http Request And Http Response |
When a request is sent from browser to web server then this request is called Http Request. We have learnt in our previous tutorial about working of CLient/Server that when a server receives a request for a page then it returns the processed page back to the client and if the server cannot find that requested page then It gives a error ( Error : 404 page not found ) The error message or response or the processed page / data which is sent by the sever to the browser is called Http response.
Http Protocol And Its Role In Client Server RelationShip :
When a request is received by a server then there is also some data in the request along with the website URL. In the same way when a server gives response then there is also a lot of information which it sends back to the web browser. The information and knowledge data that is transferred and exchanged between server and client is all automatically produced and processed. A user has to do nothing with it. Therefore we do not need to worry about these as a user, but as a developer we should have complete knowledge about these communications between client and server. This communication is made with the help of HTTP Request and HTTP Response.
Http Message And Its Parts :
It is important to know that whether it is a Client Request or Server Response every message is a Http Message and format of every Http message is same.
Http message has three parts
- Http body
- Http header
- Header Request/Response Line
Whether it is a Http Response And Http Request , both messages have the above three parts.
We will be explaining All these parts in detail and briefly in next tutorial. So subscribe to our email and Join Us on Facebook. Follow Us On Twitter . Find Us on Google+
We will be explaining All these parts in detail and briefly in next tutorial. So subscribe to our email and Join Us on Facebook. Follow Us On Twitter . Find Us on Google+
Share It With Others. Thanks.
Php Tutorial In Urdu :
![]() |
| Php Tutorial In Urdu |
Read More »
Labels:
Client/Server,
Internet,
PHP,
Tricks and Tutorials,
Web Development
Saturday, 16 March 2013
Working Of Online Php Program And Relation Ship Of Client And Server
How Does Online Php Program Work?
![]() |
| Working Of Online Php Program And Relation Ship Of Client And Server |
Now we are moving towards some practical implementations of php web development.Many of friends may have confusions in their minds that
- How does a php program run and work?
- What is the relationship between client and server?
Working Of Php :
Php is not like those desktop softwares that run on our local disks. We know that the extension of these softwares is .exe and they are executable. But php online program runs only when a request is sent to the server by the client and that request asks for running a particular file on the web server. The web server executes the file notified by the request and sends the output result of that file back to the client. But before the response of the web server, It is checked that the request file is whether a php file or not. If it is a php file then Php engine is given a chance to process the php script of that file. But the point here to be noted is that a web server can run only one file at a time. Therefore we can request only one file from server. Although we can add external files on our page by Include Or Require constructs. It means that we copying them in our page dynamically while original file is only one which is on web server. ( We will discuss and explain Include and require Constructs in our next tutorials ). A Http Request completes when a page is processed till end and after completion of HTTP Request, all the data and variables used in this processing will be removed.
What Is A Client And Server?
![]() |
| Client And Server |
The Program Which Interacts With server is called Client. The program which provides services to client is called a Server.
For Example Browsers (Google Chrome, Firefox, and Internet Explorer), Email Clients/Senders and FTP are all " Client " programs and run on Client System. These Client programs are connected to servers and perform different function because of this connection to server.
Examples of The " Servers " to which Clients are connected are Web servers , FTP Servers , Email Servers etc
Relationship of Client And Server is very important in Php because all the Php code runs and executes on server while HTML and JAVA SCRIPT code present on the server is returned as it to the client without processing. "JavaScript" is a language processed by a Web browser. Php code is processed on Server. Therefore the processed Php page is sent by server and you will not find the php code in the source of the processed page.
Php Tutorial In Urdu :
![]() |
| Php Tutorials |
" Stay Blessed And Happy "
" Make Others Happy "
" Sharing Is Caring "
" Keep Visiting "
" Thanks "
" Peace ! "
Read More »
Labels:
Computer Science,
PHP,
Programming,
Tricks and Tutorials
Thursday, 14 March 2013
Complete Php Tutorial On Constants And define() Function
Why To Use Constants In Php ?
We have discussed and learnt in the previous tutorials that we can store data in variables temporarily and data in variables can be changed. But sometimes we require such a value that we want to be changed never. For this purpose we use Constants.
What Is A Constant ?
Constant is type of variable to which we assign a value only once and then the assigned value never changes.
Difference Between Variable And Constant And Their Definition :
There is a Difference Between Variable And a Constant .For defining a variable , we just add $ sign to the name of variable. For defining a constant in Php, there is a function in php which we have to use. The name of the function is Define. This function gets two parameters input. First we write the name of the constant and second we write the value which we want to assign to the constant.
For Example :
define (“CONSTANT_NAME”, “MyTricksLab”);
Here in the above given example we have given define a constant with the name CONSTANT_NAME and then we have assigned it the value MyTricksLab. Here it is important to note that we can only assign a number or string value to a constant.
If we want to get the value of any constant, then we only write the name of the constant and we do not use $ sign with the name of the constant. For understanding this, Just see the script below.
<?phpDefine(“COUNTRY”, “PAKISTAN”);Print “ I Love “.COUNTRY;?>
![]() |
| Share It |
Read More »
Labels:
PHP,
Programming,
Tricks and Tutorials,
Web Development
Complete All PHP Operators Tutorials
What We Have Learnt So Far About Php ?
- Php Web Development Tutorial Series And Introduction .
- Php Tools And Xampp Installation And Customization .
- How To Write Php Source Code And Run / Execute It In Web Browser ?
- How To Add Comments In Php Code ?
- How To Open And Close Php Tags And Their Types ?
- Everything About Php Variables , Their Decalaration And Assignments .
- What Are Php Programming Data Types ?
- Data Type Conversion Using Type Casting In Php .
- Data Type Conversion Using Functions In Php .
- How To Print Special Characters In Php ?
![]() |
| Php Operators |
Operators :
Now Its time to learn about programming operators. So now we can make a variable and assign a value to it easily and also we can find its data type and change data type of variable.
What Are Operators ?
for example : 5+10
Here in the above example 5 and 10 are operands and the + (plus sign) is the Operator. Using Operators on Operands performs a Operation . As a result, new value is produced. The new value produced in above example is 15 as a result of + operator. Except some operators, all operators are used between operands.
Lets have a look on some other operators.
Types Of Operators :
Lets have a look on some other operators.
- The Assignment Operator .
- Arithmetic Operators .
- Concatenation Operator .
- Combined Assignment Operators .
- Comparison Operators .
- Logical Operators.
- Increment And Decrement Operators .
The Assignment Operator ( = ) :
We have already discussed in our previous tutorials, How to assign a value to a variable. So the Equal sign (=) is called "Assignment Operator". It is used to assign a value to a variable.
For example
$name = "Asim";
Arithmetic Operators :
Types Of Arithmetic Operators :
- Operator Symbol : +
Name :Plus Operator
Example : 10 + 3
Result : 13
- Operator Symbol : -
Name : Minus Operator
Example : 10 - 7
Result : 3
- Operator Symbol : /
Name : Plus Operator
Example : 10 / 2
Result : 5
- Operator Symbol : *
Name : Multiplication Operator
Example : 10 * 2
Result : 20
- Operator Symbol : %
Name : Modulus (Remainder) Operator
Example : 10 % 3
Result : 1
I think You will be all familiar with all above arithmetic operators except %(Modulus) Operator. It will be new for you. % Mod operator actually return the remainder after dividing one operand with another.
Concatenation Operator (.) :
Concatenation Operator is an operator which joins two or more than two strings.
for Example : If you want to join strings, "Hello" and "World" , then this can be done using concatenation operator as follows: "Hello"."World". The output result of this concatenation example will be "HelloWorld"
Here is another example of Concatenation
$centimeters = 300;
print "The width is ".($centimeters/100). "meters";
Output : The width is 3 meters
In the above statement the value of centimeters variable is concatenated with two strings "The width is " and " meters".
Combined Assignment Operators :
Although we have just one assignment operator i-e ( = ) But php provides the facility of using it with Arithmetic Operators and Concatenation Operator,
For Example :
<?php
$y = 10;
$y = $y + 5; // $y now equals 15
print $y;
?>
We can also write above program as
<?php
$y = 10;
$y += 5; /* Assignment operator used with Arithmetic Operator . $y now equals 15*/
print $y;
?>
The output of both above programs will be same. But you can see we have combined Assignment operator = with Arithmetic Operator +. It means that the value of left operand ($y) is added is added to right operand (5) and the result is stored in left operand ($y). We can also used other arithmetic operators like (-,*,/,%) in place of + with assignment operator.
Types Of Combined Assignment Operators :
- Operator Symbol : +=
Example :
$y += 5
is equivalent and same to
$y = $y + 5
- Operator Symbol : -=
Example :
$y -= 5
is equivalent and same to
$y = $y - 5
- Operator Symbol : *=
Example :
$y *= 5
is equivalent and same to
$y = $y * 5
- Operator Symbol : /=
Example :
$y /= 5
is equivalent and same to
$y = $y / 5
- Operator Symbol : %=
Example :
$y %= 5
is equivalent and same to
$y = $y % 5
- Operator Symbol : .=
Example :
$y .= "Test"
is equivalent and same to
$y = $y . "Test"
Comparison Operators :
Comparison operators compares the operands with each other and in case of success , gives Boolean value true or false. These operands are mostly used in control structures and loops (ifelse statement, while loop , for loop )
For example :
If we want to check that 5 is smaller or not than the value stored in $X.
We will simple use this statement as
$x < 5;
If the value of $x is 4 then the above statement will return true and If the value of $x is 8 then the above statement will return false.
Types Of Comparison Operators :
- Operator Symbol : ==
Operator Name : Equivalence Or Equals
Operator Function : Checks the equality of operands
Example :200 == 200
Result : True
Because 200 is equal to 200. If operands are not equal then the output will be false.
- Operator Symbol : !=
Operator Name : Non-Equivalence or Not Equals To
Operator Function : Checks the inequality of operands
Example :200 != 100
Result : True
Because 200 is not equal to 100. If operands are equal then the output will be false.
- Operator Symbol : >
Operator Name : Greater than
Operator Function : Checks whether the left operand is greater than the right operand or not
Example :200 > 300
Result : False
Because 200 is not greater than 300. If left operand is greaer than right operand (for example 200 > 100)then the output will be true.
- Operator Symbol : <
Operator Name : Less than
Operator Function : Checks whether the left operand is less than the right operand or not
Example :200 < 300
Result : true
Because 200 is less than 300. If left operand is less than right operand (for example 200 < 100) then the output will be false.
- Operator Symbol : >=
Operator Name : Greater than or Equals to
Operator Function : Checks whether the left operand is greater than or equal to the right operand or not
Example :5 >= 15
Result : False
Because 5 is not greater than 15 and also 5 is not equal to 15. If left operand is greater than right operand or equal to the right operand (for example 200 >= 100) or (for example 200 >= 200) then the output will be true.
- Operator Symbol : <=
Operator Name : Less than or Equals to
Operaor Function : Checks whether the left operand is less than or equal to the right operand or not
Example :5 <= 15
Result : true
Because 5 is less than 15 . If left operand is greaer than right operand or equal to the right operand (for example 200 >= 100) or (for example 200 >= 200) then the output will be true.
- Operator Symbol : ==
Operaor Function : Checks whether the left operand VALUE AND DATAYPE is same as the right operand or not
Example :5 == "5"
Result : falseBecause 5 is an integer while "5" is string.
Logical Operators (and, or, not) :
These operators check the conditions and return boolean value true or false.
OR logical Operator :
This operator checks two conditions and gives true If any of the two values is true. Symbol Of OR Logical Operator is || or OR
Example
($age == 27) || ($age == 30 )
You can see that i am checking two conditions in above example. It means that I want value of age 27 or 30 . If the value of age is 27 then the ($age == 27) statement will return true and the output of OR || operator will be true. It means that OR Operator output will be true if any of the operands is true. If both operands conditions are false then only the output of OR operator will be false.
Here is the truth table of OR Logical Operator .
We can see in the truth table that the only false output occurs when both or all operands are false . If any of the operand is true then the output will be true. Working Of OR operator can be just like the circuit below. In this circuit the bulb will glow If any of the switches are closed.
AND Logical Operator checks two or more than two condiotions and the output is only true when all conditions are true. If any of the conditon is false then the output of AND operator will be false.
Example:
($age == 27) && ($country == "Pakistan")
The above condition which return true only when the age is 27 and country is Pakistan. Means the user is of 27 age and also a citizen of pakistan country, only then it will return true. You will understand AND operation more clearly with the help of this Truth Table.
Another comparison example For working of AND Logical Operator.
For example.
If we add the ++ after the name of variable then it is called Post Increment and It we add ++ before name of variable then it is called Pre Increment. If we add the -- after the name of variable then it is called Post decrement and It we add -- before name of variable then it is called Pre decrement.
For example ;
It is very important to understand the difference between Postfix and Prefix. When we perform post increment or post decrement Like in using $a++ , first value of variable is returned and then it is incremented or decremented in case of $a--. While in Pre Increment or Pre decrement , the value is incremented or decremented first and then it is returned with the incremented or decremented value.
If you have still a problem then lets make a program to understand.
You can see that i am checking two conditions in above example. It means that I want value of age 27 or 30 . If the value of age is 27 then the ($age == 27) statement will return true and the output of OR || operator will be true. It means that OR Operator output will be true if any of the operands is true. If both operands conditions are false then only the output of OR operator will be false.
Here is the truth table of OR Logical Operator .
![]() |
| And Logical Operator |
We can see in the truth table that the only false output occurs when both or all operands are false . If any of the operand is true then the output will be true. Working Of OR operator can be just like the circuit below. In this circuit the bulb will glow If any of the switches are closed.
![]() |
| And Logical Operator |
AND Logical Operator ( && ) :
AND Logical Operator checks two or more than two condiotions and the output is only true when all conditions are true. If any of the conditon is false then the output of AND operator will be false.
Example:
($age == 27) && ($country == "Pakistan")
The above condition which return true only when the age is 27 and country is Pakistan. Means the user is of 27 age and also a citizen of pakistan country, only then it will return true. You will understand AND operation more clearly with the help of this Truth Table.
![]() |
| OR Logical Operator |
Another comparison example For working of AND Logical Operator.
![]() |
| OR Logical Operator |
Not Logical Operator (!) :
Not Operator Just checks the coditon and if the condition is true then after applying NOT operation , the output will be false and if condion is false then the output will be true. In simple words NOT reverses the truth value. NOT is only applied on a single operand.Increment ( ++ ) And Decrement ( -- ) Operators :
These Operators can increase or decrease the value of a variable by 1. These operators are mostly used is loops. When we add two plus signs ++ after the name of a variable ( like $i++ )then it is called incrementing and if we add two minus signs -- after the name of a variable ( like $i++ ) then it is called decrementing. ++ is increment operaor and -- is called decrement operator.For example.
$a = 5 ;
$a++ ; /* Value of $a is incremented By 1 */
$a-- ; /* Value of $a is decremented By 1 */
If we add the ++ after the name of variable then it is called Post Increment and It we add ++ before name of variable then it is called Pre Increment. If we add the -- after the name of variable then it is called Post decrement and It we add -- before name of variable then it is called Pre decrement.
For example ;
$a = 5 ;
++$a ; /* $a is incremented */
--$a ; /* $a is decremented */
Difference Between Postfix And Prefix :
It is very important to understand the difference between Postfix and Prefix. When we perform post increment or post decrement Like in using $a++ , first value of variable is returned and then it is incremented or decremented in case of $a--. While in Pre Increment or Pre decrement , the value is incremented or decremented first and then it is returned with the incremented or decremented value.
If you have still a problem then lets make a program to understand.
<?php
/*using post increment */
$test_var = 5;
print " Post Increment ";
print "The value of the test_var is :".$test_var."<br>;
print " By Using Post Increment the value of test_var is :".$test_var++;
print "<br>; /* for next line */
print " On next line, the value is now : ".$test_var;
print "<br>; /* for next line */
/*using Post Decrement */
$test_var = 5;
print " Post Decrement ";
print "The value of the test_var is :".$test_var."<br>;
print "By Using Post Decrement the value of test_var is :".$test_var--;
print "<br>; /* for next line */
print " On next line, the value is now : ".$test_var;
print "<br>; /* for next line */
/*using Pre Increment */
$test_var = 5;
print " Pre Increment ";
print "The value of the test_var is :".$test_var."<br>;
print " By Using Pre Increment the value of test_var is :".++$test_var;
print "<br>; /* for next line */
print " On next line, the value is now : ".$test_var;
print "<br>; /* for next line */
/*using Pre Decrement */
$test_var = 5;
print " Pre Decrement ";
print "The value of the test_var is :".$test_var."<br>;
print " By Using Pre Decrement the value of test_var is :".--$test_var;
print "<br>; /* for next line */
print " On next line, the value is now : ".$test_var;
print "<br>; /* for next line */
?>
Output :
Post Increment
The value of test_var is : 5
By using Post Increment the value of test_var is : 5
On next line, the value is now : 6
Post Decrement
The value of test_var is : 5
By using Post Decrement the value of test_var is : 5
On next line, the value is now : 4
Pre Increment
The value of test_var is : 5
By using Pre Increment the value of test_var is : 6
On next line, the value is now : 6
Pre Decrement
The value of test_var is : 5
By using Pre Decrement the value of test_var is : 4
On next line, the value is now : 4
![]() |
| Php operators program |
In the above program we have declared a $test_var variable. Then by different ways we have Increment and Decrement the value of the variable. You can see that in Post Increment ANd Post Decrement , the value of the variable is increased or decreased by 1 in next line while in pre icrement or decrement the value of variable in increased or decreased by 1 in the same line and then its value is printed.
Your Turn Now :
I have tried my best and really worked hard for writing this brief and exclusive tutorial to help yo to understand all aspects of Php operators. I hope that It will really help you. If you have any problem or want to ask any question, then feel free to ask questions to me . I will surely help you. If you want to give any feedback or want to say thanks, then give it via comments. It will be a great honour for us. Subscribe to email and on social networks to get free future posts. As this post is a comprehensive and complete post so make sure to share it with others . Keep sharing. Thanks.
Share It To Others To Spread Knowledge : )
Read More »
Labels:
PHP,
Php Operators,
Tricks and Tutorials,
Web Development
Wednesday, 13 March 2013
Change Data Type Using Functions And Print Special Characters In Php
Data Type Conversion Using Functions In PHP :
There are some other ways to change the data type of available without using Type casting. There are some functions that change the data type of a variable .
For example
- intval (value) ;
- double (value);
It takes a value (whose data type we want to change ) as input and returns a double data type output .
- strval (value) ;
It takes a value (whose data type we want to change ) as input and returns a string data type output .
Print Special Characters In Php :
One thing I forgot in my previous post that we can use echo or print statement for printing output on screen. If you want to print a special character on screen like double quotes (") or single quote ( ' ) or backslash ( \ ), then we can print these by using a backslash . See the example to understand
<?php
echo "He said : \ " I love Pakistan \" ";
?>
Output
He said : "I love Pakistan "
In above statement you can see that I wanted to print double quotes on the screen so that I used backslash. If you want to print the name of the variable instead of its value then use single quotes in echo statement
<?php
$city = "Karachi";
echo 'City is : $city '. '<br/>;
echo " City is : $city ";
?>
Output
" Share With Others And Care Others "
Read More »
Labels:
PHP,
PHP Data types,
Programming,
Tricks and Tutorials,
Web Development
Tuesday, 12 March 2013
Convert Data Type By Type Casting In Php
What is Data Type Conversion And Type Casting In Php ?
If we want to change a data type of a variable then there is a way that just write the data type in round brackets and write it before the variable. In this way the data type of the variable will be changed to the data type written in brackets.
Difference Between Type Casting And Using Settype Function :
The main difference between Type Casting and Settype function is that in type casting the original data type of the variable does not changes but a new variable copy with a new data type will be created. If you are getting confused then observer the program below to understand type casting
<?php
$undecided = 3.14 ;/* this variable is only declared and it has been assigned a data type*/
$holder ; /* this variable is only declared and it has not been assigned a data type yet */
$holder = (double) $ undecided;
print gettype( $holder ) ; /* This will print the data type of holder variable at this stage
*/
print " -- $ holder <br/> " ; /* This will print the value asigned to holder variable*/
$holder = ( string ) $undecided ;
print gettype( $holder ) ; /* This will print the data type of holder variable at this stage */
print " -- $ holder <br/> " ; /* This will print the value asigned to holder variable */
$holder = ( integer ) $undecided ;
print gettype( $holder ) ; /* This will print the data type of holder variable at this stage */
print " -- $ holder <br/> " ; /* This will print the value asigned to holder variable */
$holder = ( boolean ) $undecided ;
print gettype( $holder ) ; /* This will print the data type of holder variable at this stage */
print " -- $ holder <br/> " ; /* This will print the value asigned to holder variable */
$holder = ( double ) $undecided ;
print gettype( $holder ) ; /* This will print the data type of holder variable at this stage */
print " -- $ holder <br/> " ; /* This will print the value asigned to holder variable */
?>
Output :
double -- 3.14
string -- 3.14
integer -- 3
boolean -- 1
double -- 3.14
In the above script we have made a variable $undecided and the given a floating point value to it. Then with type casting we have made of copy of $undecided variable with different data type and then placed the copy in $holder variable . In this way the data type of $undecided variable remains same and we can just use this variable to make its copies with different data types and then assigning it to others. This is helpful when we want some specific data types like string or integer.
For example If you ask user to enter his/her age in text box and users enters 25 years in the textbox. User has entered a string But Age is usually in integer. So now you have to type cast the string entered by the user. This will be done as follows :
For example If you ask user to enter his/her age in text box and users enters 25 years in the textbox. User has entered a string But Age is usually in integer. So now you have to type cast the string entered by the user. This will be done as follows :
$age = (integer) $ user_age ;
print $age;
The output of above statement will be
Output :27
Other Ways For Data Type Conversion :
Ofcourse There are always many other ways to perdorm a single task. In the same way there is another way to change the data type of given variable without using Type casting. We will discuss those ways in our next Tutorial.
Stay tuned and subscribed for learning Complete Web development. Share It with others. Ask Questions And Queries Via Comments. You feedback will be welcomed. Thanks
" Share It Please . Thanks!!!"
Read More »
Labels:
PHP,
PHP Data types,
Programming,
Tricks and Tutorials,
Web Development
Subscribe to:
Posts (Atom)





















