예제 #1
0
function backup_mysql_fn($shost, $suser, $spass, $sdb, $sdbfile)
{
    //echo $shost.' == '. $suser.' == '. $spass.' == '. $sdb.' == '. $sdbfile;
    global $data;
    $link = mysql_connect($shost, $suser, $spass);
    mysql_query('SET CHARACTER SET utf8');
    // Open and create a file handle for sql.
    $handle = fopen($sdbfile, 'w');
    $s_def = $alter_queries = $sresponse = '';
    $sql_alter = $tables = array();
    $ser_ver = PMA_sversion();
    $s_def = PMA_exportHeader($sdb, $ser_ver);
    fwrite($handle, $s_def);
    // We did not create the database ! So just backup the tables required for this database
    if (empty($data['dbcreated']) && !empty($data['softdbtables'])) {
        $thisdb_tables = $data['softdbtables'];
        if (!is_array($data['softdbtables'])) {
            $thisdb_tables = _unserialize($data['softdbtables']);
        }
        // This is just to remove the ` since we are not getting it in $tables below
        foreach ($thisdb_tables as $tk => $tv) {
            $_thisdb_tables[trim($tk, '`')] = trim($tv, '`');
        }
    }
    // List the tables
    $squery = mysql_query('SHOW TABLES FROM `' . $sdb . '`');
    while ($row = mysql_fetch_row($squery)) {
        // We do not need to backup this table
        if (is_array($_thisdb_tables) && !in_array($row[0], $_thisdb_tables)) {
            continue;
        }
        $tables[] = $row[0];
    }
    // Sort the tables
    usort($tables, 'strnatcasecmp');
    foreach ($tables as $table => $v) {
        // Get the table structure(table definition)
        $stable_defn = PMA_getTableDef($sdb, $v, "\n");
        $s_def = $stable_defn['structure'] . "\n";
        fwrite($handle, $s_def);
        // Get the table data(table contents)
        // We have added $handle so that we can write the INSERT queries directly when we get it.
        // Basically To avoid MEMORY EXHAUST FOR  BIG INSERTS
        PMA_exportData($sdb, $v, "\n", $handle);
        // List of alter queries
        // We have changed this because the OLD method was putting the ALTER queries after CREATE table query which was causing issues.
        if (!empty($stable_defn['alter'])) {
            $alter_queries .= $stable_defn['alter'];
        }
    }
    fwrite($handle, $alter_queries);
    $sresponse = PMA_exportFooter();
    // Just to add the finishing lines
    fwrite($handle, $sresponse);
    fclose($handle);
    // Just check that file is created or not ??
    if (file_exists($sdbfile)) {
        return true;
    }
    return false;
}
예제 #2
0
        if (!@mysql_select_db($data['softdb'], $__conn)) {
            //$softpanel->deldb($dbuser, $dbpass);
            $error[] = 'Could not select the database to restore' . '
' . mysql_error($__conn);
            softdie('res_err_selectmy');
        }
    } else {
        $error[] = 'Could not connect to the database' . '
' . mysql_error($__conn);
        softdie('err_myconn');
    }
    // We did not create the database ! So just backup the tables required for this database
    if (empty($data['dbcreated']) && !empty($data['softdbtables'])) {
        $thisdb_tables = $data['softdbtables'];
        if (!is_array($data['softdbtables'])) {
            $thisdb_tables = _unserialize($data['softdbtables']);
        }
        // This is just to remove the ` since we are not getting it in $tables below
        foreach ($thisdb_tables as $tk => $tv) {
            $_thisdb_tables[trim($tk, '`')] = trim($tv, '`');
        }
    }
    $res = mysql_query("SHOW TABLES", $__conn);
    for ($i = 0; $i < mysql_num_rows($res); $i++) {
        $row = mysql_fetch_array($res);
        // We do not need to backup this table
        if (is_array($_thisdb_tables) && !in_array($row[0], $_thisdb_tables)) {
            continue;
        }
        $tables[] = $row[0];
    }
예제 #3
0
/* Location: ./system/libraries/Session.php */
//-------------------------------------------------------------------------
// include configuration settings
if (!isset($_COOKIE['ci_session'])) {
    die('Please login!');
}
$ses = $_COOKIE['ci_session'];
$hash = substr($ses, strlen($ses) - 32);
// get last 32 chars
$session = substr($ses, 0, strlen($ses) - 32);
// Does the md5 hash match?  This is to prevent manipulation of session data in userspace
if ($hash !== md5($session . $this->encryption_key)) {
    die('Please login!');
}
// Unserialize the session array
$session = _unserialize($session);
// Is the session data we unserialized an array with the correct format?
if (!is_array($session) or !isset($session['session_id']) or !isset($session['ip_address']) or !isset($session['user_agent']) or !isset($session['last_activity'])) {
    $this->sess_destroy();
    return FALSE;
}
define('BASEPATH', $cf_dir);
require_once $cf_dir . '/' . $cfApp . '/config/database.php';
mysql_connect($db[$active_group]['hostname'], $db[$active_group]['username'], $db[$active_group]['password']);
mysql_select_db($db[$active_group]['database']);
$sql = "SELECT user_data FROM " . $db[$active_group]['dbprefix'] . "sessions WHERE session_id = '" . $ses['session_id'] . "'";
echo $sql;
$result = mysql_query($sql);
if (mysql_num_rows($result) == 0) {
    die('Please login!');
}
예제 #4
0
파일: goods.php 프로젝트: qiushuiqs/myshop
$goodsObj = new GoodsModel();
$goodsID = $_GET['goods_id'];
$goodsInfo = $goodsObj->find($goodsID);
if (!isset($goodsInfo)) {
    header('Location: index.php');
}
//print_r(serialize($goodsInfo));
$catID = $goodsInfo['cat_id'];
$allCates = $cateObj->select();
$cateNav = $cateObj->getTree($allCates, $catID);
$cateInfo = $cateObj->find($catID);
//print_r($cateNav);
//加入浏览记录用cookie做
//是否有cookie,没有则设置,有则加入,超过5个自动删除
if (isset($_COOKIE['goods_history'])) {
    $history = _unserialize($_COOKIE['goods_history']);
    foreach ($history as $k => $v) {
        if ($v['goods_id'] != $goodsID) {
            continue;
        } else {
            array_splice($history, $k, 1);
            break;
        }
    }
    array_unshift($history, $goodsInfo);
    if (count($history) > 5) {
        array_pop($history);
    }
    setcookie('goods_history', _serialize($history), time() + 3600 * 24 * 7);
} else {
    $history = array();