if (strlen($id_old) < 1 || !isset($ccount_database[$id_old])) {
    $_SESSION['PJ_MESSAGES']['ERROR'] = 'Invalid link ID';
    header('Location: admin.php');
    exit;
}
$id_new = $id_old;
// Add a new link?
if (pj_POST('action') == 'save' && pj_token_check()) {
    // Check demo mode
    pj_demo('edit_link.php?id=' . $id_old);
    // Link URL
    $ccount_database[$id_old]['L'] = pj_validateURL(pj_POST('url')) or $error_buffer['url'] = 'Enter a valid URL address.';
    // Link title
    $ccount_database[$id_old]['T'] = stripslashes(pj_input(pj_POST('title'))) or $title = '';
    // Link ID
    $id_new = pj_input(pj_POST('newid'));
    // Check ID syntax
    if (preg_match('/[^0-9a-zA-Z_\\-\\.]/', $id_new)) {
        $error_buffer['id'] = 'Invalid link ID. Leave it empty or use only these chars: a-z A-Z 0-9 _ - .';
    } elseif (strlen($id_new) > 0 && $id_new != $id_old) {
        // A duplicate ID?
        if (isset($ccount_database[$id_new])) {
            $error_buffer['id'] = 'Link with this ID already exists! Each link requires a unique ID (leave empty to use current one).';
        } else {
            $warn_new_link = true;
        }
    }
    // Total clicks
    $ccount_database[$id_old]['C'] = intval(pj_POST('total', 0));
    // Unique clicks
    $ccount_database[$id_old]['U'] = intval(pj_POST('unique', 0));
function pj_REQUEST($in, $default = false)
{
    return isset($_GET[$in]) ? pj_input(pj_GET($in)) : (isset($_POST[$in]) ? pj_input(pj_POST($in)) : $default);
}
// Pre-set values
$url = '';
$title = '';
$id = '';
$count = 0;
$error_buffer = array();
// Add a new link?
if (pj_POST('action') == 'add' && pj_token_check()) {
    // Check demo mode
    pj_demo('new_link.php');
    // Link URL
    $url = pj_validateURL(pj_POST('url')) or $error_buffer['url'] = 'Enter a valid URL address.';
    // Link title
    $title = stripslashes(pj_input(pj_POST('title'))) or $title = '';
    // Link ID
    $id = pj_input(pj_POST('id')) or $id = '';
    // Check ID
    if (preg_match('/[^0-9a-zA-Z_\\-\\.]/', $id)) {
        $error_buffer['id'] = 'Invalid link ID. Leave it empty or use only these chars: a-z A-Z 0-9 _ - .';
    }
    // Count
    $count = intval(pj_POST('count', 0));
    // If no errors, check for duplicates/generate a new ID
    if (count($error_buffer) == 0) {
        // Get links database
        $data = explode('//', file_get_contents($ccount_settings['db_file']), 2);
        // Convert contents into an array
        $ccount_database = isset($data[1]) ? unserialize($data[1]) : array();
        unset($data);
        // ID exists?
        if (strlen($id)) {
    $ccount_settings['admin_pass'] = pj_input(pj_POST('admin_pass')) or $error_buffer['admin_pass'] = '******';
    // click.php URL
    $ccount_settings['click_url'] = pj_validateURL(pj_POST('click_url')) or $error_buffer['click_url'] = 'Enter a valid URL address of the click.php file on your server.';
    // Database file
    $ccount_settings['db_file'] = pj_input(pj_POST('db_file', 'ccount_database.php'));
    // Check database file
    if (preg_match('/[^0-9a-zA-Z_\\-\\.]/', $ccount_settings['db_file'])) {
        $error_buffer['db_file'] = 'Invalid file name. Use only these chars: a-z A-Z 0-9 _ - .';
    }
    // Unique hours
    $ccount_settings['unique_hours'] = intval(pj_POST('unique_hours', 24));
    if ($ccount_settings['unique_hours'] < 0) {
        $ccount_settings['unique_hours'] = 0;
    }
    // Notation
    $ccount_settings['notation'] = pj_input(pj_POST('notation', 'US'));
    if (!in_array($ccount_settings['notation'], array('US', 'UK', 'FR', 'X1', 'X2'))) {
        $ccount_settings['notation'] = 'US';
    }
    // If no errors, check for duplicates/generate a new ID
    if (count($error_buffer) == 0) {
        // Update settings file
        if (@file_put_contents('../ccount_settings.php', "<?php\nerror_reporting(0);\nif (!defined('IN_SCRIPT')) {die('Invalid attempt!');}\n\n// Password hash for admin area\n\$ccount_settings['admin_pass']='******'admin_pass']}';\n\n// URL of the click.php file\n\$ccount_settings['click_url']='{$ccount_settings['click_url']}';\n\n// Number of hours a visitor is considered as \"unique\"\n\$ccount_settings['unique_hours']={$ccount_settings['unique_hours']};\n\n// Sets the preferred number notation (US, UK, FR, X1, X2)\n\$ccount_settings['notation']='{$ccount_settings['notation']}';\n\n// Name of the log file\n\$ccount_settings['db_file']='{$ccount_settings['db_file']}';\n\n// Version information\n\$ccount_settings['version']='{$ccount_settings['version']}';", LOCK_EX) === false) {
            $_SESSION['PJ_MESSAGES']['ERROR'] = 'Error writing to settings file, please try again later.';
        } else {
            $_SESSION['PJ_MESSAGES']['SUCCESS'] = 'Settings have been saved.';
        }
    }
}
if (count($error_buffer)) {
    $_SESSION['PJ_MESSAGES']['ERROR'] = 'Missing or invalid data, see below for details.';
示例#5
0
// Is this a LOGOUT request?
if (pj_GET('logout', false) !== false && pj_token_check()) {
    // Expire session variable
    $_SESSION['LOGGED_IN'] = false;
    // Delete cookie
    setcookie('ccount_hash', '');
    // Stop session
    pj_session_stop();
    // Define a success message
    $_SESSION['PJ_MESSAGES']['SUCCESS'] = 'You have logged out successfuly.';
} elseif (pj_isLoggedIn()) {
    header('Location: admin.php');
    die;
} elseif ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Check password etc
    if (stripslashes(pj_input(pj_POST('pass', false))) == $ccount_settings['admin_pass']) {
        // Set session variable
        $_SESSION['LOGGED_IN'] = true;
        // Remember user?
        if (pj_POST('remember') == 'yes') {
            setcookie('ccount_hash', pj_Pass2Hash($ccount_settings['admin_pass']), strtotime('+1 year'));
        }
        // Redirect to admin
        header('Location: admin.php');
        die;
    } else {
        $_SESSION['PJ_MESSAGES']['ERROR'] = 'Invalid password.';
    }
} elseif (isset($_GET['notice'])) {
    $_SESSION['PJ_MESSAGES']['INFO'] = 'Session expired, please login again.';
}