PHP Questions

Q:

How to use HTTP Headers inside PHP? Write the statement through which it can be added?

Answer

HTTP headers can be used in PHP by redirection which is written as:


<?header('Location: https://www.php.net')?>


The headers can be added to HTTP response in PHP using the header(). The response headers are sent before any actual response being sent. The HTTP headers have to be sent before taking the output of any data. The statement above gets included at the top of the script.


 

Report Error

View answer Workspace Report Error Discuss

Subject: PHP

2 18269
Q:

How can I retrieve values from one database server and store them in other database server using PHP?

Answer

we can always fetch from one database and rewrite to another. Here is a nice solution of it.$db1 = mysql_connect("host","user","pwd")
mysql_select_db("db1", $db1);
$res1 = mysql_query("query",$db1);$db2 = mysql_connect("host","user","pwd")
mysql_select_db("db2", $db2);
$res2 = mysql_query("query",$db2);At this point you can only fetch records from you previous ResultSet, i.e $res1 – But you cannot execute new query in $db1, even if you supply the link as because the link was overwritten by the new db.so at this point the following script will fail
$res3 = mysql_query("query",$db1); //this will failSo how to solve that?

take a look below.
$db1 = mysql_connect("host","user","pwd")
mysql_select_db("db1", $db1);
$res1 = mysql_query("query",$db1);

$db2 = mysql_connect("host","user","pwd", true)
mysql_select_db("db2", $db2);
$res2 = mysql_query("query",$db2);

So mysql_connect has another optional boolean parameter which indicates whether a link will be created or not, as we connect to the
$db2 with this optional parameter set to 'true', so both link will remain live.

Now the following query will execute successfully.
$res3 = mysql_query("query",$db1);

Report Error

View answer Workspace Report Error Discuss

Subject: PHP

2 10694
Q:

Why was PHP developed, what it is used for, and where can you get it?

Answer

PHP developed for less script, time saving, Free Open Source Software and runs on different platforms such as Windows, Linux, Unix, etc. PHP compatible with almost all servers used today such as Apache, IIS, etc.

The PHP scripting language resembles JavaScript, Java, and Perl, These languages all share a common ancestor, the C programming language. PHP has full access to the information that the server has, and very little access to information that the client has. In fact, it only has information that the client tells the server and that the server passes on to PHP. Because it is on the server, however, PHP cannot be modified by the client. While you cannot necessarily trust the information that the client gives to PHP, you can trust that your PHP is doing what you told it to do. Because PHP is on the server end, your PHP scripts can affect your server -- such as by keeping an activity log or updating a database.

Report Error

View answer Workspace Report Error Discuss

Subject: PHP

3 10465
Q:

What type of inheritance that PHP supports? Provide an example.

Answer

PHP supports single level inheritance.


Inheriting a class would mean creating a new class with all functionality of the existing class in addition to some more. The created class is called as a subclass of the parent class. Parent is a keyword which we use to access members of a parent class. Inheritance is usually defined by using the keyword “Extend”. $this is used a reference to the calling object. Inheritance avoids redundancy of code.


Example:


Class employee extends manager : Here Employee is a subclass of manager.


Echo $this->name can be used to echo variable name of the parent class.

Report Error

View answer Workspace Report Error Discuss

Subject: PHP

1 9872
Q:

How can we display the output directly to the browser?

Answer

To be able to display the output directly to the browser, we have to use the special tags <?= and ?>.

Report Error

View answer Workspace Report Error Discuss

Subject: PHP

8 7725
Q:

What’s the difference between md5( ), crc32( ) and sha1( ) crypto on PHP?

Answer The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit value, and md5() returns a 160 bit value. This is important when avoiding collisions.
Report Error

View answer Workspace Report Error Discuss

Subject: PHP

1 7013
Q:

What is PHP's configuration file called?

Answer

PHP’s configuration file is called php.ini.

Report Error

View answer Workspace Report Error Discuss

Subject: PHP

1 6986
Q:

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

Answer PHP Interpreter treats numbers beginning with 0 as octal. Look at the similar PHP interview questions for more numeric problems.
Report Error

View answer Workspace Report Error Discuss

Subject: PHP

1 6672