【发布时间】:2020-11-18 07:24:21
【问题描述】:
我目前正在使用 Wordpress 创建一个网站,我正在创建我的主题并且我没有使用 jQuery。我需要介绍一个简单的联系表单,它会在提交时发送一封电子邮件,并且所有插件都需要 jquery 才能工作。
创建发送电子邮件的联系表单是否安全?提交时不查询数据库,是否存在 SQL 注入风险?
我的安全技能很少,欢迎任何信息或澄清
【问题讨论】:
标签: php sql database wordpress email
我目前正在使用 Wordpress 创建一个网站,我正在创建我的主题并且我没有使用 jQuery。我需要介绍一个简单的联系表单,它会在提交时发送一封电子邮件,并且所有插件都需要 jquery 才能工作。
创建发送电子邮件的联系表单是否安全?提交时不查询数据库,是否存在 SQL 注入风险?
我的安全技能很少,欢迎任何信息或澄清
【问题讨论】:
标签: php sql database wordpress email
例如:
$name = "{$_POST['message_name']} {$_POST['message_lastname']}"; // I like to combine first and lastname in to 1 variable.
$email = $_POST['message_email'];
$website = $_POST['message_url'];
$message = $_POST['message_description'];
if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
$response = form_validation_response( 'error', $email_invalid );
} else {
if ( empty( $name ) || empty( $message) ) {
$response = form_validation_response( 'error', $missing_content );
}
}
// The most simple check you can do is make sre that the fields are NOT empty.
form_validation_response 方法是一个简单的函数,可以用来返回错误信息:
$not_human = "Human verification incorrect.";
$missing_content = "Please supply all information.";
$email_invalid = "Email Address Invalid.";
$message_unsent = "Message was not sent. Try Again.";
$message_sent = "Thanks! Your message has been sent.";
function form_validation_response( $type, $message ) {
$class = 'px-2 py-1 mb-6 rounded-md' // These are tailwind classes, but it could be bootstrap
if ( $type == 'success' ) {
$class .= "border border-green-800 text-green-700";
} else {
$class .= "border border-redish text-redish";
}
return "<div class='{$class}'>{$message}</div>";
}
上面的示例用于验证电子邮件,但您也可以在开始验证过程之前确保字段已实际提交:
【讨论】:
如果您不熟悉创建“安全”的 php 表单,我建议您为此使用插件。
如果您“允许”安装插件,请查看“表单插件”,例如:
这只是一些可用的表单插件。然后,根据您的需要/预算,您应该决定哪个插件最适合(有些是免费、免费增值、高级等)。
【讨论】: