PHP Questions and Answers Part-23

1. Which one of the following function is used to send an email using PHP script?
a) mail_send()
b) send_mail()
c) mailrr()
d) mail()

Answer: d
Explanation: The function mail() allows you to send emails directly from a script. Using mail(string to, string subject, string message), you can send any mail.

2. How many configuration directives pertinent to PHP’s mail function are available?
a) 4
b) 5
c) 6
d) 7

Answer: b
Explanation: They are- SMTP, sendmail_from, sendmail_path, smtp_port, mail.force_extra_parameters.

3. Which of the following statements is used to add an attachment to the mail?
a) $mimemail->attachment(‘attachment.pdf’);
b) $mimemail=>attachment(‘attachment.pdf’);
c) $mimemail->addAttachment(‘attachment.pdf’);
d) $mimemail=>addAttachment(‘attachment.pdf’);

Answer: c
Explanation: Call the Mail_Mime object’s addAttachment() method passing in the attachment name and extension.

4. Which one of the following is the very first task executed by a session enabled page?
a) Delete the previous session
b) Start a new session
c) Check whether a valid session exists
d) Handle the session

Answer: c
Explanation: The session variables are set with the PHP global variable which is $_SESSION. The very first task executed by a session enabled page is Check whether a valid session exists.

5. How many ways can a session data be stored?
a) 3
b) 4
c) 5
d) 6

Answer: b
Explanation: Within flat files(files), within volatile memory(mm), using the SQLite database(sqlite), or through user defined functions(user).

6. Which directive determines how the session information will be stored?
a) save_data
b) session.save
c) session.save_data
d) session.save_handler

Answer: d
Explanation: The class SessionHandler is used to wrap whatever internal save handler is set as defined by the session.save_handler configuration directive which is usually files by default.

7. If session.use_cookie is set to 0, this results in use of _____________
a) Session
b) Cookie
c) URL rewriting
d) Nothing happens

Answer: c
Explanation: The URL rewriting allows to completely separate the URL from the resource. URL rewriting can turn unsightly URLs into nice ones with a lot less agony and expense than picking a good domain name. It enables to fill out your URLs with friendly, readable keywords without affecting the underlying structure of pages.

8. If the directive session.cookie_lifetime is set to 3600, the cookie will live until ____________
a) 3600 sec
b) 3600 min
c) 3600 hrs
d) the browser is restarted

Answer: a
Explanation: The lifetime is specified in seconds, so if the cookie should live 1 hour, this directive should be set to 3600.

9. Neglecting to set which of the following cookie will result in the cookie’s domain being set to the host name of the server which generated it.
a) session.domain
b) session.path
c) session.cookie_path
d) session.cookie_domain

Answer: d
Explanation: The directive session.cookie_domain determines the domain for which the cookie is valid.

10. What is the default number of seconds that cached session pages are made available before the new pages are created?
a) 360
b) 180
c) 3600
d) 1800

Answer: b
Explanation: The directive which determines this is session.cache_expire.