chop Posted August 20, 2006 Share Posted August 20, 2006 this is my common.php file which is used for include all the header and declare all the functions need for the site:[code]<?php if (defined('_COMMON_INC') ) return ; define ('_COMMON_INC', 1); ini_set("session.gc_maxlifetime","86400"); ini_set("session.use_trans_sid","Off"); session_start(); ini_set("variables_order", "EGPCS"); ini_set("safe_mode_gid","On"); error_reporting (E_ALL ^ E_NOTICE ); include("include/config.php"); include(_VNESHOP_ROOT_PATH . "/include/antiflood.php"); include(_VNESHOP_ROOT_PATH . "/adodb/adodb.inc.php"); include(_VNESHOP_ROOT_PATH . "/include/time.php"); include(_VNESHOP_ROOT_PATH . "/include/page_list.php"); include(_VNESHOP_ROOT_PATH . "/include/common_action.php"); include(_VNESHOP_ROOT_PATH . "/language/language.php"); $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; $db = &ADONewConnection('mysql'); $db->PConnect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASSWORD, $DATABASE_NAME); init_config(); function tohtml($strValue) { return htmlspecialchars($strValue); } function tourl($strValue) { return urlencode($strValue); } function get_param($param_name) { global $HTTP_POST_VARS; global $HTTP_GET_VARS; $param_value = ""; if(isset($HTTP_POST_VARS[$param_name])) $param_value = $HTTP_POST_VARS[$param_name]; else if(isset($HTTP_GET_VARS[$param_name])) $param_value = $HTTP_GET_VARS[$param_name]; return $param_value; } function get_session($param_name) { if (isset($_SESSION[$param_name])) $param_value = $_SESSION[$param_name]; else $param_value=""; return $param_value; } function set_session($param_name, $param_value) { if (isset($_SESSION[$param_name])) unset($_SESSION[$param_name]); $_SESSION[$param_name] = $param_value; } function is_number($string_value) { if(is_numeric($string_value) || !strlen($string_value)) return true; else return false; } function tosql($value, $type) { if($value == "") return "NULL"; else if($type == "Number") return str_replace (",", ".", doubleval($value)); else { if(get_magic_quotes_gpc() == 0) { $value = str_replace("'","''",$value); $value = str_replace("\\","\\\\",$value); } else { $value = str_replace("\\'","''",$value); $value = str_replace("\\\"","\"",$value); } return "'" . $value . "'"; } } function strip($value) { if(get_magic_quotes_gpc() == 0) return $value; else return stripslashes($value); } function stripc(&$value) { if (!is_array($value)) $value = stripcslashes($value); else array_walk($value, "stripc"); } function Stripc_var() { $resarray = array(); foreach (func_get_args() as $outvar) { stripc($outvar); $resarray[] = $outvar; } if (func_num_args() == 1) { return $resarray[0]; } else { return $resarray; } } function get_current_var($name) { $var = get_session(_PREFIX . $name); return $var; } function get_session_var($name) { $var = get_session(_PREFIX . $name); return $var; } function set_session_var($name, $value) { set_session(_PREFIX . $name, $value); } function get_current_language() { $lang = $_COOKIE[_PREFIX . "lang_id"]; return $lang; } function get_condb() { global $db; return $db; } function get_module_name() { global $module_name; return $module_name; } function get_module_dir() { global $module_dir; if (!strlen($module_dir)) { $module_name = get_module_name(); $module_dir = "modules/" . $module_name; } return $module_dir; } function check_authority($auth_level) { $right = get_current_var("User_Right"); if ($right >= $auth_level) return true; else return false; } function check_security($security_level) { global $User_Right; if(!session_is_registered(_PREFIX . "User_ID")) header ("Location: Login.php?querystring=" . urlencode(getenv("QUERY_STRING")) . "&ret_page=" . urlencode(getenv("REQUEST_URI"))); else if( (!session_is_registered(_PREFIX . "User_Right") )|| ( ($UserRights=get_session(_PREFIX . "User_Right")) < $security_level) ) header ("Location: Login.php?querystring=" . urlencode(getenv("QUERY_STRING")) . "&ret_page=" . urlencode(getenv("REQUEST_URI"))); } function check_permit($member_id, $permit) { if (check_authority(_MOD_LEVEL)) return true; else { $db = get_condb(); $rs = $db->Execute("SELECT * FROM member_permit WHERE member_id='" . $member_id . "' AND permit='" . $permit. "'"); return ($rs->RecordCount())?true : false; } } function init_config() { global $config_tb; $config_tb = get_session("config_tb"); if (!is_array($config_tb)) { $db = get_condb(); $config_tb = array(); $rs = $db->Execute("SELECT name, value FROM config"); while (!$rs->EOF) { $config_tb[$rs->fields["name"]] = $rs->fields["value"]; $rs->MoveNext(); } init_module_config(); set_session("config_tb", $config_tb); } } function init_module_config($module="default") { global $config_tb; if ($config_tb[$module . "_menu"]) { $config_tb["center_menu"] = unserialize($config_tb[$module . "_center_menu"]); $config_tb["left_menu"] = unserialize($config_tb[$module . "_left_menu"]); $config_tb["right_menu"] = unserialize($config_tb[$module . "_right_menu"]); } else { $db = get_condb(); $pos_arr = array("left","right","center"); $rs_func = $db->Execute("SELECT * FROM sys_module_func"); $func_arr = $rs_func->GetAssoc(); foreach ($pos_arr as $key=>$pos) { $sql = "SELECT * FROM menu INNER JOIN sys_module ON menu.module_id=sys_module.module_id WHERE sys_module.module_name='" . $module . "' AND menu.position='" . $pos . "' AND menu.is_active=1 "; $rs = $db->Execute($sql); if ($rs->RecordCount()) { $value = $rs->fields["value"]; if ($value) { $value_arr = explode("|",$value); $arr = array(); for($i=0, $max=count($value_arr); $i < $max; $i++) { $arr[$i]["func_name"] = $value_arr[$i]; $arr[$i]["func_file"] = $func_arr[$value_arr[$i]]["func_file"]; $arr[$i]["is_active"] = $func_arr[$value_arr[$i]]["is_active"]; $arr[$i]["title"] = translate($func_arr[$value_arr[$i]]["title"],$lang); } $arr["size"] = count($value_arr); $config_tb[$module . "_" . $pos . "_menu"] = serialize($arr); unset($arr,$value_arr); } } else { $config_tb[$module . "_" . $pos . "_menu"] = $config_tb["default_" . $pos . "_menu"]; } } $config_tb["center_menu"] = unserialize($config_tb[$module . "_center_menu"]); $config_tb["left_menu"] = unserialize($config_tb[$module . "_left_menu"]); $config_tb["right_menu"] = unserialize($config_tb[$module . "_right_menu"]); $config_tb[$module . "_menu"] = 1; set_session("config_tb", $config_tb); } } function get_config($name) { global $config_tb; return $config_tb[$name]; } function get_theme_name() { global $theme_name; return $theme_name; } function Theme_load($theme) { global $barcolor , $linkcolor , $vlinkcolor, $alinkcolor, $textcolor , $bgcolor , $title_bar_color ; global $bgImage , $big_bar_image ,$bar_image, $top_left_image ; global $screen_width, $left_width, $center_width, $right_width; global $bgcolor1, $bgcolor2; global $index_bar_image1, $index_bar_image2, $index_bar_image3, $index_bar_image4; global $theme_name; global $banner; $include_path = _VNESHOP_ROOT_PATH . "/theme/" . $theme . "/theme.php"; $default_path = _VNESHOP_ROOT_PATH . "/theme/default/theme.php"; $theme_name = $theme; if (!file_exists($include_path)) { echo $include_path; $include_path = $default_path; $theme_name = "default"; } include($include_path); } function fnMail($to, $subject, $message, $headers="", $debug=0) { $headers .= "\n Content-Type: text/html; charset=utf-8"; if ($debug) { echo "Mail To: ".$to."<br>"; echo "Mail Subject: ".$subject."<br>"; echo "Mail Message: ".$message."<br>"; echo "Mail Headers: ".$headers."<br>"; } $return = @mail($to, $subject, $message, $headers); return $return; } function Clean_input() { $ret_array = array(); foreach(func_get_args() as $var) { $outvar = htmlentities($var); array_push($ret_array, $outvar); } if (func_num_args() == 1) { return $ret_array[0]; } else { return $ret_array; } } ?>[/code]This works in my friend machine but not for me :My machine :Ubuntu 6.06.1Apache2 2.0.55php5 5.1.2mysql 5.0.22The error isFatal error: Cannot redeclare tohtml() (previously declared in /home/chop/Web/Website/include/common.php:21) in /home/chop/Web/Website/include/common.php on line 23 Link to comment https://forums.phpfreaks.com/topic/18095-having-problems-with-include-things-and-functions/ Share on other sites More sharing options...
hitman6003 Posted August 20, 2006 Share Posted August 20, 2006 Make sure that you only have the function "tohtml" once in your code. The error means that you are trying to declare, or create, the same function twice. Link to comment https://forums.phpfreaks.com/topic/18095-having-problems-with-include-things-and-functions/#findComment-77540 Share on other sites More sharing options...
chop Posted August 21, 2006 Author Share Posted August 21, 2006 Hi, i already know what the problem is, just dont know how to fix it, actually how to trace it down.I think i did have[code]if (defined('_COMMON_INC') ) return ; define ('_COMMON_INC', 1);[/code]so if the thing is included twice then nothing happends.Thanks for answering. Link to comment https://forums.phpfreaks.com/topic/18095-having-problems-with-include-things-and-functions/#findComment-77802 Share on other sites More sharing options...
ToonMariner Posted August 21, 2006 Share Posted August 21, 2006 I think it is more likely that you have include('common.php'); in more than one place - like it is included in a file which is included in common.php - what ever has happened ther is a second include of this file.One of the reasosn why require_once is what you shoudl really use for a site wide script liek this. Link to comment https://forums.phpfreaks.com/topic/18095-having-problems-with-include-things-and-functions/#findComment-77811 Share on other sites More sharing options...
chop Posted August 21, 2006 Author Share Posted August 21, 2006 got it, thanks guys problem is solvedThanks,this is a great forums :) Link to comment https://forums.phpfreaks.com/topic/18095-having-problems-with-include-things-and-functions/#findComment-77838 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.