电脑技术学习

WAP开发常见问题汇总篇

dn001

  <p>
   Cookie "TestCookie" was <?echo($cookieset)?>.
   Value is currently "<?echo($cookieid)?>"
  </p>
  <p>

<anchor>
Increase value
<go method="get" href="<?echo($PHP_SELF)?>?random=<?echo($random)?>"/>
</anchor>
</p>
<p>Gateway: 
  <?
    if(isset($HTTP_VIA))
{ // Is there something in the HTTP_VIA variable?
      echo($HTTP_VIA);
    }
    else {
      if(isset($HTTP_USER_AGENT))
{ // Is there something in the HTTP_USER_AGENT variable?
        echo($HTTP_USER_AGENT);
      }
      else {
// Absolutely no identifier was found
        echo("Unknown");
      }
    }
  ?>
  </p>
  </card>
  </wml>
47. 如何使用WAP设备发送E-Mail?

在HTML中有一个默认的E-Mail机制:“ mailto: 。但在WML中不好使,因此E-Mails必须通过WML表单来解决。例如:

<wml>
     <card id="edit" title="Email Editor">
      <p>From: <input type="text" name="from" format="*M"/></p>
      <p>To: <input type="text" name="to" format="*M"/></p>
      <p>Subject: <input type="text" name="subject" format="*M"/></p>
      <p>Message body: <input type="text" name="body" format="*M"/></p>
      <p>
        <anchor>Send this mail
          <go method="post" href="http://some.host/mailhandler"?action=send/">
            <postfield name="from" value="$(from)"/>
            <postfield name="to" value="$(to)"/>
            <postfield name="subject" value="$(subject)"/>
            <postfield name="body" value="$(body)"/>
          </go>
       </anchor>
      </p>
   </card>
</wml> 

在代码中的http://some.host/mailhandler是一个CGI程序,它是服务端的脚本程序,将提交的表单转换成E-Mail格式并发送出去。
如果想使用一个类似于发信的过程,就需要编辑变量名。另外发送的数据是有限的,长信息可能需要打断。
为了演示它是如何工作的,下面的 PHP 脚本可以用来处理Mail。它将格式化WML页面,告诉用户是否发出信件。在真实的应用中,应该加入检测,例如:E-Mail的合法格式。

<?
// Tell the client that this is a WML deck
    header("Content-type: text/vnd.wap.wml");
    echo("<?xml version=/"1.0/"?>/n");
    echo("<!DOCTYPE wml PUBLIC /"-//WAPFORUM//DTD WML 1.1//EN/"
/"http://www.wapforum.org/DTD/wml_1.1.xml/">/n");
// The name of your mail server
    $mailer = "wap.colorline.no";
// Format the from field
    $from = $from." (WAP user at ".$mailer.")";

// Add the from field and some character handling to the extra headers
  $extraheaders = $from."/nContent-Type: text/plain;
charset=iso-8859-1/nContent-Transfer-Encoding: 8bit";

// Start sending out the WML deck
    echo("<wml>/n");
    if(mail($to,$subject,$body,$extraheaders))
{// Use PHP's internal mail functionality
// Mail was successfully sent
      echo("<card id=/"sent/" title=/"Mail sent/">/n");
      echo("<p>Mail was sent successfully</p>/n");
      echo("</card>/n");
    }
    else {
// The mail could not be sent
      echo("<card id=/"notsent/" title=/"Mail failed/">/n"); 
      echo("<p>Unable to send mail</p>/n");