Chapter 11 - Review

Output
Show all Hide all
1Toggle answer visibilityWhat function is used to send email? What are the function’s arguments? What does the server need in order to send email?

To send mail in php use the mail() function. The general format for usage including arguments is:

	
		$to = 'nobody@example.com';
		$subject = 'the subject';
		$message = 'hello';
		$message = wordwrap($message, 70, "\r\n");
		$headers = 'From: webmaster@example.com';

		mail($to, $subject, $message, $headers);

In order for the email to be delivered, the host must be configured with a proper SMTP Mail Server.

2Toggle answer visibilityDoes it make a difference whether \n is used within single or double quotation marks?

\n must be used in double quotes in order to be interpreted as a new line - otherwise it will be displayed literally.

3Toggle answer visibilityCan you easily know for certain if, or when, a recipient received an email sent by PHP?

You can not know for sure whether an email has successfully been received through php. To increase your mail() success rate you can make sure your mail server is configured properly, you can validate the email address to know it is properly formed. and you can set a bounce header that will receive a message when an email bounces. Using these headers in the mail() function can help with automated replies... The from header identifies who the email purports to come from, the reply-to header to which human initiated replies will be directed and, lastly, the return-path to which automated delivery status mails are sent.

4Toggle answer visibilityWhat debugging steps can you take if you aren’t receiving any email that should be sent from a PHP script?

If you aren't receiving emails from a php script you should confirm with your host (if using a hosted site) or yourself (if running PHP on your server), that there's a working mail server installed. You should also test the script using different email addresses (for both the to and from values). Also, watch that your spam filter isn't eating up the message.

5Toggle answer visibilityHow do folder permissions come into play for handling uploaded files?

The folder containing any uploaded files must have permissions of 0755 which allows read/write/execute for the owner and limits users and groups to just read and execute. This protects the folder from malicious access while allowing your scripts to alter the data as needed.

6Toggle answer visibilityWhat two directories are used in handling file uploads?

File uploads require a temporary folder and a permanent folder for storage once uploaded.

7Toggle answer visibility What additional attribute must be made to the opening form tag in order to handle a file upload?

Any form containing a file upload must include enctype="multipart/form-data"in it's opening tag. The form must also be submitted using the POST method.

8Toggle answer visibilityWhat is a MIME type?

MIME type stands for Multipurpose Internet Mail Extensions and is used to identify content being passed over the internet. It allows the web server or email client to display the content in it's proper format.

9Toggle answer visibilityIn what ways are PHP and JavaScript alike? How are they different?

Javascript is primarily a client side scripting language that has access to lots of information to manipulate the web browser and user experience. PHP is primarily server side and can interact with databases and the server environment. PHP can dynamically generate both HTML and Javascript. Javascript can be disabled in the browser which can limit functionality, so you should always perform any necessary tasks with php as backup (user input validation... etc) and javascript should not be relied on for displaying necessary content. It should be used as an accessory to enhance behavior or usability. The site should be fully accessible without it!

10Toggle answer visibilityWhat tag is used to add JavaScript to an HTML page?

Inline javascript is inserted like this:

<script type="text/javascript">your javascript code here</script>
Or you can include an external file using this:
<script type="text/javascript" src="somefile.js"></script>

11Toggle answer visibilityWhat does the var keyword mean in JavaScript?

The var keyword is the preferred method for declaring variables in javascript. It will declare a variable within the scope of it's declaration. If the variable is in the global scope, it is a global variable, else if declared in a function , the variable has local scope. If var is omitted - then the scope chain will be followed until a variable with that name is found and it's value will be overwritten which can lead to errors and difficulty in debugging.

12Toggle answer visibilityWhat is the concatenation operator in JavaScript?

You can concatenate strings in javascript using the + operator, += operator or builtin concat() method.

		 var string1 = "Hello" + " PHP " + "Percolators!";
		 var string2 += " More than half way there!";
		 var string3 = string2.concat(" This ","is ","chapter 11!");

13Toggle answer visibilityWhat does the PHP header() function do?

The php header() function is used to send a raw HTTP header in order to request a server resource. The HTTP protocol is a request/response protocol. A client sends a request to the server in the form of a request method, URI, and protocol version, followed by a MIME-like message containing request modifiers, client information, and possible body content over a connection with a server. The server responds with a status line, including the message's protocol version and a success or error code, followed by a MIME-like message containing server information, entity metainformation, and possible entity-body content.

14Toggle answer visibilityWhat do headers already sent error messages mean?

Functions that send/modify HTTP headers must be invoked before any output is made. Otherwise the call fails:
Warning: Cannot modify header information - headers already sent (output started at file:line)
Content includes white space, html code, html comments, empty lines or included files that contain ouput etc..

15Toggle answer visibilityWhat is a proxy script? When might a proxy script be necessary?

A proxy is an intermediary which acts as a host for retrieving resources indirectly for another calling script. A proxy script is necessary to retrieve data that is not directly accessible through the web root. By passing necessary information to a proxy script - that script then handles authentication, and setting appropriate headers for the return display of the resource.

16Toggle answer visibility What does the readfile() function do?

The readfile() function reads a file and writes it to the output buffer.Best used with static content that does not contain php.

		 readfile('file.php');  will just read in the file and send it out as is to the browser..
		 include('file.php');  will send that file through the php parser and evaluate the code in it....

Source
<?php 
$review = array(
	1 => array(
		'q'=>'What function is used to send email? What are the function’s arguments? What does the server need in order to send
		 email?',
		'a'=>'<p>To send mail in php use the <b>mail()</b> function. The general format for usage including arguments is:<br />
		<pre>	
		$to = \'nobody@example.com\';
		$subject = \'the subject\';
		$message = \'hello\';
		$message = wordwrap($message, 70, "\r\n");
		$headers = \'From: webmaster@example.com\';

		mail($to, $subject, $message, $headers);</pre><br />In order for the email to be delivered, the host must be 
		configured with a proper SMTP Mail Server.
		</p>'
	),
	2 => array(
		'q'=>'Does it make a difference whether \n is used within single or double quotation marks?',
		'a'=>'<p><b>\n</b> must be used in double quotes in order to be interpreted as a new line - otherwise it will be displayed
		literally.</p>'
	),
	3 => array(
		'q'=>'Can you easily know for certain if, or when, a recipient received an email sent by PHP?',
		'a'=>'<p>You can not know for sure whether an email has successfully been received through php. To increase your mail() success rate  
		you can make sure your mail server is configured properly, you can validate the email address to know it is properly formed. 
		and you can set a bounce header that will receive a message when an email bounces. Using these headers in the mail() function
		can help with automated replies... The from header identifies who the email purports to come from, the reply-to header
		 to which human initiated replies will be directed and, lastly, the return-path to which automated delivery status mails are sent.</p>'
	),
	4 => array(
		'q'=>'What debugging steps can you take if you aren’t receiving any email that should be sent from a PHP script?',
		'a'=>'<p>If you aren\'t receiving emails from a php script you should confirm with your host (if using a hosted site) or 
yourself (if running PHP on your server), that there\'s a working mail server installed. You should also test the script using different
 email addresses (for both the to and from values). Also, watch that your spam filter isn\'t eating up the message.</p>'
	),
	5 => array(
		'q'=>'How do folder permissions come into play for handling uploaded files?',
		'a'=>'<p>The folder containing any uploaded files must have permissions of 0755 which allows read/write/execute for the owner
		and limits users and groups to just read and execute. This protects the folder from malicious access while allowing your scripts
		to alter the data as needed.</p>'
	),
	6 => array(
		'q'=>'What two directories are used in handling file uploads?',
		'a'=>'<p>File uploads require a temporary folder and a permanent folder for storage once uploaded.</p>'
	),
	7 => array(
		'q'=>' What additional attribute must be made to the opening form tag in order to handle a file upload?',
		'a'=>'<p>Any form containing a file upload must include <b>enctype="multipart/form-data"</b>in it\'s opening tag. The form
		must also be submitted using the POST method.</p>'
	),
	8 => array(
		'q'=>'What is a MIME type?',
		'a'=>'<p>MIME type stands for Multipurpose Internet Mail Extensions and is used to identify content being passed over the internet.
		It allows the web server or email client to display the content in it\'s proper format.</p>'
	),
	9 => array(
		'q'=>'In what ways are PHP and JavaScript alike? How are they different?',
		'a'=>'<p>Javascript is primarily a client side scripting language that has access to lots of information to manipulate the web browser and 
		user experience. PHP is primarily server side and can interact with databases and the server environment. PHP can dynamically 
		generate both HTML and Javascript. Javascript can be disabled in the browser which can limit functionality, so you should always perform 
		any necessary tasks with php as backup (user input validation... etc) and javascript should not be relied on for displaying necessary content.
		It should be used as an accessory to enhance behavior or usability. The site should be fully accessible without it!</p>'
	),
	10 => array(
		'q'=>'What tag is used to add JavaScript to an HTML page?',
		'a'=>'<p>Inline javascript is inserted like this: <br /><pre>&lt;script type="text/javascript"&gt;your javascript code here&lt;/script></pre>
		Or you can include an external file using this: <pre>&lt;script type="text/javascript" src="somefile.js"&gt;&lt;/script&gt;</pre></p>'
	),
	11 => array(
		'q'=>'What does the var keyword mean in JavaScript?',
		'a'=>'<p>The <b>var</b> keyword is the preferred method for declaring variables in javascript. It will declare a variable within 
		the scope of it\'s declaration. If the variable is in the global scope, it is a global variable, else if declared in a function
		, the variable has local scope. If var is omitted - then the scope chain will be followed until a variable with that name is found and it\'s value
		will be overwritten which can lead to errors and difficulty in debugging.</p>'
	),
	12 => array(
		'q'=>'What is the concatenation operator in JavaScript?',
		'a'=>'<p>You can concatenate strings in javascript using the <b>+</b> operator, <b>+=</b> operator or builtin concat()
		 method.<pre>
		 var string1 = "Hello" + " PHP " + "Percolators!";
		 var string2 += " More than half way there!";
		 var string3 = string2.concat(" This ","is ","chapter 11!");</pre></p>'
	),
	13 => array(
		'q'=>'What does the PHP header() function do?',
		'a'=>'<p>The php header() function is used to send a raw HTTP header in order to request a server resource. The HTTP protocol is a request/response protocol.
		 A client sends a request to the server in the form of a request method, URI, and protocol version, followed by a MIME-like
		  message containing request modifiers, client information, and possible body content over a connection with a server. 
		  The server responds with a status line, including the message\'s protocol version and a success or error code, followed
		   by a MIME-like message containing server information, entity metainformation, and possible entity-body content.</p>'
	),
	14 => array(
		'q'=>'What do headers already sent error messages mean?',
		'a'=>'<p>Functions that send/modify HTTP headers must be invoked before any output is made. Otherwise the call fails:<br />
    <span class="error">Warning: Cannot modify header information - headers already sent (output started at file:line)</span><br />
     Content includes white space, html code, html comments, empty lines or included files that contain ouput etc..</p>'
	),
	15 => array(
		'q'=>'What is a proxy script? When might a proxy script be necessary?',
		'a'=>'<p>A proxy is an intermediary which acts as a host for retrieving resources indirectly for another calling script.
		A proxy script is necessary to retrieve data that is not directly accessible through the web root. By passing necessary information
		to a proxy script - that script then handles authentication, and setting appropriate headers for the return display of the resource.</p>'
	),
	16 => array(
		'q'=>' What does the readfile() function do?',
		'a'=>'<p>The readfile() function reads a file and writes it to the output buffer.Best used with static content that does not contain php.<pre>
		 readfile(\'file.php\');  will just read in the file and send it out as is to the browser..
		 include(\'file.php\');  will send that file through the php parser and evaluate the code in it....</pre></p>'
	)
);
include('templates/review.php');