In my PHP codes, I always have this problem that I can not use include somewhere!
For e.g. I’m using MySQL to connect to my database and I made a global.php to include & connect to my database and use it for all other PHP files.
But somewhere I keep getting the error:
Fatal error: Cannot redeclare connect() (previously declared in C:\xampp\htdocs\mypm\functions\global.php:4) in C:\xampp\htdocs\mypm\functions\global.php on line 7
I can not include or use some files that uses global.php in other PHP files!
Any suggestions? Thanks
Here is the code
require ('users.php'); function get_gravatar($id) { $email = get_email($id); $s = 80; $d = 'mm'; $r = 'g'; $img = false; $atts = array();
$url = 'http://www.gravatar.com/avatar/'; $url .= md5( strtolower( trim($email) ) );
$url .= "?s=$s&d=$d&r=$r";
if ( $img ) {
$url = '<img src="' . $url . '"'; foreach ( $atts as $key => $val ) $url .= ' ' . $key . '="' . $val . '"'; $url .= ' />'; } return $url;
}
PHP has alternate versions of
include()andrequire()which address this problem. Useinclude_once()orrequire_once()for files which might be included from multiple files to prevent the common file from being included in your code multiple times.