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

时间:2022-09-16 09:48:15

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

我正在编写注册表单并使用简单的验证码php脚本生成验证码图像。

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

这是用于在页面上显示验证码图像的html代码

<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.

在页面的静态版本上一切正常,但图像不会在Wordpress生成的页面上显示。

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

是否可以在不使用任何插件的情况下在Wordpress页面中显示我的验证码图像?

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

编辑:我正在添加更多的代码

My page.php file

我的page.php文件

<?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

我在Wordpress仪表板的文本框中输入的代码

<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 个解决方案

#1


1  

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"

由于WP使用.htaccess进行重写,因此不应使用src =“captcha.php”中的相对路径,而应使用src =“http://www.example.com/wp/captcha.php”之类的绝对路径或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:

WP知道您的网站所在的位置,因此要独立,请使用以下内容:

<?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.

编辑:<?php仅在插件或模板中有效。如果您的html代码仅在WP Widget文本内容中,则出于安全原因不会解析PHP。

#1


1  

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"

由于WP使用.htaccess进行重写,因此不应使用src =“captcha.php”中的相对路径,而应使用src =“http://www.example.com/wp/captcha.php”之类的绝对路径或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:

WP知道您的网站所在的位置,因此要独立,请使用以下内容:

<?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.

编辑:<?php仅在插件或模板中有效。如果您的html代码仅在WP Widget文本内容中,则出于安全原因不会解析PHP。

相关文章