42
368
HOUR 21:Beyond the Basics,Part 1: PHP in Expression Web 4
PHP is actually a scripting language you can use to create small programs that
behave according to your input. One of the many things you can do with PHP is
define a set of conditions that have to be met for some specific action to occur and
also say what happens if the conditions are not met.
1. If the email is sent successfully, you want the browser to be redirected to the
success.html page. To do this, you use the echo function with an HTML
metatag called Refresh to redirect the browser. Still in the emailProcessor.php
file, on a new line, type echo “<meta http-equiv=\“refresh\” content=\
“0;URL=success.html\“>“;. The Refresh metatag can delay the redirection to
a new page. The delay, measured in seconds, is defined by the content vari-
able. The backslashes in front of the quotation marks tell the PHP interpreter
that they are not PHP code, but HTML.
2. Likewise, if the email is not sent, you want the browser to be redirected to the
failure.html page. On a new line, type echo “<meta http-equiv=\“refresh\”
content=\“0;URL=failure.html\“>“;.
3. To let the server know when to say the email was sent, you first have to define
what you consider a success. In the case of the email form, a success would
mean that the mail() function executed properly. To define the mail() func-
tion executing properly as a success, place the cursor at the beginning of the
line that has the mail() function and type $success =.
Now that you have a way to measure whether the email was sent and you
have the resulting actions for what should happen in either case, you need to
make a small program that tells the server when to do what. This is done by
using the if andelse statements. Like the names suggest, the if statement
checks whether a certain condition is met. If it is, the attached action takes
place. The else statement kicks in whenever the if condition is not met. In
this case, you want the if condition to be the $success variable. If it is met,
the success.html page should display, and if not, the failure.html page should
display.
4. Create a new line above the
redirectmetatag that leads to the success.html
page and type if ($success){.
5. Create a new line directly below the
redirectmetatag and close the curly
bracket by typing }.
6. Create a new line under the last one and type else {. Close this curly bracket
on a new line after the redirect meta tag that leads to the failure.html page.
▼
▼
www.it-ebooks.info