PHP Interview Questions and Answers Set 5

41. How do I escape data before storing it into the database?

addslashes function enables us to escape data before storage into the database.

42. How is it possible to remove escape characters from a string?

The stripslashes function enables us to remove the escape characters before apostrophes in a string.

43. How can we automatically escape incoming data?

We have to enable the Magic quotes entry in the configuration file of PHP.

44. What does the function get_magic_quotes_gpc() means?

The function get_magic_quotes_gpc() tells us whether the magic quotes is switched on or no.

45. Is it possible to remove the HTML tags from data?

The strip_tags() function enables us to clean a string from the HTML tags.



46. what is the static variable in function useful for?

A static variable is defined within a function only the first time and its value can be modified during function calls as follows:

<!–?php function testFunction() { static $testVariable = 1; echo $testVariable; $testVariable++; } testFunction();

47. How can we define a variable accessible in functions of a PHP script?

This feature is possible using the global keyword.

48. How is it possible to return a value from a function?

A function returns a value using the instruction ‘return $value;’.

49. What is the most convenient hashing method to be used to hash passwords?

It is preferable to use crypt() which natively supports several hashing algorithms or the function hash() which supports more variants than crypt() rather than using the common hashing algorithms such as md5, sha1 or sha256 because they are conceived to be fast. hence, hashing passwords with these algorithms can vulnerability.

50. Which cryptographic extension provide generation and verification of digital signatures?

The PHP-openssl extension provides several cryptographic operations including generation and verification of digital signatures.