plugins - Sanitize $_GET variable when comparing

I know when I want to save data in database, I must sanitize data but what about following case which is a simple compar

I know when I want to save data in database, I must sanitize data but what about following case which is a simple comparison. Should I sanitize?

if ( ! isset( $_GET['page'] ) ) {
        return;
}

if ( 'google' === $_GET['page'] ) {
    wp_redirect( '' );
    exit;
}

if ( 'facebook' === $_GET['page'] ) {
    wp_redirect( '' );
    exit;
}

I know when I want to save data in database, I must sanitize data but what about following case which is a simple comparison. Should I sanitize?

if ( ! isset( $_GET['page'] ) ) {
        return;
}

if ( 'google' === $_GET['page'] ) {
    wp_redirect( 'https://google' );
    exit;
}

if ( 'facebook' === $_GET['page'] ) {
    wp_redirect( 'https://facebook' );
    exit;
}
Share Improve this question asked May 27, 2019 at 3:08 user3631047user3631047 1731 silver badge7 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

No, it's not necessary to sanitise in this case.

If you were redirecting to the value directly, or outputting it in some way, you would definitely need to, but since you're just comparing its value against a white list (essentially) no sanitising or escaping is necessary.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745461952a4628746.html

相关推荐

  • plugins - Sanitize $_GET variable when comparing

    I know when I want to save data in database, I must sanitize data but what about following case which is a simple compar

    4小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信