PHP စစ်ဆေး အီးလီယာ

အရှိန်းချို့ ပါဝင်သော PHP e-mail အဘာသာကြောင်း တွင် အရေးပါသော အချက်အလက် ရှိပါသည်。

PHP E-mail Injection

ပထမပေါင်းက အရှိန်းချို့ ပါဝင်သော PHP ကို ကြည့်ပါတယ်:

<html>
<body>
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
  {
  //send email
  $email = $_REQUEST['email']; 
  $subject = $_REQUEST['subject'];
  $message = $_REQUEST['message'];
  mail("someone@example.com", "Subject: $subject",
  $message, "From: $email" );
  echo "Thank you for using our mail form";
  }
else
//if "email" is not filled out, display the form
  {
  echo "
Email:
Subject:
Message:

"; } ?>

အထူးသတ်မှတ်ထားသော အဘောင်းချက်များမှာ အခွင့်မဲ့ အသုံးပြုသူ များ ဖြင့် ဖော်ပြပုံ အိမ်တိုက် အချက်အလက် ထည့်သွင်းရန် ဖြေရှင်းခွင့်ပြုထားသည်。

သင့် အသုံးပြုသူ ပါဝင်သော ဖော်ပြမှု များ ကို ပါဝင်ထည့်သွင်းပါက ဘယ်အခါ ဖြစ်ပေါ်လာမည်များ ဖြစ်နိုင်သလဲ။

someone@example.com%0ACc:person2@example.com
%0ABcc:person3@example.com,person3@example.com,
anotherperson4@example.com,person5@example.com

PHP မိပို့စာပို့ ကာကွယ်

မိပို့စာပို့မှ ထိခိုက်မှု ကာကွယ်ကြောင်း အကောင်းဆုံး နည်းလမ်း မှာ ဆက်သွယ်ထားသော ကြောင်းရာများ အား စစ်ဆေးပါ

အောက်ပါ ကြောင်းရာ သို့မဟုတ် အပြီးပိုင်း မှာ သားရောက်ကြောင်း ရှိသည်။ ထို့ပြင် မှတ်ချက်များ ကို ထပ်ပေါင်းထားပါသည်မှာ သားရောက်ပြီးဖြစ်သည်။

<html>
<body>
<?php
function spamcheck($field)
  {
  //filter_var() sanitizes the e-mail 
  
  $field=filter_var($field, FILTER_SANITIZE_EMAIL);
  //filter_var() validates the e-mail
  
  if(filter_var($field, FILTER_VALIDATE_EMAIL))
    {
    return TRUE;
    }
  else
    {
    return FALSE;
    }
  }
if (isset($_REQUEST['email']))
  //if "email" is filled out, proceed
  //မိပို့အိမ်းအား မမှန်ကန်သလား စစ်ဆေးပါ
  $mailcheck = spamcheck($_REQUEST['email']);
  if ($mailcheck==FALSE)
    {
    echo "Invalid input";
    }
  else
    //မိပို့စာပေးပါ
    $email = $_REQUEST['email']; 
    $subject = $_REQUEST['subject'];
    $message = $_REQUEST['message'];
    mail("someone@example.com", "Subject: $subject",
    $message, "From: $email" );
    echo "Thank you for using our mail form";
    }
  }
else
  {//if "email" is not filled out, display the form
  echo "
Email:
Subject:
Message:

"; } ?>

在上面的代码中,我们使用了 PHP 过滤器来对输入进行验证:

  • FILTER_SANITIZE_EMAIL 从字符串中删除电子邮件的非法字符
  • FILTER_VALIDATE_EMAIL 验证电子邮件地址

您可以在我们的 PHP စစ်ဆေးသည့်这一节中阅读更多有关过滤器的内容。