【发布时间】:2016-01-20 16:24:51
【问题描述】:
我正在创建我的登录页面,当我加载它时,我似乎收到以下错误消息:
致命错误:无法在第 4 行的 /home/a4625512/public_html/core/functions/general.php 中重新声明 email()(之前在 /home/a4625512/public_html/core/functions/general.php:2 中声明)
我的主机是 000WebHost 所以不知道跟他们有没有关系, 我已经在网上到处搜索了。
general.php 代码:
function email($to, $subject, $body) {
mail($to, $subject, $body, 'From: hello@points4u.com');
}
登录代码:
include 'core/init.php';
if(empty($_POST) === false){
$username = $_POST['username'];
$password = $_POST['password'];
if(empty($username) === true || empty($password) === true){
$errors[] = 'You need to enter a username and password.';
}else if(user_exists($username) === false){
$errors[] = 'We cant find that username. Have you registered?';
}else if(user_active($username) === false){
$errors[] = 'You have not activated your account!';
}else{
$login = login($username, $password);
if($login === false){
$errors[] = 'That username/password is incorrect.';
}else{
$_SESSION['user_id'] = $login;
header('location: index.php');
exit();
}
}
print_r($errors);
}
【问题讨论】:
-
错误信息说明了一切。您不能重新声明...
-
我不知道如何解决这个问题
-
有几个解决方案;您可以更改函数的名称,或使用命名空间来停止冲突,或者由于未保留“电子邮件”,因此您应该能够使用它,您可以查找函数
email()先前声明的位置(提示:core/functions/general.php:2) 并在不使用时将其删除
标签: php html sql declare redeclare