我有一个非插件脚本,它有自己的数据库,我想与Wordpress一起使用。如何在wordpress页面中添加连接到此单独数据库的自定义php代码?它需要放在上面每一页的顶部<html>
我正在使用Genesis框架。
非常感谢您的帮助
这是我的函数中的自定义函数。php文件
/** Activate IP Timer Countdown */
add_action( \'init\', \'your_script_function\' );
function your_script_function() {
$notimeleft_str = "There is no time left";
$hours = 48;
$minutes = 0;
$days = 0;
$months = 0;
$db_host = "localhost";
$db_user = "xxxxx";
$db_pass = "xxxxx";
$db_dbname = "xxxxx";
$str = "+" . $months . \' months +\' . $days . \' days +\' . $hours . \' hours +\' . $minutes . \' minutes\';
// DO NOT EDIT BELOW THIS LINE!
date_default_timezone_set(\'UTC\');
include_once("mysql.class.php");
$db = new MySQL(true, $db_dbname, $db_host, $db_user, $db_pass);
$db->ThrowExceptions = true;
$script_name = $_SERVER["PHP_SELF"];
$cookie_expire = 60*60*24*365*20;
$str_interval = "+" . $months . \' months +\' . $days . \' days +\' . $hours . \' hours +\' . $minutes . \' minutes\';
if($_COOKIE[\'cd_until\']) $cookie = json_decode($_COOKIE[\'cd_until\'], true);
else $cookie = Array();
if(isset($_GET["reset"])) {
//$db->DeleteRows("cd_until", Array("ip" => \'"\' . $_SERVER["REMOTE_ADDR"] . \'"\', "page" => \'"\' . $script_name . \'"\'));
unset($cookie[$script_name]);
header("Location: " . $_SERVER["PHP_SELF"]);
}
else {
$query = "SELECT * FROM cd_until WHERE ip=\'" . $_SERVER["REMOTE_ADDR"] . "\' AND page=\'" . $script_name . "\'";
$value = $db->QuerySingleRow($query);
if($value) {
$thedatetime = new DateTime();
$thedatetime->setTimestamp(intval($value->until));
$cookie[$script_name] = intval($value->until);
} else {
if($cookie[$script_name]) {
$thedatetime = new DateTime();
$thedatetime->setTimestamp( intval( $cookie[$script_name] ) );
} else {
$thedatetime = new DateTime();
$thedatetime->modify( $str_interval );
$cookie[$script_name] = intval( $thedatetime->format("U") );
}
$new_id = $db->InsertRow(
"cd_until",
Array(
"ip" => \'"\' . $_SERVER["REMOTE_ADDR"] . \'"\',
"until" => intval( $thedatetime->format("U") ),
"page" => \'"\' . $script_name . \'"\'
)
);
}
}
setcookie("cd_until", json_encode($cookie), time() + $cookie_expire, "/");
}