Archive for November, 2007

$message = This is a Multipart Message in (Net web server)

Wednesday, November 28th, 2007

$message = This is a Multipart Message in MIME formatn ; $message .= –$boundaryn ; $message .= Content-type: text/html; charset=iso-8859-1n ; $message .= Content-Transfer-Encoding: 7bitnn ; $message .= $confirmmessage . n ; $message .= –$boundaryn ; $message .= Content-Type: text/plain; charset= iso-8859-1 n ; $message .= Content-Transfer-Encoding: 7bitnn ; $message .= $textconfirm . n ; $message .= –$boundary– ; The variable $confirmmessage is the HTML version of the confirmation e-mail. The variable $text confirm is the plain-text version. The variable $message is the entire message, coded to send both plain and HTML e-mails. Note where you insert the $confirmmessage and $textconfirm variables in the multipart message. Finally, the following sends the e-mail. Don t be confused by the variable $from. That actually controls who this e-mail is being sent to. That s the whole idea behind sending out this confirmation e-mail. $mailsent = mail($from, $confirmsubject, $message, $headers); When the user receives the confirmation e-mail, there is a link at the bottom: $confirmmessage .= Click here to confirm ; When the user clicks the link, confirmmail.php is loaded in his or her browser, appended with ?id= plus the unique validation ID. This is used within confirmmail.php to access the proper postcard in the database, compose the e-mail, and send it on its way. A quick reminder: If you always set your variables like this, you never have to worry about the register_globals setting in your php.ini file. $id = $_GET[ id ]; The following gets all postcards that match your ID. Of course, there should always be just one match, because $id is unique. $sql = SELECT * FROM confirm WHERE validator = $id ; The array $pcarray contains all of the postcard data you need to send the postcard to its intended recipient: $query = mysql_query($sql, $conn) or die(mysql_error()); $pcarray = mysql_fetch_array($query); Here s a little insurance to make sure you don t try to send out a postcard if no postcard data exists. (Of course, you will think of a much more elegant error message, won t you?) This might be a good place for the PHP header() function to redirect the user to a more information error page. if (!is_array($pcarray)) { echo Oops! Nothing to confirm. Please contact your administrator ; exit; } 353 Sending E-mail
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

Web design course - However, to ensure that you get the first

Monday, November 26th, 2007

However, to ensure that you get the first value in the $postcard array regardless of the key, you use the foreach() loop. You must use the if statement because if there is no $postcard array, foreach() returns an invalid argument warning. Yes, we know that currently a postcard value is always posted to the sendconf.php page, but if you make a change to postcard.php (for instance, to make the postcard image optional), you don t want sendconf.php to break, right? Let s move on. Your sendconf.php script performs an extra step you did not take care of in sendmail.php. You must temporarily store the postcard data while you await confirmation. $temp = gettimeofday(); $msec = (int) $temp[ usec ]; $msgid = md5(time() . $msec); Note the use of a new PHP function, md5().This returns a 128-bit fingerprint, or hash, of the message passed to it. For example, the md5 hash of Hello World is b10a8db164e0754105b7a99be72e3fe5. It is designed as a one-way encryption of the data passed in to it, so you cannot reverse it to discover the original value. Using a one-way hash in this manner allows you to safely have the user click on a link in their e-mail to view their postcard. If you had used a simple number or keyword, a malicious user could more easily guess the URL, and ruin all your fun guessing an md5 hash would take too long to make it worthwhile for the hacker. By passing in a time value, you can be fairly certain that the md5 hash returned will be a unique value, which you use as a unique ID for the data. It is not 100 percent guaranteed to be unique, but because it is generated based on the current time in seconds and contains 32 alphanumeric characters, you can be reasonably sure it will be unique. If you are interested in finding out more information about the md5 hash, visit RFC 1321: The MD5 Message-Digest Algorithm at www.faqs.org/rfcs/rfc1321. require( ./includes/conn_comic.php ); $sql = INSERT INTO confirm (validator, to_email, toname, from_email, . fromname, bcc_email, cc_email, subject, postcard, message) . VALUES ( $msgid , $to , $toname , $from , . $fromname , $bcc , $cc , $subject , $postcard , $messagebody ) ; $query = mysql_query($sql, $conn) or die(mysql_error()); Next, you store the postcard data temporarily until it is validated. When the user clicks the confirmation link in the e-mail to send it, the postcard is sent on to its intended recipient. $confirmsubject = Please Confirm your postcard ; $confirmmessage = Hello . $fromname . ,nn ; $confirmmessage .= Please click on the link below to confirm that . you would like to send this postcard:nn ; $confirmmessage .= $html_msg . nn ; $confirmmessage .= Click here to confirm ; $textconfirm = Hello . $fromname . ,nn ; $textconfirm .= Please visit the following URL to confirm your . postcard:nn ; $textconfirm .= http://localhost/bp5am/ch11/confirm.php . ?id= $msgid ; 352 Chapter 11
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

Web hosting directory - Next you loop through the $images array, constructing

Sunday, November 25th, 2007

Next you loop through the $images array, constructing the rest of your HTML select tag (options). The $image_url variable is set to the default image s URL: while ($imagearray = mysql_fetch_array($images)) { $iloop++; $iurl = $imagearray[ img_url ]; $idesc = $imagearray[ img_desc ]; if ($iloop == 1) { echo n ; $image_url = $imagearray[ img_url ]; } else { echo n ; } } ?> Then you place the default image on the page, just below the select box. You are going to use JavaScript to change this image whenever the user selects a different postcard from the select box. You could use PHP to do this instead, but it would reload the page every time you changed the image. Using JavaScript in this situation helps you reduce loading time and round-trips to the server. width=320 height=240 border=0 id= postcard > What follows, of course, is the JavaScript function that changes the image. It should be pretty selfexplanatory if you know JavaScript. If you don t know JavaScript, this is the JavaScript function that changes the image. If you want to know more about JavaScript, you can buy JavaScript For Dummies, Third Edition, by Emily A. Vander Veer (Wiley, 2000). Now you move on to sendconf.php. Much of it is similar to sendmail.php, so we ll just touch on some of the more important points: if (!empty($_POST[ postcard ])) { foreach($_POST[ postcard ] as $value) { $postcard = $value; } } Remember, $postcard is an array. A simpler method of getting the value of the postcard would have been to use the 0 key of the $postcard array: $postcard = $_POST[ postcard ][0]; 351 Sending E-mail
We recommend high quality webhost to host and run your jsp application: christian web host services.

By now, you should be fairly familiar (Apache web server tutorial) with

Friday, November 23rd, 2007

By now, you should be fairly familiar with using PHP to access MySQL. The file db_makeconfirm.php is pretty standard: $sql = <<

Next is a simple select statement. It will be followed by PHP code that builds the list of postcards the user will be able to select from. Note the square brackets after postcard[]. These are required so that PHP is able to access the $postcard variable as a proper array:
  • You are currently browsing the PHP Web Hosting, Tomcat, JSP, J2EE, Servlets, Struts - PHP4, PHP5 Programming Blog weblog archives for November, 2007.

  • Archives

  • Categories