Jump to content

Andy_Kemp

Members
  • Posts

    21
  • Joined

  • Last visited

Andy_Kemp's Achievements

Member

Member (2/5)

0

Reputation

1

Community Answers

  1. In Wordpress there is this code <?php $user_info = get_userdata(1); echo 'Username: ' . $user_info->user_login . "\n"; echo 'User roles: ' . implode(', ', $user_info->roles) . "\n"; echo 'User ID: ' . $user_info->ID . "\n"; ?> My question is how they get this? $user_info->user_login My code class Config { private $db; public function __construct($db) { $this->db = $db; } public function get() { $query = 'SELECT * FROM config'; $select = $this->db->query($query); $config = array(); while ($row = $select->fetch(PDO::FETCH_OBJ)) { $config[$row->config] = $row->value; } return $config; } } $config = new Config($db); $conf = $config->get(); print $conf['test']; Now i liked to do same way like wordpress Instead of this $conf['test']; i'd like to get result like this $conf->test;
  2. <?php declare(strict_types = 1); function test(string $username, int $age, float $price) : array { return array('Username' => $username, 'Age' => $age, 'Price' => $price); } $_get = array( 'username' => '', 'age' => '', 'price' => '', ); $_get = array_merge($_get, $_GET); print_r(test($_get['username'], $_get['age'], $_get['price'])); I am new with php7 So when i looked those examples i see test('test_username', 20, 20.01) but int and float are absolutely useless with $_POST, $_GET, Its always error. WITH int - must be of the type integer, string given. WITH float - must be of the type float, string given
  3. Whats the best method to determine who can access to admin panel? <?php if (!defined('Test_script')) { exit('You don\'t have right permission to access this file directly.'); } if (!is_logged_in($ui)) { redirect_to('../index.php?do=login'); } # By user role if (!user_has_role($db, $ui['id'], return_role_id($db, 'user'))) { redirect_to('../index.php?do=home'); } # Or by permission if (!user_has_permission($db, $ui['id'], return_permission_id($db, 'admin_access'))) { redirect_to('../index.php?do=home'); } /* ............................... */ ?>
  4. Added role_id to user table + -- + -------- + --------- + --------------- + ------- + ---------- + ----------- + + ------- + -------- + | id | username | password | email | last_ip | last_login | last_active | ......... | role_id | status | + -- + -------- + --------- + --------------- + ------- + ---------- + ----------- + + ------- + -------- + | 1 | user_1 | long_hash | email@email.com | ::1 | 0123456789 | 0123456789 | ......... | 1 | active | + -- + -------- + --------- + --------------- + ------- + ---------- + ----------- + + ------- + -------- + | 2 | user_2 | long_hash | email@email.com | ::1 | 0123456789 | 0123456789 | ......... | 2 | inactive | + -- + -------- + --------- + --------------- + ------- + ---------- + ----------- + + ------- + -------- + Table name: role + -- + ----------- + ----------- + | id | name | description | + -- + ----------- + ----------- + | 1 | super_admin | Super Admin | + -- + ----------- + ----------- + | 2 | user | User | + -- + ----------- + ----------- + Table name: permission + -- + ----------- + ----------- + | id | name | description | + -- + ----------- + ----------- + | 1 | edit_news | Edit News | + -- + ----------- + ----------- + | 2 | manage_news | Manage News | + -- + ----------- + ----------- + Table name: role_permission + -- + -------- + ------------ + | id | role_id | permission_id | + -- + ------- + ------------- + | 1 | 1 | 1 | + -- + ------- + ------------- + | 2 | 1 | 2 | + -- + ------- + ------------- + Do i need to add login page to user and admin side? I have no idea what to do next.
  5. Admin panel login. Am I doing it right? $query = 'SELECT a.id, a.username, b.password AS admin_password, b.status AS admin_status FROM user AS a INNER JOIN admin AS b ON a.id = b.user_id WHERE a.username = :username'; Table name: user status - active, inactive, un-verified, suspended + -- + -------- + --------- + --------------- + ------- + ---------- + ----------- + + -------- + | id | username | password | email | last_ip | last_login | last_active | ......... | status | + -- + -------- + --------- + --------------- + ------- + ---------- + ----------- + + -------- + | 1 | user_1 | long_hash | email@email.com | ::1 | 0123456789 | 0123456789 | ......... | active | + -- + -------- + --------- + --------------- + ------- + ---------- + ----------- + + -------- + | 2 | user_2 | long_hash | email@email.com | ::1 | 0123456789 | 0123456789 | ......... | inactive | + -- + -------- + --------- + --------------- + ------- + ---------- + ----------- + + -------- + Table name: admin status - enabled, disabled + -- + -------- + --------- + ------- + ---------- + ----------- + -------- + | id | user_id | password | last_ip | last_login | last_active | status | + -- + -------- + --------- + ------- + ---------- + ----------- + -------- + | 1 | 1 | long_hash | ::1 | 0123456789 | 0123456789 | enabled | + -- + -------- + --------- + ------- + ---------- + ----------- + -------- + | 2 | 2 | long_hash | ::1 | 0123456789 | 0123456789 | disabled | + -- + -------- + --------- + ------- + ---------- + ----------- + -------- +
  6. Its fixed now. I dont know why but i need to recreate those files. require ROOT_DIR . 'includes/language_changer/a_panel/index.php'; This index.php require ROOT_DIR . 'includes/template_changer/a_panel/index.php'; This index.php require_once ROOT_DIR . 'languages/a_panel/' . $language . '/main/index.php'; This index.php
  7. And blank line at the top of the page.
  8. Dont know what do do with this issue. Inside php <?php $smarty->display('test.tpl'); ?> Output When i put test.tpl content to test.html and open it to firefox. Then everything is ok.
  9. Where should i set setcookie() to remember what language is selected? includes/configs/a_panel/index.php <?php /* ---------------------------------- */ require ROOT_DIR . 'includes/language_changer/a_panel/index.php'; if (is_file(ROOT_DIR . 'languages/a_panel/'.Language::get_language($db, $config).'/main/index.php') && file_exists(ROOT_DIR . 'languages/a_panel/'.Language::get_language($db, $config).'/main/index.php')) { $language = Language::get_language($db, $config); $charset = Language::get_charset($db, $language); require_once(ROOT_DIR . 'languages/a_panel/'.$language.'/main/index.php'); } else { $language = 'en'; $charset = 'utf-8'; require_once(ROOT_DIR . 'languages/a_panel/'.$language.'/main/index.php'); } /* ---------------------------------- */ $smarty->assign('db', $db); $smarty->assign('config', $config); $smarty->assign('ui', $ui); $smarty->assign('lang', $lang); $smarty->assign('language', $language); $smarty->assign('charset', $charset); ?> includes/language_changer/a_panel/index.php <?php class Language { public static function get_language($db, $config) { if ($config['ap_allow_language_changing'] === 'true') { if (isset($_GET['language']) && self::is_language_supported($db, $config, $_GET['language'])) { return $_GET['language']; } else if (isset($_COOKIE['admin_language']) && self::is_language_supported($db, $config, $_COOKIE['admin_language'])) { return $_COOKIE['admin_language']; } } return $config['ap_default_language']; } private static function is_language_supported($db, $config, $language) { $query = 'SELECT folder_name AS lang_code FROM language WHERE panel = "a_panel" AND version = :version'; $select = $db->prepare($query); $select->bindParam(':version', $config['script_version'], PDO::PARAM_STR); $select->execute(); $supported_languages = array(); while($row = $select->fetch(PDO::FETCH_ASSOC)){ $supported_languages[] = $row['lang_code']; } if (in_array($language, $supported_languages)) { return true; } return false; } public static function get_charset($db, $language) { $query = 'SELECT charset FROM language WHERE panel = "a_panel" AND folder_name = :language'; $select = $db->prepare($query); $select->bindParam(':language', $language, PDO::PARAM_STR); $select->execute(); $row = $select->fetch(PDO::FETCH_ASSOC); return $row['charset']; } } ?>
  10. How to automatically detect user timezone name? Like Europe/Stockholm How to automatically detect user locale? Like sv_SE Or its easier to let user to select their timezone and locale?
  11. I dont know if its right way to do this. If you would do it in a different way pleas let me know. Create unix timestamp with admin selected timezone else use server default timezone. function create_timestamp($config) { $time_zone = ($config['site_time_zone'] === 'default') ? date_default_timezone_get() : $config['site_time_zone']; $date = date_create(NULL, timezone_open($time_zone)); return date_timestamp_get($date); } Format unix timestamp to user selected timezone and date format else use default timezone and date format. function format_timestamp($config, $ui, $timestamp) { $time_zone = (is_logged_in($ui) && $ui['time_zone'] !== 'default') ? $ui['time_zone'] : date_default_timezone_get(); $date_format = (is_logged_in($ui) && $ui['date_format'] !== 'default') ? $ui['date_format'] : $config['default_date_format']; $date = date_create('@'.$timestamp); date_timezone_set($date, timezone_open($time_zone)); return date_format($date, $date_format); } Add interval to unix timestamp. function add_interval_timestamp($config, $interval, $timestamp = NULL) { $timestamp = ($timestamp === NULL) ? NULL : '@'.$timestamp; $time_zone = ($config['site_time_zone'] === 'default') ? date_default_timezone_get() : $config['site_time_zone']; $date = date_create($timestamp, timezone_open($time_zone)); date_add($date, date_interval_create_from_date_string($interval)); return date_timestamp_get($date); } Substract interval from unix timestamp. function sub_interval_timestamp($config, $interval, $timestamp = NULL) { $timestamp = ($timestamp === NULL) ? NULL : '@'.$timestamp; $time_zone = ($config['site_time_zone'] === 'default') ? date_default_timezone_get() : $config['site_time_zone']; $date = date_create($timestamp, timezone_open($time_zone)); date_sub($date, date_interval_create_from_date_string($interval)); return date_timestamp_get($date); }
  12. http://php.net/manual/en/pdo.prepared-statements.php <?php $stmt = $dbh->prepare("INSERT INTO REGISTRY (name, value) VALUES (:name, :value)"); $stmt->bindParam(':name', $name); $stmt->bindParam(':value', $value); // insert one row $name = 'one'; $value = 1; $stmt->execute(); // insert another row with different values $name = 'two'; $value = 2; $stmt->execute(); ?>
  13. You mean something like this $query = 'UPDATE config SET value = :value WHERE config = :key'; $update = $db->prepare($query); $update->bindParam(':value', $value, PDO::PARAM_STR); $update->bindParam(':key', $key, PDO::PARAM_STR); foreach($post as $key => $value) { $value = $value; $key = $key; $bool = $update->execute(); }
  14. TABLE NAME config id = INT(11), config = varchar(255), value = varchar(255) +----------+--------------------------------+----------------------------------+ | id | config | value | +----------+--------------------------------+----------------------------------+ | 1 | captcha_type | disabled | # disabled, recaptcha_version_2, solvemedia +----------+--------------------------------+----------------------------------+ | 2 | captcha_login | true | # false, true +----------+--------------------------------+----------------------------------+ | 3 | captcha_pass_recovery | true | # false, true +----------+--------------------------------+----------------------------------+ | 4 | captcha_reset_pass | false | # false, true +----------+--------------------------------+----------------------------------+ | 5 | recaptcha_version_2_site_key | K7ERoXZln9UvnD.NaOksQEDlfkRWMlYz | +----------+--------------------------------+----------------------------------+ | 6 | recaptcha_version_2_secret_key | K7ERoXZln9UvnD.NaOksQEDlfkRWMlYz | +----------+--------------------------------+----------------------------------+ | 7 | recaptcha_version_2_type | image | # audio, image +----------+--------------------------------+----------------------------------+ | 8 | recaptcha_version_2_theme | light | # dark, light +----------+--------------------------------+----------------------------------+ | 9 | recaptcha_version_2_size | normal | # compact, normal +----------+--------------------------------+----------------------------------+ | 10 | solvemedia_public_key | K7ERoXZln9UvnD.NaOksQEDlfkRWMlYz | +----------+--------------------------------+----------------------------------+ | 11 | solvemedia_private_key | K7ERoXZln9UvnD.NaOksQEDlfkRWMlYz | +----------+--------------------------------+----------------------------------+ | 12 | solvemedia_hash_key | K7ERoXZln9UvnD.NaOksQEDlfkRWMlYz | +----------+--------------------------------+----------------------------------+ | 13 | site_name | Testing site name | +----------+--------------------------------+----------------------------------+ | 14 | site_title | Testing site title | +----------+--------------------------------+----------------------------------+ | 15 | site_description | | +----------+--------------------------------+----------------------------------+ | 16 | site_keywords | | +----------+--------------------------------+----------------------------------+ | 17 | site_url | www.testingsite.com/test | +----------+--------------------------------+----------------------------------+ .....................................................................................................................................................................
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.