Learning conditional statements in PHP

Conditionals allow your program to make choices. Following the same sort of boolean logic you just learned about, the computer can only make two choices; true or false. In the case of PHP this is accomplished using IF : ELSE statements. Below is an example of an IF statement that would apply a senior’s discount.

in following statements if $name is premal then all statements inside breckets should be display.





echo “Premal Katigar”;




echo “Wrong Statement”;




Detect IP address using PHP


$ip=$_SERVER[‘REMOTE_ADDR’]; echo “Your IP Address : $ip”;


Changing the capitalization of stings

Making the string all capital letters:

You can simulate the CAPSLOCK key using thestrtoupper() PHP function.

Making the string all lower case letters:

You can also force all letters in a string to be lower case. This is done with the strtolower() PHP function.

Capitalizing each word:

You can choose to only capitalize the first letter of every word. This works great when working with a list of names or cities. This is done with theucwords() PHP function.

Code :


// using strtoupper() we can easily get all characters in capital.

echo strtoupper(“This is Premal Katigar”);


// using strtoupper() we can easily get all characters in capital.

echo strtolower(“This is Premal Katigar”);

// using ucwords() we can easily get all words with first character capitalized


capitalize all words

Output Of above code :

capitalized character output


Know More about php

Mail me your topic or problems


Contact : +91-84604-57306

How to use arrays in php

When you are working with PHP, one way to represent data is to use a variable. But sometimes a variable just isn’t enough. Sometimes you need an array. An array is sort of like a variable that holds multiple entries. For example, if you wanted a variable called $state you could only hold one state name. But if you made the same variable an array, you could hold all 50 states.

<?php  $state = "Premal";  echo $state;  ?>

If you run the code above it will simply return:


<?php  $states = array ('Bhavi', 'Premal');  print_r ($states);  ?>

If you run this you will see:

Array ( [0] => Bhavi [1] => Premal [2] )

All of the elements (the items in our array) are indexed by number. The first number is always 0.

Let’s try it:

<?php  $states = array ('Premal', 'Katigar');  echo ($states[1]);  ?>

Running this will display:


<?php   $states = array('Developer' => 'Premal', 'Develop' => 'Paresh');   print_r($states);   ?>

Here is another way to define the same array:

<?php  $states['Developer'] = 'Premal';  $states['Develop'] = 'Paresh'  print_r ($states); ?>

Try this code:

<?php   $states = array('Developer' => 'Premal','Develop'=>'Angel');   echo ($states[Developer]);  ?>

Running this code will simply give you:


File Handling in PHP

Most Important think that is :

you have to configure first ini file :

goto php.ini

file_uploads = On

file upload
file upload

Check if uploaded file is already exist or not

$target_dir = “uploads/”;
$target_file = $target_dir . basename($_FILES[“fileToUpload”][“name”]);

if (file_exists($target_file)) {
echo “Sorry, file already exists.”;
$uploadOk = 0;


Restriction for file size

if ($_FILES[“fileToUpload”][“size”] > 500000) {
echo “Sorry, your file is too large.”;
$uploadOk = 0;

Limit File Type :

if($imageFileType != “jpg” && $imageFileType != “png” && $imageFileType != “jpeg”
&& $imageFileType != “gif” ) {
echo “Sorry, only JPG, JPEG, PNG & GIF files are allowed.”;
$uploadOk = 0;

Using Cookies in PHP

A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user’s computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.

Now Let’s See how to use Cookies.

A cookie is created with the setcookie() function.

Remember one think we have to use cookie before <html> tag.


setcookie(name, value, expire, path, domain, secure, httponly);


Above code show how to set cookie.

I have set Cookie for 30 days.




main think is that if you want to remove cookie then you have to set it always before 1 hour ahead.

// set the expiration date to one hour ago
setcookie(“user”, “”, time() – 3600);
echo “Cookie ‘user’ is deleted.”;



Any Questions feel free to comment & mail me.

Sessions in PHP

When you work with an application, you open it, do some changes, and then you close it. This is much like a Session. The computer knows who you are. It knows when you start the application and when you end. But on the internet there is one problem: the web server does not know who you are or what you do, because the HTTP address doesn’t maintain state. Session variables solve this problem by storing user information to be used across multiple pages.

Let’s Start with using sessions.

First of all create a new page named home.php. then at first line you have to write session_start(). It’s a function necessary to use when you are using session. This begins or starts the session.


After that Create simple page which contains textbox & button.


Declaration of the sessions

$_SESSION[‘name of session’]=value;

in above sentence you have to give the name of session & value too.



The above page is home.php

now we pass the value of session to another page that is welcome.php

this is session

This is home.php on web browser


When we click on ok then session will pass to welcome.php


Any Query regarding to PHP feel free to ask.


how to connect database in php

It’s quite Simple to connect to the database of php that is MY_SQL.

Simple Create a new php file with database.php.



localhost is host name & root is user name.


Above sentence is for selecting database my database is psk & we have to pass one variable that is of connection. I have pass $p.

mysql_query() is used for execute query. I have used for update query.


Congo. You got connect with database.



How to Send email with WordPress

I will show you how to send mail to others using wordpress with your gmail account.

download wp smtp plugin.

here is link for free download :


Open it from Settings -> WP SMTP


WP SMTP Settings page opened :



Now write smtp.gmail.com.

select SSL authantication

SMTP port is 465


user name is your email.

password is your email