-1

Fatal error: Cannot redeclare getIp() (previously declared in C:\xampp\htdocs\ecommerce\functions\functions.php:12) in C:\xampp\htdocs\ecommerce\functions\functions.php on line 21

This is the error I received when creating a checkout page

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;
}

this is the function it refers to

<?php 
  if(!isset($_SESSION['customer_email'])) {

    include("customer_login.php");

  }else{

    include("payment.php");
  }
?>

and it happens after this is not set function

Santiago Hernández
  • 5,438
  • 2
  • 26
  • 34
Ms. Code
  • 27
  • 1
  • 1
  • 5

1 Answers1

7

probably you have included the file before, use include_once

<?php 
  if(!isset($_SESSION['customer_email'])) {

    include_once("customer_login.php");

  }else{

    include_once("payment.php");
  }
?>

or you can check if function exists with function_exists:

if(!function_exists("getIp")) {
   // declare your function
} else {
   // it already exists, do something else
}
Santiago Hernández
  • 5,438
  • 2
  • 26
  • 34