Full Guideline about If and Else Function

PHP If Else
This function is just to clarify in php that if something exist then what to show and if its not exist at all then what should be there for user to see. If and Else functions are most commonly used php element next to print or include. This function can work both positively and negatively depending upon your choice hoe to use it.

It generally used where a condition is set for server depending on user data or your data. Most easiest example to explain this is given below -

$date = date("D");
if ($date == "Fri")
 { echo "Have a nice weekend!"; }
else 
 { echo "Have a nice day!"; }

Now in above Example $date is getting the present day and if today is Friday then it executes command "Have a nice weekend!" otherwise it executes "Have a nice day!"if it is any other day. It is positive conditon for if and else.

Now You can use it in negativel condition also in your document. So see below example also


$date = date("D");
if ($date !== "Sunday")
 { echo "Its not Sunday today!"; }
else 
 { echo "Have a nice Sunday!"; }


Here (' !== ') sign in condition is representing negative condition for Sunday. Means on setting !== "Sunday" , you are telling that if condition is set if its not Sunday.

In other cases like Security Case or giving access to some of your closed members than you can set password or username to get acess to any page. Example is given below -

<form method="post"><input name="pass" type="password" /><input type="Submit" /></form>
<?php
$pass = $_POST['pass'];
if ($pass == "abc")
 {
      print 'Logged Successfully';
 }
else
 {
      print 'Error in Log in. Wrong Password Entered.';
 }
?>


So in above example if user enters pass "abc" only the he/she will get access to your page whose link can be added in print of If here. In same way you can ask for username also. But this protection can be used up to some cases or less serious cases.

Last function to discuss here is elseif function. Else if mean that in case that If is not valid for a case than to have a second case with you, you can us elseif. It is also as simple as if itself. So lookout at this simple example -

$d=date("D");
if ($d=="Fri")
{
echo "Have a nice weekend!";
}
elseif ($d=="Sun")
{
echo "Have a nice Sunday!";
}
else
{
echo "Have a nice day!";
}


Here you can see that if its Friday then message comes "Have a nice weekend!", but else if its Sunday then message comes "Have a nice Sunday!". But if its neither Friday nor Sunday today then the message comes "Have a nice Day!".

If you have any doubts feel free to comment below.
[ Read More ]

CSS3 Linear Gradient Syntax

The CSS gradient feature was introduced by Webkit for about two years but was rarely used due to incompatibility with most browers. But now with the Firefox 3.6+, which supports gradient, we can style create gradient without having to create an image. This post is usefull for all people especially those who want that there website opens quikly on all slow and dial up connections. So, instead of using photos for background gradients we will make use of of a CSS3 property which is linear gradient .So Look at this Example

In this photo you can see the shades of white, green, purple and blue produced with the help of linear gradient. You can use both rgb and hex colors for this css3 property.







So code used in above picture for purple color is (Google Chrome, Safari)
background: -webkit-gradient(linear, left top, left bottom, from(#A349A4), to(rgb(126,56,126)));

For firefox you have to use
background: -moz-linear-gradient(top, #A349A4, rgb(126,56,126));

For IE Use css
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#A349A4', endColorstr='rgb(126,56,126)');

For Opera You can go with this
 background: -o-linear-gradient(top, #A349A4, rgb(126,56,126));

To use in all browsers use a combine css like this
.thisClass {
background: -webkit-gradient(linear, left top, left bottom, from(#A349A4), to(rgb(126,56,126)));  /** Google Chrome , Safari **/
background: -moz-linear-gradient(top, #A349A4, rgb(126,56,126)); /** Firefox **/
 background: -o-linear-gradient(top, #A349A4, rgb(126,56,126)); /** Oper **/
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#A349A4', endColorstr='rgb(126,56,126)'); /** IE** /
}
[ Read More ]