Greetings,
I have a php web app I 'inherited' and am working on tweaking/cleaning. Below is from a common function script, called common.php. The only include or require is shown below.

The scenario:

When I execute a script to generate some graphics, I receive the following error:
PHP Fatal error: Cannot redeclare get_client_ip() (previously declared in /home/dshield/php/common.php:14) in /home/dshield/php/common.php on line 13

The common.php file is included in a required file, db_report.php, from the graphics gen script.

I have grepped and searched through all included/required files, and can find no signs of a problem. The inclusion of common.php in db_report.php is not in a loop structure. It seems to be localized to the common.php module. If I run any other script that either directly or indirectly calls common.php, I receive an error.

The entire function is included.

Thanks for any help,
monger

Sys Info - Fedora Core 2
apache 2.-.51.-2.9
php 4.3.10-2.4

      1 <?php
      2 
      3 #
      4 # set global variables if not already done so by .htaccess
      5 #
      6 
      7 require_once ("evn_var.php");
      8 
      9 #
     10 # we will go out of our way to find the 'real' IP where a client comes from.
     11 #
     12 
     13 function get_client_ip(){
     14   if (isset($REMOTE_ADDR)) {
     15         $ip=$REMOTE_ADDR;
     16   #global $HTTP_SERVER_VARS;
     17   #if ( isset($HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR']) ) {
     18    # $ip=$HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'];
     19     if ( ! is_ip($ip) ) {
     20         unset ($ip);
     21     }
     22   }
     23   if ( ! isset($ip) ) {
     24     $ip=$_SERVER['REMOTE_ADDR'];
     25   }
     26 #  if ( ! isset($ip) ) {
     27 #    $ip=$HTTP_SERVER_VARS['REMOTE_ADDR'];
     28 #  }
     29 
     30 //do some logging to see if we did it right.
     31 error_log("via: ".$HTTP_SERVER_VARS['HTTP_VIA']."\t forw: ".$HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR']."\t client: ".$HTTP_SERVER_VARS['HTTP_CLIENT_IP']."\t rem.ad: ".$HTTP_SERVER_VARS['REMOTE_ADDR']."\tused: $ip\n",3,'/tmp/client_log');
     32  return $ip;
     33 }

    so you aren't including common.php from any other scripts? if so are you using require_once or include?

      Looks like it's mostly just

       require 

      . Is require_once better?

      Originally posted by tekky
      so you aren't including common.php from any other scripts? if so are you using require_once or include?

        tekky- looks like require_once did it.

        Thanks

        monger

          Write a Reply...