如何从头到尾注释掉整个PHP代码?

时间:2018-09-20 23:47:58

标签: php wordpress

这是Wordpress中的默认代码,我想摆脱它,但不一定要永远将其完全删除:

<?php if ( is_active_sidebar( 'sidebar' ) ) : ?>

<div class="sidebar fright" role="complementary">

    <?php dynamic_sidebar( 'sidebar' ); ?>

</div><!-- .sidebar -->

<?php else : ?>

<div class="sidebar fright" role="complementary">

    <div id="search" class="widget widget_search">

        <div class="widget-content">

            <?php get_search_form(); ?>

        </div>

    </div><!-- .widget_search -->

    <div class="widget widget_recent_entries">

        <div class="widget-content">

            <h3 class="widget-title"><?php _e("Latest posts", "baskerville") ?></h3>

            <ul>
                <?php
                    $args = array( 'numberposts' => '5', 'post_status' => 'publish' );
                    $recent_posts = wp_get_recent_posts( $args );
                    foreach( $recent_posts as $recent ){
                        echo '<li><a href="' . get_permalink( $recent["ID"]) . '" title="' . esc_attr( $recent["post_title"]).'" >' .   $recent["post_title"] . '</a></li>';
                    }
                ?>
            </ul>

        </div>

        <div class="clear"></div>

    </div><!-- .widget_recent_entries -->

    <div class="widget widget_text">

        <div class="widget-content">

            <h3 class="widget-title"><?php _e( "Text widget", "baskerville" ); ?></h3>

        </div>

        <div class="clear"></div>

    </div><!-- .widget_recent_entries -->

</div><!-- .sidebar -->

<?php endif; ?>

如何注释掉整个代码?如果我只是在开始时做了,那是行不通的。

2 个答案:

答案 0 :(得分:2)

标准的PHP注释语法为:

// comment(单线)

/* multiple lines of code */多行

请注意,如果您混合使用了PHP和纯HTML(未包含在PHP标记中),则可能会遇到一些不正常的行为,因为/* blah */会阻止PHP解释器使用实际上包含在PHP中的代码进行工作标记,但不会注释掉纯HTML,而您希望省略的那段代码确实有

答案 1 :(得分:1)

如果您想成为大型黑客,只需在以下几行中更改

public class AuthSessionFilter extends OncePerRequestFilter {

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
            throws ServletException, IOException {

        Authentication auth = new AuthSessionToken(request.getHeader("sessionId"));
        SecurityContextHolder.getContext().setAuthentication(auth);

        filterChain.doFilter(request, response);
    }
}

成为

public class AuthSessionAuthenticationProvider implements AuthenticationProvider {

    //...

    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {

        AuthSessionToken token = (AuthSessionToken) authentication;

        if (token.getSessionId() == null) {
            throw new AccessDeniedException("Missing header sessionId");
        }

        AuthSessionAuthorities user = authSessionService.getUserAuthoritiesToken(token.getSessionId());

        if (user == null) {
            throw new AccessDeniedException("Session ID invalid: " + token.getSessionId());
        }

        token.setAuthenticatedUser(user);
        return token;
    }

    //...

}

这意味着整段代码将永远不会被击中!