Notice: Undefined index: name in กับ Warning: parse_ini_file() แก้ไขยังไงครับ

สำหรับผู้ที่ เริ่มต้น Programming - PHP มีอะไร แนะนำ หรือข้อสงสัยต้องบอร์ด นี้ คนที่มีความรู้ แบ่งปันคนอื่นบ้างนะ ปัญหาการเขียนโปรแกรม แบบ OOP Session Cookies php network

Moderator: mindphp, ผู้ดูแลกระดาน

pungponnat
PHP Newbie
PHP Newbie
โพสต์: 2
ลงทะเบียนเมื่อ: 08/02/2009 4:43 pm

Notice: Undefined index: name in กับ Warning: parse_ini_file() แก้ไขยังไงครับ

โพสต์ที่ยังไม่ได้อ่าน โดย pungponnat »

รูปภาพ

Notice: Undefined index: name in 37

โค้ด: เลือกทั้งหมด

$configFile = $dir . DIRECTORY_SEPARATOR . $file . DIRECTORY_SEPARATOR . 'config.ini';
			if (file_exists($configFile)) {
				$config = parse_ini_file($configFile);
				$pluginName = isset($config['name']) ? $config['name'] : '';
				if (SJB_Users_CookiePreferences::isPluginDisabled($pluginName)) {
					continue;
				}
กับ Warning: parse_ini_file() in 47

โค้ด: เลือกทั้งหมด

// add to plugins list
				self::$pluginsList[$config['name']] = $config;
				
				if ( $active && !empty($initFile) ) {
				
ขอความกรุณาถ้าไม่ลำบากจนเกินไป รบกวนแก้ไขให้หน่อยครับ ขอบพระคุณครับ :-D

code เต็ม

โค้ด: เลือกทั้งหมด

<?php

/**
 * Plugin Manager class
 *
 *
 * @copyright  2015 Job2Day
 * @version    1
 * @author     Webmaster
 */
class SJB_PluginManager
{
	static $pluginsLoaded = array();
	
	static $pluginsList = array();
	
	
	/**
	 * load all active plugins
	 *
	 * @param string $dir
	 */
  	public static function loadPlugins($dir)
  	{
  		$dh = opendir($dir);
  		if ($dh === false)
  			return;
  			
  		$excludeDirs = array('.', '..');
  			
		while (($file = readdir($dh)) !== false) {
			if (in_array($file, $excludeDirs))
				continue;
				
			$configFile = $dir . DIRECTORY_SEPARATOR . $file . DIRECTORY_SEPARATOR . 'config.ini';
			if (file_exists($configFile)) {
				$config = parse_ini_file($configFile);
				$pluginName = isset($config['name']) ? $config['name'] : '';
				if (SJB_Users_CookiePreferences::isPluginDisabled($pluginName)) {
					continue;
				}
				$active		= isset($config['active']) && ($config['active'] == '1');
				$initFile	= isset($config['init_file']) ? $config['init_file'] : '';
				$config['config_file'] = $configFile;
				$config['group_id'] = isset($config['group'])?str_replace(' ', '_', $config['group']):'';
				// add to plugins list
				self::$pluginsList[$config['name']] = $config;
				
				if ( $active && !empty($initFile) ) {
					$initFilePath = $dir . DIRECTORY_SEPARATOR . $file . DIRECTORY_SEPARATOR . $initFile;
					if (file_exists($initFilePath)) {
						require_once($initFilePath);
						self::$pluginsLoaded[] = $config;
					} else {
						SJB_System::$pluginsErrors[] = "'{$pluginName}' plugin '{$initFilePath}' init file not exists or not readable!";
					}
				}
			}
		}
		closedir($dh);
  	}
  	
  	/**
  	 * reload all plugins
  	 *
  	 */
  	public static function reloadPlugins()
  	{
  		self::$pluginsList = array();
  		self::$pluginsLoaded = array();
  		self::loadPlugins(SJB_System::getSystemSettings('PLUGINS_DIR'));
  	}
  	/**
  	 * get list of all plugins
  	 *
  	 * @return array
  	 */
  	public static function getAllPluginsList()
  	{
  		return self::$pluginsList;
  	}
  	
  	public static function getPluginByName($name)
  	{
  		foreach (self::$pluginsList as $plugin) {
  			if ($plugin['name'] == $name) 
  				return $plugin;
  		}
  		return false;
  	}
  	
  	/**
  	 * get config from ini file
  	 *
  	 * @param string $path
  	 * @return array
  	 */
	public static function getPluginConfigFromIniFile($path)
  	{
  		return parse_ini_file($path);
  	}
  	
  	/**
  	 * save config into ini file
  	 *
  	 * @param string $path
  	 * @param array $config
  	 * @return boolean
  	 */
  	public static function savePluginConfigIntoIniFile($path, $config)
  	{
  		$str = '';
  		foreach ($config as $key => $val)
  			$str .= $key . " = \"" . $val ."\"\n";

  		$result = @file_put_contents($path, $str);
  		return $result !== false;
  	}

	/**
	 * @param string $pluginName
	 * @return bool
	 */
	public static function isPluginActive($pluginName)
	{
		$plugin = SJB_PluginManager::getPluginByName($pluginName);
		return ($plugin && $plugin['active'] == '1');
	}

}
ขอบคุณครับ :icon_plusone:
ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41251
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

Re: Notice: Undefined index: name in กับ Warning: parse_ini_file() แก้ไขยังไงครับ

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

มันเจ้งว่าฟังก์ชั่น parse_ini_file() ใช้งานไม่ได้ถูกปิดอยู่ด้วยเหตุผลเรื่องความปลอดภัย
ทางแก้ ลองเข้าไปดูใน ไฟล์ php.ini ว่าถูกปิดไว้หรือเปล่า หรือ ลอง เขียนฟังก์ชั่นใหม่ ที่ทำงานเหมือน ฟังก์ชั่นนั้นใช้งานเอง
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
rangsun6342

Re: Notice: Undefined index: name in กับ Warning: parse_ini_file() แก้ไขยังไงครับ

โพสต์ที่ยังไม่ได้อ่าน โดย rangsun6342 »

mindphp เขียน:มันเจ้งว่าฟังก์ชั่น parse_ini_file() ใช้งานไม่ได้ถูกปิดอยู่ด้วยเหตุผลเรื่องความปลอดภัย
ทางแก้ ลองเข้าไปดูใน ไฟล์ php.ini ว่าถูกปิดไว้หรือเปล่า หรือ ลอง เขียนฟังก์ชั่นใหม่ ที่ทำงานเหมือน ฟังก์ชั่นนั้นใช้งานเอง
code ในไฟล์ php.ini ครับ

โค้ด: เลือกทั้งหมด

safe_mode = off
display_errors = off
memory_limit = 64M
disable_functions =
safe mode กับ display เราต้องเปลี่ยนเป็น on ใช้เปล่าครับ
บุคคลทั่วไป

Re: Notice: Undefined index: name in กับ Warning: parse_ini_file() แก้ไขยังไงครับ

โพสต์ที่ยังไม่ได้อ่าน โดย บุคคลทั่วไป »

เจอปัญหาเหมือนกัน
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 133