Useful .htaccess Tricks for WordPress

Useful .htaccess Tricks for WordPress

PHP Developers and WordPress developers some times comes across .htacess file.
this file is configuration file for for security and performance. here i will show few usefull tricks to do with .htacess file. This file is located at root of your website (/public_html/)

Before we start lets grab the .htacess file from FTP and keep one backup (Just for fail safe).
if you dont have any .htacess file in your root folder under public_html.


  1. Protect wp-config.php file
    1. It was most important to protect your wp-config file because it has all the information about your database. if anyone get this file they can easily connect to our data base. Here  is the code for protecting wp-config.php file
      <files wp-config.php>
      order allow,deny
      deny from all
    2.  Protect wp-admin folder
      you can easly genarate login protect for wp-admin folder here is the link how to do it
PHP interview questions and answers

PHP interview questions and answers

1)    What does a special set of tags <?= and ?> do in PHP?

2)    What’s the difference between include and require?

3)    I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what’s the problem?

4)    Would I use print “$a dollars” or “{$a} dollars” to print out the amount of dollars in this example?

5)    How do you define a constant?

6)    How do you pass a variable by value?

7)    Will comparison of string “10” and integer 11 work in PHP?

8)    When are you supposed to use endif to end the conditional statement?

9)    Explain the ternary conditional operator in PHP?

10) How do I find out the number of parameters passed into function?

11) If the variable $a is equal to 5 and variable $b is equal to character a, what’s the value of $$b?

12) What’s the difference between accessing a class method via -> and via ::?

13) Are objects passed by value or by reference?

14) How do you call a constructor for a parent class?

15) What’s the special meaning of __sleep and __wakeup?

16) Why doesn’t the following code print the newline properly?

17) Would you initialize your strings with single quotes or double quotes?

18) How come the code <?php print “Contents: $arr[1]”; ?> works, but <?php print “Contents: $arr[1][2]”; ?> doesn’t for two-dimensional array of mine?

19) What is the difference between characters 23 and x23?

20) With a heredoc syntax, do I get variable substitution inside the heredoc contents?


 Just press Like button to download Answers


PHP Arrays

PHP Arrays

  1. An array is a concept of declaring a variable in which multiple values can be stored or
    An array stores multiple values in a single variable..
  2. an array in PHP is compound type.
  3. An array is actually an ordered map.
    A map is a type that maps values.
  4. Each element in array has its own index.
  5. It takes a certain number of comma separated Key =>value pairs
    Array(key=>value, key=>value, . . .)


  1. It is a function of PHP used to get the size of an array
  2. The size of an array is number of elements present in the array

Ex: count($x)

Print_r (array_name)

It is Function used to display the entire content of array with key.


We have 3 types of arrays in PHP

  1. Numeric array
  2. Associative array
  3. array

Numeric Array

Numeric stores the each array element with a numeric index.

In PHP we have 2 techniques to create a array.

  1. Assign index automatically
    $x = array(10,20,30,40)
  2. Assign index Manually
    $x = array();

Loops in arrays

Foreach loop:-

  1. For each loop gives an easy way to iterate over arrays.
  2. foreach works only on arrays and objects.

Syntax 1 of foreach :-

foreach (array as $value)


for every iteration the value of current array element is assigned to $value and the array  pointer is moved to next element so on ..
On the next loop iteration it will be looking at next array value.

Syntax2 for foreach loop

foreach (array as $key=> value)
This loop is also does the same thing , but except that the current elements key index will be assigned to the variable $key on each loop iteration.

<? PHP
Echo “size of array is “.count($x).”<br>”;
echo”size of array is “.count($y).”<br>”;
foreach($x as $k=>$R)

Associative Array

  1. An array where each ID key is associated with a value is called assosiative array
  2. With assosiative arrays we can use the values as keys and assign values to them.
  3. when storing data about specific named values, a numerical array is not always the best way to do it.

Example :-

  1. $Ages = array(“x”=>20, “y”=>30, “z”=>40);

  2. $ages = array();
    $ages[“x”] = 20;
    $ages[“y”] = 30;
    $ages[“z”] = 40;

In the both of above examples the values in the variable remains same but we used different ways to store the data.

if you do not specify a key for given value then the maximum of integer indices is taken till there, and the new key will be that maximum value+1.

if you you specify a key value that already assigned that value will be overwritten.

Multi dimension array:

An array containing one or more arrays in a multi dimension at array, each element in the main array can also be an array and each element in the sub array and so on..

if you want to remove a value from the array you need to use the function unset();
syntax: unset($age[‘x’]);

Data Types and Built in functions

Data Types and Built in functions

PHP supports 8 data types

  1. scalar data types( A variable in which only one value can be stored at a time
    1. Boolean
    2. integer
    3. Float / Double
    4. String
  2. Compound data type (A variable in which multiple values can be stored)
    1. Array
    2. Object
  3. Special data types
    1. resource
    2. Null

The type of variable is not set by the programmer, rather it is decided at run type byPHP depending upon the context in which the variable is used.

Var_dump (Var_name):-

it is built in function of PHP used to getting the type of variable with content of variable

It is also an Built in function in PHP it is used to get the type of variable.

It is also an Built in function in PHP it is used to change the type of variable.

I will explain about notice error in the next class

It is also an Built in function in PHP it is used to removing the content from variable.

variables and output statements in PHP

variables and output statements in PHP

We have 2  functions for output in PHP those are echo() and Print ()

actually output statements used to send output to the client (browser)

differences between echo() and print() are

  1. echo() is faster than print() in execution
  2. print() is return an integer value where echo() dosent return a value

in PHP the semicolon (;) is used to separate the two statements or scripts in PHP

Comments in PHP

In PHP, we use // or # to make a one-line comment

/* and */ to make a comment block:

Variables in PHP

  1. variables are used used to store values like text, string, numbers,arrays,objects, etc..
  2. when a variable is set it can be used again and again in PHP program.
  3. all the variables in PHP starts with $.
  4. in PHP an variable dose not need to be declare before it being set.
  5. it is not necessary to tell PHP which data type is the variable.
  6. PHP automatically converts the variable into correct data type depending on the situation where it was being used.


output will be “abcxyz”

Variable naming rules

  1. A variable name can have alphanumeric characters and underscore “_”.  That is all alphabets and numbers from 0 to 9.
  2. A variable name should start with a letter or “_”. We cant use number at starting of variable name.
  3. No spaces are allowed in variable names.
  4. variable names are case sensitive.
  5. It is advised not use the reserved keywords  of PHP as a variable name.Example : $firstname, $ last_name, $_age
  6. Dot operator (.) is concadination operator in PHP

Note:If we a variable in double quotes (“ ”)self expansion of the variable will happen where the memory usage is more so we should not use variable in double quotes(“ ”)


“$firstname”  don’t use these type

Operators in PHP

Operators in PHP

Operators are used to perform some operations on data operators are broadly classified into 2 categories

  1. Unary operators
    An operator  that requires only one operant in unary operator.
    Ex: $a++
    in the above statement a is operant and ++ is operator
  2. Binary Operator
    An operator that require two operant is called as binary operator.
    Ex: $a+$b

We have 8 types of operators in PHP those are

  1. Arithmetic operators
    1. +
    2. *
    3. /
    4. %

  2. Assignment operators
    1. =
    2. +=
    3. -=
    4. *=
    5. /=
    6. %=
    7. .=


  3. increment and decrement Operators
    1. ++(increases value by one)
    2. –(Decrease value by one)

  4. Relation operators
    1. <
    2. >
    3. <=
    4. >=
    5. == (will check only for content is same or not)
    6. !=
    7. <>
    8. === (will check content and type of content also)
    9. !==
  5. Logical operators  (it was used to frame a compound condition)
    1. &&
    2. ||

      In case of logical operators all the expressions will not be evaluated every time . It is based on the result of first condition.(($a>$b)&&($a>$c))


  6. Negation operators

    it used to multiply a number with “-“ operator$a=10;


  7. Error Control operators  (@)

    when prepended with an expression, any warning messages that is being generated will gets suppressed.

  8. Bitwise operators

    Bit wise operators are 3 they are

    1. AND –&
    2. OR    — |
    3. XOR  — ^

      In this case bit wise operators both operant will converted to binary form and corresponding bitwise operation will be performed.

  9. Shift Operators
    1. Left Shift operator (<<)
    2. Right shift operator (>>)

      In this case of shift operators the first operant will be converted to binary form and corresponding shifts will happen based on second number of operant.EX:–

      echo (100>>2);

      echo (100<<2);

      output will be



  10. String / Concadination operator
    1. .
    2. .=
  11. concadination / ternary operator
    1. ?:
  12. Type operator
    1. “insaneof”
  13. New Operator
    1. new
  14. Scope operator
    1. ::
  15. De-referencing operator
    1. ->