安全吗?由用户将数据插入数据库..?

发布于 2024-10-07 18:52:07 字数 492 浏览 0 评论 0原文

我试图让访问者可以从前端或(索引页面)而不是管理页面注册..

首先,我制作了模板页面,名称为:注册用户

,但我担心用户是否会做坏事(sql注入..等)..

这是我的代码..

if(!empty($_POST['user_name']) || !empty($_POST['email'])){
$user_login  = $_POST['user_name'];
$user_email  = $_POST['email'];
$random_password = wp_generate_password(5 , true );
wp_create_user( $user_login, $random_password, $user_email )

} else {
echo 'The user name or E-mail is empty';

}

另外,怎么知道这是电子邮件还是不是?

抱歉,我的语言不好>_<

I'm tring to make the visitor can register from the front end or (the index page )not admin page ..

firstly , I made the template page , it is name : Register User

but I am afraid if the user can do somthing bad (sql injection .. etc) ..

this is my code ..

if(!empty($_POST['user_name']) || !empty($_POST['email'])){
$user_login  = $_POST['user_name'];
$user_email  = $_POST['email'];
$random_password = wp_generate_password(5 , true );
wp_create_user( $user_login, $random_password, $user_email )

} else {
echo 'The user name or E-mail is empty';

}

also , how can know this is email or not ?

sorry , my language is bad >_<

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

灯角 2024-10-14 18:52:07

您可以使用wordpress中已经包含的功能:

详细信息在这里:
http://codex.wordpress.org/Function_Reference/is_email

is_email()

<?php if ( is_email( '[email protected]' ) ) {
      echo 'email address is valid.';
} ?>

可能还想使用函数 username_exists()

http 验证“用户名” ://codex.wordpress.org/Function_Reference/username_exists

<?php  
       $username = $_POST['username'];
       if ( username_exists( $username ) )
           echo "Username In Use!";
       else
           echo "Username Not In Use!";
?>

You can use the already included function in wordpress:

Details here:
http://codex.wordpress.org/Function_Reference/is_email

is_email()

<?php if ( is_email( '[email protected]' ) ) {
      echo 'email address is valid.';
} ?>

Might also want to validate the 'username' using the function username_exists()

http://codex.wordpress.org/Function_Reference/username_exists

<?php  
       $username = $_POST['username'];
       if ( username_exists( $username ) )
           echo "Username In Use!";
       else
           echo "Username Not In Use!";
?>
仙女 2024-10-14 18:52:07

这取决于 wp_create_user 函数 - 它是否为您清理/转义数据?如果没有,您可能需要自己执行此操作(请参阅 mysql_real_escape_string )

That depends on the wp_create_user function - is it sanitizing/escaping the data for you? If not, you may need to do it yourself (see mysql_real_escape_string)

无法回应 2024-10-14 18:52:07

wp_create_user 函数应该可以安全地发送用户输入。

第二部分由 Jakub 回答

The wp_create_user function should be safe to just send user-input to.

The second part is answered by Jakub

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文