致命错误:无法在第21行的C:\ xampp \ htdocs \ ecommerce \ functions \ functions.php中重新声明getIp()(先前在C:\ xampp \ htdocs \ ecommerce \ functions \ functions.php:12中声明)
这是我在创建结帐页面时收到的错误
function getIp() {
$ip = $_SERVER['REMOTE_ADDR'];
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
return $ip;
}
这是它引用的功能
<?php
if(!isset($_SESSION['customer_email'])) {
include("customer_login.php");
}else{
include("payment.php");
}
?>
并且在没有设置功能
之后发生答案 0 :(得分:4)
可能您之前已包含该文件,请使用include_once
<?php
if(!isset($_SESSION['customer_email'])) {
include_once("customer_login.php");
}else{
include_once("payment.php");
}
?>
或者您可以检查function_exists是否存在函数:
if(!function_exists("getIp")) {
// declare your function
} else {
// it already exists, do something else
}