2
Q:

PHP allows you to send emails directly from a script.

php allows you to send emails directly from a script

 

A) TRUE B) FALSE

Answer:   A) TRUE



Explanation:

The mail() function allows you to send emails directly from a script.

 

Q:

Explain when to use GET or POST. Provide example for both the ways.

Answer

Both GET and POST are used to collect data from a form. However, when security is desired $_POST should be used. When the $_ POST variable is used, all variables used are NOT displayed in the URL. Also, they have no restrictions to the length of the variables. GET should be used when the interaction with the form is more like a question. For e.g. firing a query etc. POST should be used more often when the interaction is more like an order or the interaction changes the state of the resource.


POST example:


<form action="sample.php" method="post">


Name: <input type="text" name="name" />


Age: <input type="text" name="age" />


<input type="submit" />


</form>


On clicking submit the URL resembles to: https://www.mysamplesite.com/sample.php


The sample.php file can be used for catching the form data using $_POST 


Hello <?php echo $_POST["name"]; ?>.<br />


You are <?php echo $_POST["age"]; ?> years old!


 


GET EXAMPLE


<form action="sample.php" method="get">


Name: <input type="text" name="name" />


Age: <input type="text" name="age" />


<input type="submit" />


</form>


On clicking submit the URL resembles to : https://www.mysamplesite.com/sample.php?name=jim&age=37


The sample.php file can be used for catching the form data using $_GET 


Hello <?php echo $_GET["name"]; ?>.<br />


You are <?php echo $_GET["age"]; ?> years old!

Report Error

View answer Workspace Report Error Discuss

Subject: PHP - Technology

0 3995
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 - Technology

0 9283
Q:

Explain how to create random passwords.

Answer

Generating random passwords in PHP can be done in multiple ways depending on how much security the application demands:-


Md5 function can be passed one parameter as uniqid() function which in turn generates a random number. Passing the parameter as TRUE in uniqid() adds additional uniqueness.


<?php
   $passwd = md5(uniqid(rand(), true));
   Echo $passwd;
?>

Report Error

View answer Workspace Report Error Discuss

Subject: PHP - Technology

0 2134
Q:

Explain how to store the uploaded file to the final location.

Answer

A HTML form should be build before uploading the file. The following HTML code is used for selecting the file that is to be uploaded. The type attribute of input must be “file”.


<form enctype="multipart/form-data" action="uploader.php" method="POST">


<input type="hidden" name="MAX_FILE_SIZE" value="100000" />


Choose a file to upload: <input name="uploadedfile" type="file" /><br />


<input type="submit" value="Upload File" />


</form>


At the time of executing uploader.php, the uploaded file will be stored in a temporary storage are on the webserver. An associative array $_FILES['uploadedfile']['name'] is used for uploading. The ‘name’ is the original file that is to be uploaded. Another associative array $_FILES['uploadedfile']['tmp_name'] is used for placing the uploaded file in a temporary location on the server and the file should be empty and should exist with the tmp_name.


The following code snippet is used for uploading the file.


$target_path = "uploads/"; // the target location of the file


$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);


if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) 


{


       echo "The file ". basename( $_FILES['uploadedfile']['name']). 


        " has been uploaded";


}


else


{


      echo “There was an error while uploading the file”;


}


The function move_uploaded_file()is used to place the source file into the destination folder, which resides on the server.


If the uploading is successful, the message “The file filename has been uploaded. Otherwise the error message “There was an error while uploading the file” would be displayed.

Report Error

View answer Workspace Report Error Discuss

Subject: PHP - Technology

0 2048
Q:

Explain how to send large amounts of emails with php.

Answer

The mail() function of PHP is quite robust for sending bulk emails. A SMTP server can also be directly used from the script. PHPmailer class can be used for sending emails.

Report Error

View answer Workspace Report Error Discuss

Subject: PHP - Technology

0 2266
Q:

Explain Superglobal variables in PHP .

Answer

To access the global data which is originating externally, the super globals are used. The superglobals are available as arrays. These superglobals represents the data from URLs, HTML forms, cookies, sessions and also the web server. For this purpose, $HTTP_GET_VARS, $HTTP_POST_VARS are used. The super globals are pretty good enough to be used in functions. The following are the list of super globals.


$_GET, $_POST, $_COOKIE;$_REQUEST, $_SERVER, $_SESSION, $_ENV, $_FILE


Another PHP Superglobal, called $GLOBALS; is available for persisting every variable with global scope.

Report Error

View answer Workspace Report Error Discuss

Subject: PHP - Technology

0 3980
Q:

Describe how to create a simple AD rotator script without using database in PHP.

Answer

Following are the steps to create a simple AD rotator script without using database in PHP:


- All the ad’s can be collected in one place and be displayed randomly.rand() function can be used for this purpose.


- In order to NOT use any database, a flat file can be used to store the ad’s.


- In order to store the Ad’s information (HTML code), a flat file say “ad.txt” can be created.


- The random number can be stored in a variable 


$result_random=rand(1, 100);


- Conditions can be checked to display the ad’s.


if($result_random<=70)


{


      echo "Display ad1";


}

Report Error

View answer Workspace Report Error Discuss

Subject: PHP - Technology

1 2842
Q:

Explain how to work with Permissions in PHP.

Answer

Permissions in PHP are very similar to UNIX. Each file has three types of permissions – Read, write and execute. Permissions can be changed using the change mode or CHMOD command. CHMOD is followed by 3 digit number specifying the permission type. CHMOD 777 is for Read, Write and execute.


Unnecessary permissions can be stripped off using UNMASK command.


Unmask (777);

Report Error

View answer Workspace Report Error Discuss

Subject: PHP - Technology

0 2425