| 第十四週電子郵件確認信<?php /* 程式結構 $ccode=$_GET["ccode"]; $command=$_POST["command"]; if ($command==null && ccode==null) { 顯示第一個頁面 } if ($command=="註冊") { 取出資料處理並寄信 } if ($command==null && ccode<>null) { 取出識別碼與帳號處理 } */ $command=$_POST["command"]; $curr_ccode=$_GET["ccode"]; if ($command==null && $curr_ccode==null) { echo "<html><body><center> 註冊後系統會寄一封確認信至您的信箱,開啟後確認成功才能啟用帳號 <form method='post' action=''> 電子郵件帳號:<input type='text' name='username'> 密碼:<input type='password' name='password'> <input type='submit' name='command' value='註冊'> </form></center></body></html>"; } if ($command=="註冊") { $to=$_POST["username"]; $password=$_POST["password"]; if ($to=="" || $password=="") { echo "電子郵件或帳號欄不能空白,請回前頁重新輸入"; die(); } // 儲存電子郵件帳號與密碼 $ccode=md5(uniqid(rand())); // 產生惟一的識別碼 $message="xxxx君您好<br><br>"; $message.=" 請直接點擊下列連結來確認此註冊信<br><br>"; $message.="http://localhost/register.php?ccode=$ccode&username=$username"; $message.="&password=$password<br><br>"; $mailserver="ccs.cust.edu.tw"; $subject = "註冊確認"; $from = "s10014dxxx@ccs.cust.edu.tw"; $from.="\nContent-Type:text/html;charset=utf-8"; ini_set("SMTP",$mailserver); ini_set("sendmail_from",$mailfrom); $message=iconv("big5","UTF-8",$message); $headers = "From:" . $from; $ok=mail($to,$subject,$message,$headers); if (!$ok) { echo "系統無法發送確認信至您的Email信箱,請稍候再試"; die(); } echo "系統已經發送一封確認信至您的Email信箱<p>請立即開啟Email進行註冊確認"; $fp=fopen("register.txt","w"); fputs($fp,$to); fputs($fp,"\r\n"); fputs($fp,$password); fputs($fp,"\r\n"); } if ($command==null && $curr_ccode<>null) { //完成此程式作確認動作, 由檔案中讀出先前寫入的電子郵件帳號與密碼進行比較 如果正確則顯示註冊確認成功 } ?> | |