ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

13-2-1 ±H°e¶P¥dªºµ{¦¡

13-2-1 ±H°e¶P¥dªºµ{¦¡

13-2-1   ±H°e¶P¥dªºµ{¦¡¶ñ¼g¶P¥d¸ê®Æªºindex.htmºô­¶¡A³£¬O¤@¨Ç°ò¦ªºHTMLÀ³¥Î¡A¦b¦¹´N¤£¦h¥[»¡©ú¤F¡A¶P¥d¸ê®Æ¦b«ö¤U¡u¹wÄý¶P¥d¡v«ö¶s«á¡A¥ý°e¥æviewcard.phpµ{¦¡ºô­¶¡AÅý¨Ï¥ÎªÌ¥ýÀ˵ø¶P¥dªº¤º®e¡A¦Óviewcard.phpµ{¦¡ºô­¶ªº¤u§@¦³¨â­Ó¡G
1.±N¶P¥d¸ê®Æ»P§¹¾ãªº¶P¥d¹Ï¤ùÅã¥Ü¥X¨Ó¡C
  1. <?
  2. //±µ¦¬¨Ó¦Ûªí³æªºÄæ¦ì¸ê°T
  3. $fromName=$_REQUEST["fromName"];
  4. $fromEmail=$_REQUEST["fromEmail"];
  5. $toName=$_REQUEST["toName"];
  6. $toEmail=$_REQUEST["toEmail"];
  7. $Message=$_REQUEST["message"];
  8. $Card=$_REQUEST["card"];
  9. //²¤¡K
  10. <!--Åã¥Ü¶P¥dªº¤º®e¨Ñ¨Ï¥ÎªÌ½T»{-->
  11.         <div align=center>
  12.                 <table border=1 id=table1 style="font-size:10pt; border-collapse:collapse" bordercolor="#000080">
  13.                         <tr>
  14.                                 <td>¦¬¥ó¤H:<B><?=$toName;?></B><Br>
  15.                                 ¦¬¥ó«H½c:<B><?=$toEmail;?></B></td>
  16.                         </tr>
  17.                         <tr>
  18.                                 <td><img src="<?=$Card;?>"></td>
  19.                         </tr>
  20.                         <tr>
  21.                                 <td bgcolor="#CCFFFF"><?=nl2br($Message);?></td>
  22.                         </tr>
  23.                 </table>
  24.         </div>
  25. <!------------------------------>
½Æ»s¥N½X
2.±N¶P¥d¸ê®Æ¦s©ñ©óÁôÂ꺪í³æÄæ¦ì¤¤¡A¦pªG¨Ï¥ÎªÌı±o¶P¥d¤º®eµL»~¦Ó«ö¤U¡u±H¥X¶P¥d¡v«ö¶s«á¡A¥²¶·§â¶P¥d¸ê®Æ¥æ¥Ñ¡uecard.php¡vµ{¦¡ºô­¶¨Ó±N¸ê®Æ¼g¤J¸ê®Æ®w¡A¨Ã³z¹L¡uecard.php¡vµ{¦¡ºô­¶±H¥X¶P¥d»â¨ú³qª¾«Hµ¹¦¬¥óªÌ¡G
  1. <form method=POST action=ecard.php>
  2. <p align=center>
  3. <!--±H°e¶P¥d¥ÎªºÁôÂÃÄæ¦ì-->
  4. <input type=hidden name=fromName value="<?=$fromName;?>">
  5. <input type=hidden name=fromEmail value="<?=$fromEmail;?>">
  6. <input type=hidden name=toName value="<?=$toName;?>">
  7. <input type=hidden name=toEmail value="<?=$toEmail;?>">
  8. <input type=hidden name=message value="<?=$Message;?>">
  9. <input type=hidden name=card value="<?=$Card;?>">
  10. <!---------------------------------------->
  11. <input type=submit value=±H¥X¥d¤ù>
  12. <input type=button value=­×§ï¶P¥d onclick='window.history.go(-1);'>
  13. </p>        </form>
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

¶P¥d¸ê®Æªº¼g¤J
¡uecard.php¡vµ{¦¡ºô­¶²Ä¤@­Ó­º­nªº¤u§@¬O±N¬ÛÃöªº¶P¥d¸ê®Æ¼g¤J¸ê®Æ®w¡yecard.mdb¡z¡A¥H«K»â¨ú¶P¤ù®É¡ugetcard.php¡v¯à¶¶§Q¨ú±o¶P¥d¸ê®Æ¡G
  1. //³sµ²MySQL Server
  2.     $conn = mysql_connect("localhost", "root", "12345a");
  3. //¿ï¾Ü¸ê®Æ®w
  4.     mysql_select_db("ecard", $conn);
  5. //«ü©w´£¨ú¸ê®Æªº®Õ¹ï¦r¤¸ªí
  6.     mysql_query("set character set big5");
  7. //±N¶P¥d¸ê®Æ¼g¤J¸ê®Æ®w
  8. $SQL="Insert Into cardinfo (fromname,fromemail,toname,toemail,message,card) values(
  9. '$fromName','$fromEmail','$toName','$toEmail','$Message','$Card')";
  10. mysql_query($SQL);
½Æ»s¥N½X
¥»½d¨Òªº¸ê®Æªíµ²ºc¦p¤U¡G

¹Ï13-11 ¸ê®Æªíµ²ºc¡C

Äæ¦ì

¸ê®Æ«¬ºA

¨ä¥LÄÝ©Ê

CardID

Int,¦Û°Ê½s¸¹

¯Á¤ÞÄæ¦ì

Fromname

Varchar

¤j¤p50

Fromemail

Varchar

¤j¤p50¡F¥²»Ý¦³¸ê®Æ

Toname

Varchar

¤j¤p50

Toemail

Varchar

¤j¤p50¡F¥²»Ý¦³¸ê®Æ

Message

text

Card

Varchar

¤j¤p10




´£¥Ü!!
¦b½d¨Ò¥úºÐ\DataBase¥Ø¿ý¤¤¦³¤@­ÓMySQL¸ê®Æ®w¡uecard¡v¡AÀɮצWºÙ¬°¡uECARD.sql¡v¡A½Ð±z±NÀɮ׽ƻs¨ì±zªºµwºÐ¸Ì¨Ã¨Ï¥ÎphpMyAdmin±N¨ä¸ü¤J¨ìMySQL Server¤¤¡A±z¥iª½±µ¥[¥H§Q¥Î¡C
ecard.sql (840 Bytes)
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

³qª¾«Hªº±H°e
­n±H°e³qª¾«H¡A¥»½d¨Ò¦¹¦¸¨ÌµM¨Ï¥ÎCODNTS.NewMailª«¥ó±H°e¶l¥ó¡A¦]¬°³qª¾«H¤¤¦³¤@­Ó»â¨ú¶P¥dªººô§}³sµ²¡A¦Ó¦¹ºô§}ªº²£¥Í¤è¦¡¦p¤U¡G
  1. //³]©w¨Ó¯¸¨ú±o¥d¤ùªººô­¶ºô§}¦ì¸m
  2. $httpUrl=$_SERVER["SERVER_NAME"];
  3. $basUrl=$_SERVER["PHP_SELF"];
  4. $Pos=strrpos($basUrl,'/');
  5. $basUrl=substr($basUrl,0,$Pos);
  6. $CardID=mysql_insert_id($conn);
  7. $CardUrl="http://" . $httpUrl . $basUrl ."/getcard.php?CardID=" . $CardID;
½Æ»s¥N½X
¨ä¤¤¡G

  • $_SERVER["SERVER_NAME"]¡G¥Î¥H¨ú±o¦øªA¾¹¦WºÙ¡C
  • $_SERVER["PHP_SELF"]¡G¨ú±oºô­¶¥»¨­ªººô§}¡C


¨Ò¦p¡Gecard.phpµ{¦¡ºô­¶¦ì©ó¡uhttp://www.twbts.com/ecard/ecard.php¡v¡A«h$_SERVER["SERVER_NAME"]¥i¨ú±o¡ywww.twbts.com¡z¡A¦Ó$_SERVER["PHP_SELF"]¨ú±o¡y/ecard/ecard.php¡z¡C
»â¨ú¶P¥dªººô§}³sµ²»Ý­n$_SERVER["SERVER_NAME"]¨ú±o¡ywww.twbts.com¡z¡A¦ý$_SERVER["PHP_SELF"]¨ú±oªººô­¶¦ì¸m¡y/ecard/ecard.php¡z¡A§Ú­Ì«o¥u»Ý­n¨ä¤¤ªº¡y/ecard/¡z¡A©Ò¥H¥i§Q¥Îstrrpos()»Psubstr()¨ç¼Æ¨ÓÂ^¨ú§Ú­Ì»Ý­nªº³¡¥÷¡C
¥Ñ©ó³qª¾«H°ò¥»ªº«H¥ó¤j³¡¤À¤º®e¬O©T©wªº¡A¥u¦³±H¥ó¤H¸ê°T¸ò¶P¥dªºÅª¨úºô§}·|ÅÜ¡A©Ò¥H«H¥óªº¤º®e¥i¥H©T©w¦s©ñ©ó¤@­ÓÀɮסA¨Ò¦p¥»½d¨Ò±N«H¥ó¤º®e¦s©ñ©ómail.htmºô­¶ÀÉ¡A¨ä¤º®e¦p¤U¡G
  1. "{name}"({email})¦b "³Â»¶¾Ç¶é" ¿ï¤F¤@±i¥d¤ù±Hµ¹§A³á¡I

  2. ¥d¤ù»â¨ú¿ìªk¡G
  3. ½ÐÂI¿ï¥H¤Uºô§}«e©¹¦¬¨ú(30¤Ñ¤º¦³®Ä)¡C
  4. {url}

  5. ¯¬§A¦¬¥d´r§Ö¡I
  6. ³Â»¶¾Ç¶é¶P¥d¤p²Õ ·q¤W
½Æ»s¥N½X
¨ä¤¤¡u{name}¡v¬°±H¥óªÌ¡B¡u{email}¡v¬°±H¥óªÌEmail«H½c¡B¡u{url}¡v¬°¶P¥d»â¨úºô§}¡C
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

­Y­n¶i¦æÀɮתº¦s¨ú°Ê§@¥²¶·¥ýfopen()¨ç¼Æ¶}±Ò¯S©wªºÀɮסA¥H«K¶i¦æÀɮתº¦U¶µ³B²z§@¥Î¡C·íÀɮ׳Q¦¨¥\¶}±Ò¤§«á¡A§Ú­Ì´N¥i¥H§Q¥Îfilesize()¨ç¼Æ±oª¾Àɮתº¤j¤p¡AµM«á©I¥sfread()¤èªk¨ÓŪ¨ú§¹¾ãªºÀɮפº®e¡G
  1. //Ū¨ú¥d¤ù»â¨ú³qª¾ªººô­¶¤º®e
  2. $fs=fopen("mail.htm","r");
  3. $body=fread($fs,filesize("mail.htm"));
  4. fclose($fs);
½Æ»s¥N½X
­n¸m´«¯S©wÃöÁä¦r«h¥i¨Ï¥Îstr_replace()¨ç¼Æ¡A¨Ò¦p¥»½d¨Ò¸m´«¡u{name}¡v¡B¡u{email}¡v¡B¡u{url}¡v¬°±H¥óªÌ¡B±H¥óªÌEmail«H½c¡B¶P¥d¨úºô§}¡G
  1. //¸m´«¥d¤ù»â¨ú³qª¾«H¥óªº¤º®e
  2. $body=str_replace("{name}", $toName, $body);
  3. $body=str_replace("{email}", $toEmail, $body);
  4. $body=str_replace("{url}", $CardUrl, $body);
½Æ»s¥N½X
¯S§Oª`·N¨ì¡u{url}¡vªº¸m´«³¡¥÷¡G
  1. $CardUrl="http://" . $httpUrl . $basUrl ."/getcard.php?CardID=" . $CardID;
½Æ»s¥N½X
Getcard.php¬°­t³dŪ¨ú¶P¥dªºµ{¦¡ºô­¶¡A¦¹µ{¦¡ºô­¶¦b°õ¦æ®É¡A¥²¶·¶Ç»¼¤@­Ó¡uCardID¡v°Ñ¼Æ¡A¦¹°Ñ¼Æ­È§Y¬°¶P¥d°O¿ýªº½s¸¹¡A¤]´N¬O»â¨ú¶P¥dªº½s¸¹¡A¨Ò¦p¬Y±i¶P¥d¬ö¿ý¼g¤J¸ê®Æ®w¡A¸Ó¬ö¿ýªº¡uCardID¡vÄæ¦ì­È¬°3¡A«h»â¨ú¸Ó¶P¥dªº³sµ²ºô§}´N¦p¤U©Ò¥Ü¡G
  1. http://localhost/ch13/ecard/getcard.php?CardID=3
½Æ»s¥N½X
  ´£¥Ü!!PHP ¨ç¼Æmysql_insert_id()¡A¥i¨ú±o³Ì«á¤@¦¸°õ¦æ¤F·s¼W¬d¸ß¡]INSERT¡^«á¡A¥ÑAUTO_INCREMENT ©w¸qªºÄæ¦ì­È¡C
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

        ÀR«ä¦Û¦b : ¡i®É¶¡µLªk¾B¾×¡j©È®É¶¡®ø³u¡Aªá¤F³\¦h¤ß¦å¡A·QºÉ¦U¦¡¤èªk­n¾B¾×®É¶¡¡Aµ²ªG¬O¡G®ö¶O¤F§ó¦h®É¶¡¡A¥B¤@µL©Ò¦¨¡I
ªð¦^¦Cªí ¤W¤@¥DÃD