2010-05-29 29 views
1

我得到这个错误在为什么PHP错误:调用一个成员函数set_prefix()非对象

Fatal error: Call to a member function set_prefix() on a non-object in /home/reboltutorial/reboltutorial.com/wp-settings.php on line 254

线254包含:

$prefix = $wpdb->set_prefix($table_prefix); // set up global tables 

这如果我尝试调用index_wordpress发生()而不是调用这两条线

define('WP_USE_THEMES', true); 
    require('./wp-blog-header.php'); 

所以这不起作用:

<?php 

    function index_wordpress() { 
     define('WP_USE_THEMES', true); 
     require('./wp-blog-header.php'); 
    } 
?>  

<?php 

    if(!function_exists('apache_request_headers')) { 
     function apache_request_headers() { 
      $headers = array(); 
      foreach($_SERVER as $key => $value) { 
       if(substr($key, 0, 5) == 'HTTP_') { 
        $headers[str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))))] = $value; 
       } 
      } 
      return $headers; 
     } 
    } 

    function getCurrentPageUrl() { 
    $pageURL = 'http'; 
    if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} 
    $pageURL .= "://"; 
    if ($_SERVER["SERVER_PORT"] != "80") { 
     $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; 
    } else { 
     $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; 
    } 
    return $pageURL; 
    }  

    $a = apache_request_headers(); 

    $pos = strrpos($a["User-Agent"], "REBOL"); 
    if ($pos === false) { 
     index_wordpress(); 
    } else { 

     if ($_SERVER['REMOTE_ADDR'] != "69.163.203.14") { 
     $command= './cgi-bin/index.cgi '. '"' . getCurrentPageUrl() . '"'; 
     echo system($command); 
     } else { 
     index_wordpress(); 
     } 
    } 
?> 

,而这个工程:

<?php 

    if(!function_exists('apache_request_headers')) { 
     function apache_request_headers() { 
      $headers = array(); 
      foreach($_SERVER as $key => $value) { 
       if(substr($key, 0, 5) == 'HTTP_') { 
        $headers[str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))))] = $value; 
       } 
      } 
      return $headers; 
     } 
    } 

    function getCurrentPageUrl() { 
    $pageURL = 'http'; 
    if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} 
    $pageURL .= "://"; 
    if ($_SERVER["SERVER_PORT"] != "80") { 
     $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; 
    } else { 
     $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; 
    } 
    return $pageURL; 
    }  

    $a = apache_request_headers(); 

    $pos = strrpos($a["User-Agent"], "REBOL"); 
    if ($pos === false) { 
     define('WP_USE_THEMES', true); 
     require('./wp-blog-header.php'); 
    } else { 

     if ($_SERVER['REMOTE_ADDR'] != "69.163.203.14") { 
     $command= './cgi-bin/index.cgi '. '"' . getCurrentPageUrl() . '"'; 
     echo system($command); 
     } else { 
     define('WP_USE_THEMES', true); 
     require('./wp-blog-header.php'); 
     } 
    } 
?> 

回答

2

您已经移动了包括初始化的WordPress到一个函数,从而限制了初始化过程创建该函数的范围内的所有变量,失去他们的函数结束时。

虽然这应该立即解决的问题:

function index_wordpress() { 
     global $wpdb; // Changes scope  
     define('WP_USE_THEMES', true); 
     require('./wp-blog-header.php'); 
    } 

它可能是更好的离开require在主脚本。

+0

谢谢,这是最后的逻辑。 – 2010-05-29 20:46:18

相关问题