我无法在代码中识别问题。我正在使用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致命错误:在/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('&', '&', $url);
$url = str_replace("'", ''', $url);
if ($url[0] !== '/') {
// We're only interested in relative links from $_SERVER['PHP_SELF']
return '';
} else {
return $url;
}
}
我无法找到这两个代码中会出现错误的位置。
答案 0 :(得分:1)
你说该功能存在于文件
中/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核心功能。