Zend PHP Certification Study Guide- P8 - Pdf 66

124
Chapter 7 Managing Dates and Times
Also, certain time formats can befuddle
strtotime()
. For example, this code will
cause
$ts
to be set to
-1
, indicating an error:
$ts = strtotime(“Fri, 9 Jan 2004 03:26:23 +0000 GMT”);
strtotime()
has become confused because two separate time zone offsets (
+0000
and
GMT
) were both specified. If you are manually constructing all the inputs to
strtotime()
(for example, to take advantage of the
next week
/
last week
functionality) this is not
an issue, as you can test your inputs to make sure that they are all correctly handled.
However, if you are using
strtotime()
to handle arbitrarily formatted date entries (for
example, submitted free form through a web page), you should take into account the
possibility of both incomprehensible and improperly interpreted dates.
One of the best aspects of
strtotime()

date()
, it will use the current time.
2. The ________ function will return the current UNIX time stamp.
The correct answer is
time()
.
3. Which of the following functions will output the current time as
11:26 pm
?
A. print date(‘H:m a’);
B. print date(‘G:M a’);
C. print date(‘G:i a’);
D. print strftime(‘%I:%M %p’);
The correct answers are C and D.
08 7090 ch07 7/16/04 8:44 AM Page 124
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
125
Exam Prep Questions
4. The PHP date functions are only guaranteed to work for dates after _____.
A. January 1, 1970 00:00:00
B. January 1, 1900 00:00:00
C. January 1, 1963 00:00:00
D. January 18, 2038 22:14:07
The correct answer is A.The UNIX epoch is January 1, 1970 00:00:00 UTC. On
32-bit systems, the date functions are only guaranteed to work until January 19,
2038.
5. Internally PHP handles dates and times as
A. A ‘date array’ array consisting of the year, month, day, hour, minute, and
second.
B. A UNIX time stamp representing the number of seconds since the UNIX

sendmail_from
(Windows only)
n
sendmail_path
Techniques You’ll Need to Master
n
Mail functions
n
URL functions
How Email Is Delivered
If you are going to be writing and deploying PHP scripts that generate and send email
messages, you need to know something about how email gets delivered around the
Internet.This will help you better understand and support your customers when prob-
lems arise. Figure 8.1 shows the main components of the email architecture.
09 7090 ch08 7/16/04 8:45 AM Page 127
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
128
Chapter 8 Managing Email
Figure 8.1 How email is delivered.
Here are the standard terms that you will come across at some point or another.
MTA—Mail Transport Agent
When email is sent from organization to organization, it is sent from email server to
email server.The software that runs on your email server and handles sending and
receiving email from around the Internet is called the Mail Transport Agent (MTA for
short). Examples of Mail Transport Agents are
n
sendmail
n
postfix
n

May authenticate via SASL
Receives email via
IMAP or POP3
Mail Server
(runs MTA)
DNS Server
(provides MX records)
Requests MX
records via DNS
Personal Computer
(runs MUA)
Resolves hostnames via DNS
09 7090 ch08 7/16/04 8:45 AM Page 128
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
129
How Email Is Delivered
The email domain isn’t the real name of a server. It looks like a real name (and has to
follow the same rules), but it isn’t. It’s actually a special kind of DNS alias.
To receive email for your email domain, you have to add an MX record for that email
domain to your DNS server.
Note
If you don’t set up an MX record in your DNS server, the MTA will look for a matching A record instead.
MUA—Mail User Agent
The Mail User Agent (MUA) is the jargon name for an email client.
Examples of Mail User Agents are
n
Outlook Express
n
Evolution
n

Chapter 8 Managing Email
Junk email filters have become very popular.They can be added both to the MTA
and/or the MUA. It’s a fair bet that most of the email that these filters mark as ‘junk’
never gets read by a human. Junk email filters aren’t perfect; genuine email that looks
very like real junk email will also get marked as junk.When you roll out a PHP applica-
tion that sends email, you should perform some tests with your customer to make sure
that your email will get past whatever junk email filter your customer uses.
Because of repeated security holes in MUAs, the more tech-savvy businesses and users
do not accept delivery of HTML email. It’s very tempting to send HTML email—such
emails look so much nicer than plain-text email.You should ensure that any PHP appli-
cation you write that sends email always gives the user the option to choose between
plain-text email and HTML email.You should never only support HTML email.
If you write and sell PHP software that works with email, it’s important that you keep
abreast of the new technologies that are always coming out.When capturing require-
ments from your customer, always make sure that you’ve agreed what email technologies
the customer has adopted—or is planning to adopt within six months of the end of your
project.The customer will (somewhat naively) expect your PHP application to work
perfectly with whatever changes he plans to make to his email infrastructure—and will
blame you if it doesn’t.
Preparing PHP
Before you can send email from your PHP script, you must first ensure that your copy of
PHP has been correctly configured.
If You Are Using PHP on UNIX
To send email from a PHP script running on UNIX, you must have a sendmail-
compatible MTA installed on the same server that your PHP script runs on.
On UNIX systems, PHP sends email by running the command-line program
sendmail
.
sendmail
is the de facto standard MTA for UNIX systems.

n
mb_send_mail()
—will always return
false
09 7090 ch08 7/16/04 8:45 AM Page 130
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
131
Preparing PHP
When this happens, you must install a sendmail wrapper, and then recompile PHP.
Once PHP is compiled with sendmail support enabled, whenever your script sends
email, PHP will use the
sendmail
command discovered by the
configure
script. If you
ever need to override this default, set the
sendmail_path
in
php.ini
to point to the
sendmail
command that you want PHP to use.
sendmail_path = ‘/usr/local/bin/sendmail’
If You Are Using PHP on Windows or Netware
Although not documented in the PHP Manual, if you set the
sendmail_path
setting in
your
php.ini
file, PHP will attempt to send email via the sendmail_wrapper—behaving

tication, you will need to change the security on your MTA to enable PHP to send
emails through successfully.
On UNIX, the MTA will automatically say that the email is from whichever user
your PHP script is running as.
This can’t be done on Windows because PHP is connecting to the MTA over the
network via SMTP. Instead, PHP will work out who the email is from by looking in
these places in this order:
n
the
from:
header line passed to the
mail()
function
n
the
sendmail_from
setting in the
php.ini
file
09 7090 ch08 7/16/04 8:45 AM Page 131
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status