doubeiji2602 2016-07-05 12:08
浏览 93
已采纳

在wordpress生成的页面中包含php文件

I'm working on registration form and use a simple captcha php script to generate captcha image.

This is the html code used to display the captcha image on the page

<img id="img" src="captcha.php">

Everything worked fine on the static version of the page, but the image doesn't show on Wordpress generated page.

Is it possible to display my captcha image in Wordpress page without using any plugins ?

EDIT: I'm adding a bit more of my code

My page.php file

<?php get_header(); ?>
<?php while ( have_posts() ) : the_post(); ?>
  <div class="row">
    <div class="col-md-9 col-left-outer">
        <div class="col-md-12 col-left">
            <img id="img" src="'.home_url().'/captcha.php"> <-- Added this line to test if captcha will display from page.php file -->
            <?php the_content(); ?>
        </div>
    </div>
    <div class="col-md-3">
        <div class="col-md-12 col-right">
          <!-- Archive Side Navigation -->
            <?php get_sidebar(); ?>
        </div>
    </div>
  </div>
 <!-- /.row -->
<?php endwhile; wp_reset_query(); ?>
<?php get_footer(); ?>

The code I input in the textbox in Wordpress dashboard

<div class="row">
   <div class="col-lg-4 col-md-4">
      <label for="InputName">Παρακαλούμε, εισάγετε CAPTCHA</label>        
      <img id="img" src="'.home_url().'/captcha.php">
      <input id="captcha1" class="form-control" name="captcha" type="text" required>
   </div>
</div>
  • 写回答

1条回答 默认 最新

  • dongyuan8024 2016-07-05 12:43
    关注

    Since WP uses .htaccess to rewrite, you should not use a relative path as in
    src="captcha.php", but an absolute path like
    src="http://www.example.com/wp/captcha.php" or
    src="/wp/captcha.php"

    You will have to adapt the paths above to your configuration.

    WP knows where your site is located, so to be independent, use something like:

    <?php
    echo '<img id="img" src="' . home_url() . '/captcha.php">';
    

    or

    <img id="img" src="<? php echo home_url() ?>/captcha.php">
    

    Edit:
    <?php will only work if in a plugin or template. If your html code is only in a WP Widget text Content, the PHP will not be parsed for security reasons.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 鼠标右键,撤销删除 复制 移动,要怎样删除
  • ¥15 使用MATLAB进行余弦相似度计算加速
  • ¥15 服务器安装php5.6版本
  • ¥15 我想用51单片机和数码管做一个从0开始的计数表 我写了一串代码 但是放到单片机里面数码管只闪烁一下然后熄灭
  • ¥20 系统工程中,状态空间模型中状态方程的应用。请猛男来完整讲一下下面所有问题
  • ¥15 我想在WPF的Model Code中获取ViewModel Code中的一个参数
  • ¥15 arcgis处理土地利用道路 建筑 林地分类
  • ¥20 使用visual studio 工具用C++语音,调用openslsx库读取excel文件的sheet问题
  • ¥100 寻会做云闪付tn转h5支付链接的技术
  • ¥15 DockerSwarm跨节点无法访问问题