gpt4 book ai didi

javascript - PHP fatal error : Call to undefined function esc_url()

转载 作者:行者123 更新时间:2023-12-03 12:40:37 25 4
gpt4 key购买 nike

我无法确定代码中的问题。我正在使用 WordPress 内容管理系统中的代码:

    <?php
include_once 'includes/register.inc.php';
include_once 'includes/functions.php';
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Secure Login: Registration Form</title>
<script type="text/JavaScript" src="js/sha512.js"></script>
<script type="text/JavaScript" src="js/forms.js"></script>
<link rel="stylesheet" href="styles/main.css" />
</head>
<body>
<!-- Registration form to be output if the POST variables are not
set or if the registration script caused an error. -->
<h1>Register with us</h1>
<?php
if (!empty($error_msg)) {
echo $error_msg;
}
?>
<ul>
<li>Usernames may contain only digits, upper and lower case letters and underscores</li>
<li>Emails must have a valid email format</li>
<li>Passwords must be at least 6 characters long</li>
<li>Passwords must contain
<ul>
<li>At least one upper case letter (A..Z)</li>
<li>At least one lower case letter (a..z)</li>
<li>At least one number (0..9)</li>
</ul>
</li>
<li>Your password and confirmation must match exactly</li>
</ul>
<form action="<?php echo esc_url($_SERVER['PHP_SELF']); ?>"
method="post"
name="registration_form">
Username: <input type='text'
name='username'
id='username' /><br>
Email: <input type="text" name="email" id="email" /><br>
Password: <input type="password"
name="password"
id="password"/><br>
Confirm password: <input type="password"
name="confirmpwd"
id="confirmpwd" /><br>
<input type="button"
value="Register"
onclick="return regformhash(this.form,
this.form.username,
this.form.email,
this.form.password,
this.form.confirmpwd);" />
</form>
<p>Return to the <a href="index.html">login page</a>.</p>
</body>
</html>

我收到一个错误:PHP fatal error :调用/var/www/html/register.php 中未定义的函数 esc_url()。此函数用于清理 PHP_SELF 服务器变量的输出:这是我的函数:

function esc_url($url) {

if ('' == $url) {
return $url;
}

$url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\\x80-\\xff]|i', '', $url);

$strip = array('%0d', '%0a', '%0D', '%0A');
$url = (string) $url;

$count = 1;
while ($count) {
$url = str_replace($strip, '', $url, $count);
}

$url = str_replace(';//', '://', $url);

$url = htmlentities($url);

$url = str_replace('&amp;', '&#038;', $url);
$url = str_replace("'", '&#039;', $url);

if ($url[0] !== '/') {
// We're only interested in relative links from $_SERVER['PHP_SELF']
return '';
} else {
return $url;
}
}

我找不到这两个代码中哪里会抛出错误。

最佳答案

你说该函数存在于文件中

/var/www/html/register.php

但你包括

include_once 'includes/register.inc.php';

这不是正确的文件名。如果您使用了 require_once,您就会自己发现该错误。将 include 更改为 require 并获取错误消息。

require_once 'includes/register.inc.php';
require_once 'includes/functions.php';

编辑

似乎我过度阅读了错误消息,并且 register.php 不是应该包含的文件。但这个答案仍然会站在这里并且不会被删除,因为错误仍然是由于同一问题造成的。

如果您遇到函数未定义的消息,那么它只是未定义。这仅意味着它既不存在于当前文件中,也不存在于任何包含的文件中。当然,这不是 PHP 核心函数。

关于javascript - PHP fatal error : Call to undefined function esc_url(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23545170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com