0

所以我想要的是在下载通过 wordPress-plugin 高级自定义字段动态上传的文件时请求密码。我无法让它工作,这是我的代码:

html:

<div class="documentWrap">
                <?php while ( have_posts() ) : the_post(); ?>
                <?php get_template_part( 'content', 'page'); ?>
                <?php if(get_field('dokumentgrupp')): ?>
                <?php while(has_sub_field('dokumentgrupp')): ?>
                    <div class="docGroup clearfix">
                        <h2><?php the_sub_field('gruppnamn'); ?></h2>
                        <?php if(get_sub_field('filer')): ?>
                        <?php while(has_sub_field('filer')): ?>
                        <ul>
                            <li>
                                <h3><?php the_sub_field('filnamn'); ?></h3>
                                <a href="<?php the_sub_field('fil_url'); ?>">ladda ner</a>
                                <!div id="passWrap">
                                    <div id="passBox">  
                                    <?php // if( get_field('password') ): ?>
                                        <form method="post">
                                            <input name="pass" type="password" action="download_pw.php">
                                            <input type="submit" name="submit" value="ladda ner">

                                        </form>
                                    </div>

                                    <?php //endif; ?>
                                </div>
                            </li>
                        </ul>

                    <?php endwhile; ?>
                    <?php endif; ?>
                </div>
                <?php endwhile; ?>
                <?php endif; ?>
            </div>
        <?php endwhile; ?>
        </div>

下载_pw.php:

<?php 
                                                $pw = md5($_POST['pass']);
                                                $valid_pw = md5(get_sub_field('password'););
                                                $file_url = get_sub_field("fil_url");
                                                if {$pw != $valid_pw) {
                                                echo 'Tyv&auml;rr har du inte tillg&aring;ng till denna fil';
                                                }else{
                                                    header('Location: $file_url');
                                                }
?>
4

1 回答 1

0

If you are using this HTML on the front end, how about just using the built in password protection on the page/post showing the file?

Wordpress Codex: Using Password Protection

If that's not an option, how about trying something like this: https://wordpress.stackexchange.com/questions/37144/how-to-protect-uploads-if-user-is-not-logged-in

于 2013-11-08T20:51:00.113 回答