TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-06-2010, 10:44 AM   #1 (permalink)
The Wanderer
 
oshash's Avatar
 
Join Date: Jan 2010
Posts: 6
Thanks: 1
oshash is on a distinguished road
Asterix fatal error

Hi,


Can any one tell me why i get this error::
Fatal error: Cannot redeclare date_diff() in C:\wamp\www\kamsar012010_local\includes\functions. php on line 26
And my function.php is

PHP Code:
<?php
// PHP USEFUL FUNCTIONS:-


function date_diff($date1$date2) {
  
//$date1  today, or any other day
  //$date2  date to check against

    
$d1 explode("-"$date1);
    
$y1 $d1[0];
    
$m1 $d1[1];
    
$d1 $d1[2];

    
$d2 explode("-"$date2);
    
$y2 $d2[0];
    
$m2 $d2[1];
    
$d2 $d2[2];

    
$date1_set mktime(0,0,0$m1$d1$y1);
    
$date2_set mktime(0,0,0$m2$d2$y2);

    return(
round(($date2_set-$date1_set)/(60*60*24)));
}
//*********LINE 26******Showing error here





function get_ip_address() {
    if (isset(
$_SERVER)) {
      if (isset(
$_SERVER['HTTP_X_FORWARDED_FOR'])) {
        
$ip $_SERVER['HTTP_X_FORWARDED_FOR'];
      } elseif (isset(
$_SERVER['HTTP_CLIENT_IP'])) {
        
$ip $_SERVER['HTTP_CLIENT_IP'];
      } else {
        
$ip $_SERVER['REMOTE_ADDR'];
      }
    } else {
      if (
getenv('HTTP_X_FORWARDED_FOR')) {
        
$ip getenv('HTTP_X_FORWARDED_FOR');
      } elseif (
getenv('HTTP_CLIENT_IP')) {
        
$ip getenv('HTTP_CLIENT_IP');
      } else {
        
$ip getenv('REMOTE_ADDR');
      }
    }

 return 
$ip;
 }




function 
is_leap_year($year) {
    if (
$year 100 == 0) {
      if (
$year 400 == 0) return true;
    } else {
      if ((
$year 4) == 0) return true;
    }

    return 
false;
  }



function 
check_email_address($email) {

  if (!
ereg("[^@]{1,64}@[^@]{1,255}"$email)) {

    return 
false;
  }

  
$email_array explode("@"$email);
  
$local_array explode("."$email_array[0]);
  for (
$i 0$i sizeof($local_array); $i++) {
     if (!
ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~.-]{0,63})|('[^(\|)]{0,62}'))$"$local_array[$i])) {
      return 
false;
    }
  }  
  if (!
ereg("^[?[0-9.]+]?$"$email_array[1])) { 
    
$domain_array explode("."$email_array[1]);
    if (
sizeof($domain_array) < 2) {
        return 
false
    }
    for (
$i 0$i sizeof($domain_array); $i++) {
      if (!
ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$"$domain_array[$i])) {
        return 
false;
      }
    }
  }
  return 
true;
}



// $start - From which year to start
// $years - number of years from the start year
function drop_down_years($start$years$direction) {
    if(
$direction==1) {
        
$end $start $years-1;
        for(
$i=$start;$i<=$end;$i++) {
            
$values[] = $i;
        }    
    }
    else {
    
$end $start $years;
    for(
$i=$end;$i<=$start;$i++) {
            
$values[] = $i;
        }    
        
$values array_reverse($values);
    }
    return (
$values);
}






function 
GetAge($Birthdate)

{
       
// Explode the date into meaningful variables
        
list($BirthYear,$BirthMonth,$BirthDay) = explode("-"$Birthdate);
        
// Find the differences
        
$YearDiff date("Y") - $BirthYear;
        
$MonthDiff date("m") - $BirthMonth;
        
$DayDiff date("d") - $BirthDay;
        
// If the birthday has not occured this year
        
if ($DayDiff || $MonthDiff 0)
          
$YearDiff--;
       return 
$YearDiff;
}

?>
oshash is offline  
Reply With Quote
Old 01-06-2010, 11:23 AM   #2 (permalink)
The Wanderer
Newcomer 
 
etoolbox's Avatar
 
Join Date: Dec 2008
Location: Auckland, NZ
Posts: 24
Thanks: 0
etoolbox is on a distinguished road
Default

You are getting that message because there's already a function called date_diff which has been declared. If you get this message, it means that

1) you have included code more than once which contains the same function,
2) have written code in more than one place which has the same function name, or
3) are trying to create a function which has the same name as a PHP function

In this instance it's #3:
http://nz.php.net/date_diff
__________________
Chris Hope's LAMP Blog: http://www.electrictoolbox.com/
etoolbox is offline  
Reply With Quote
Old 01-06-2010, 11:51 AM   #3 (permalink)
The Wanderer
 
oshash's Avatar
 
Join Date: Jan 2010
Posts: 6
Thanks: 1
oshash is on a distinguished road
Default

hmm... I have used the same include directory in admin folder also .
is that the problem???
oshash is offline  
Reply With Quote
Old 01-06-2010, 11:55 AM   #4 (permalink)
The Wanderer
Newcomer 
 
etoolbox's Avatar
 
Join Date: Dec 2008
Location: Auckland, NZ
Posts: 24
Thanks: 0
etoolbox is on a distinguished road
Default

No, the problem is the function has already been declared because it's a built-in PHP function. Either use the PHP function and remove your function with the same name, or name your one something different.
__________________
Chris Hope's LAMP Blog: http://www.electrictoolbox.com/
etoolbox is offline  
Reply With Quote
Old 01-06-2010, 12:03 PM   #5 (permalink)
The Wanderer
 
oshash's Avatar
 
Join Date: Jan 2010
Posts: 6
Thanks: 1
oshash is on a distinguished road
Default

how should i do that ??
am a beginner in php:(
oshash is offline  
Reply With Quote
Old 01-06-2010, 12:04 PM   #6 (permalink)
The Wanderer
Newcomer 
 
etoolbox's Avatar
 
Join Date: Dec 2008
Location: Auckland, NZ
Posts: 24
Thanks: 0
etoolbox is on a distinguished road
Default

Change
function date_diff($date1, $date2) {
to
function date_diff_some_other_name_that_doesnt_clash_with_t he_built_in_function_of_the_same_name($date1, $date2) {
__________________
Chris Hope's LAMP Blog: http://www.electrictoolbox.com/
etoolbox is offline  
Reply With Quote
The Following User Says Thank You to etoolbox For This Useful Post:
oshash (01-06-2010)
Old 01-06-2010, 12:11 PM   #7 (permalink)
The Wanderer
 
oshash's Avatar
 
Join Date: Jan 2010
Posts: 6
Thanks: 1
oshash is on a distinguished road
Default

Thanks Dude the error has gone..:)
oshash is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Fatal error: Cannot redeclare... captainmerton Absolute Beginners 19 07-01-2009 04:25 PM
Can't solve browser error Peuplarchie Absolute Beginners 1 06-09-2008 05:48 AM
Fatal error: [] operator not supported for strings in /.... pipesportugal General 2 06-05-2008 09:00 PM
an error makes me crazy nuts !!!!!!! webtuto Absolute Beginners 1 02-27-2008 10:31 AM
Fatal Error: Cannot redeclare partial_str() obolus Absolute Beginners 3 12-15-2007 06:58 PM


All times are GMT. The time now is 01:32 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design