Skip to main content

Show Posts

This section allows you to view all Show Posts made by this member. Note that you can only see Show Posts made in areas you currently have access to.

Messages - Mohammad

1
Suggestions / Re: Error handling in PHPRD
hi Willvin ,

can please help to sort this problem . in the Localhost server when i accessing the import or export the file i got error 500
php is not getting the database and csrf_token=371ce9edfeeb98c14a46d27583c219ec  casing  .htacss  is denied Apache .

Same thing is happening when i upload the database application in live server its same problem .i did the enable function of htacess but doesn't work .\\

it will highly appreciated in advance for helping . i intend to buy license but im not happy to see its not functional  .

thanks
Mohammad

2
Suggestions / Re: Error handling in PHPRD
Hello , Please check below code #

<?php
/**
 * Index Page Controller
 * @category  Controller
 */
class IndexController extends BaseController{
   function __construct(){
      parent::__construct();
      $this->tablename = "users";
   }
   /**
     * Index Action
     * @return null
     */
   function index(){
      if(user_login_status() == true){
         $this->redirect(HOME_PAGE);
      }
      else{
         $this->render_view("index/index.php");
      }
   }
   private function login_user($username , $password_text, $rememberme = false){
      $db = $this->GetModel();
      $username = filter_var($username, FILTER_SANITIZE_STRING);
      $db->where("user_name", $username)->orWhere("email", $username);
      $tablename = $this->tablename;
      $user = $db->getOne($tablename);
      if(!empty($user)){
         //Verify User Password Text With DB Password Hash Value.
         //Uses PHP password_verify() function with default options
         $password_hash = $user['password'];
         $this->modeldata['password'] = $password_hash; //update the modeldata with the password hash
         if(password_verify($password_text,$password_hash)){
              unset($user['password']); //Remove user password. No need to store it in the session
            set_session("user_data", $user); // Set active user data in a sessions
            //if Remeber Me, Set Cookie
            if($rememberme == true){
               $sessionkey = time().random_str(20); // Generate a session key for the user
               //Update user session info in database with the session key
               $db->where("id", $user['id']);
               $res = $db->update($tablename, array("login_session_key" => hash_value($sessionkey)));
               if(!empty($res)){
                  set_cookie("login_session_key", $sessionkey); // save user login_session_key in a Cookie
               }
            }
            else{
               clear_cookie("login_session_key");// Clear any previous set cookie
            }
            $redirect_url = get_session("login_redirect_url");// Redirect to user active page
            if(!empty($redirect_url)){
               clear_session("login_redirect_url");
               return $this->redirect($redirect_url);
            }
            else{
               return $this->redirect(HOME_PAGE);
            }
         }
         else{
            //password is not correct
            return $this->login_fail("Username or password not correct");
         }
      }
      else{
         //user is not registered
         return $this->login_fail("Username or password not correct");
      }
   }
   /**
     * Display login page with custom message when login fails
     * @return BaseView
     */
   private function login_fail($page_error = null){
      $this->set_page_error($page_error);
      $this->render_view("index/login.php");
   }
   /**
     * Login Action
     * If Not $_POST Request, Display Login Form View
     * @return View
     */
   function login($formdata = null){
      if($formdata){
         $modeldata = $this->modeldata = $formdata;
         $username = trim($modeldata['username']);
         $password = $modeldata['password'];
         $rememberme = (!empty($modeldata['rememberme']) ? $modeldata['rememberme'] : false);
         $this->login_user($username, $password, $rememberme);
      }
      else{
         $this->set_page_error("Invalid request");
         $this->render_view("index/login.php");
      }
   }
   /**
     * Insert new record into the user table
    * @param $formdata array from $_POST
     * @return BaseView
     */
   function register($formdata = null){
      if($formdata){
         $request = $this->request;
         $db = $this->GetModel();
         $tablename = $this->tablename;
         $fields = $this->fields = array("user_name","password","email","photo","status"); //registration fields
         $postdata = $this->format_request_data($formdata);
         $cpassword = $postdata['confirm_password'];
         $password = $postdata['password'];
         if($cpassword != $password){
            $this->view->page_error[] = "Your password confirmation is not consistent";
         }
         $this->rules_array = array(
            'user_name' => 'required',
            'password' => 'required',
            'email' => 'required|valid_email',
            'photo' => 'required',
            'status' => 'required',
         );
         $this->sanitize_array = array(
            'user_name' => 'sanitize_string',
            'email' => 'sanitize_string',
            'photo' => 'sanitize_string',
            'status' => 'sanitize_string',
         );
         $this->filter_vals = true; //set whether to remove empty fields
         $modeldata = $this->modeldata = $this->validate_form($postdata);
         $password_text = $modeldata['password'];
         //update modeldata with the password hash
         $modeldata['password'] = $this->modeldata['password'] = password_hash($password_text , PASSWORD_DEFAULT);
         //Check if Duplicate Record Already Exit In The Database
         $db->where("user_name", $modeldata['user_name']);
         if($db->has($tablename)){
            $this->view->page_error[] = $modeldata['user_name']." Already exist!";
         }
         //Check if Duplicate Record Already Exit In The Database
         $db->where("email", $modeldata['email']);
         if($db->has($tablename)){
            $this->view->page_error[] = $modeldata['email']." Already exist!";
         }
         if($this->validated()){
            $rec_id = $this->rec_id = $db->insert($tablename, $modeldata);
            if($rec_id){
               $this->login_user($modeldata['email'] , $password_text);
               return;
            }
            else{
               $this->set_page_error();
            }
         }
      }
      $page_title = $this->view->page_title = "Add New Users";
      return $this->render_view("index/register.php");
   }
   /**
     * Logout Action
     * Destroy All Sessions And Cookies
     * @return View
     */
   function logout($arg=null){
      Csrf::cross_check();
      session_destroy();
      clear_cookie("login_session_key");
      $this->redirect("");
   }
}
3
Suggestions / Error handling in PHPRD
hi , anyone can help me i got this problem

Error 500
Server Error

Exception Traces
This will only be displayed in DEVELOPMENT_MODE.
Error Message   SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '= 'sam' LIMIT 1' at line 1
File   C:\xampp\htdocs\myproject\app\models\PDODb.php On Line 1045
Stack Trace   1 C:\xampp\htdocs\myproject\app\models\PDODb.php(1045): PDOStatement->execute()
2 C:\xampp\htdocs\myproject\app\models\PDODb.php(1079): PDODb->get('manifet', 1, '*')
3 C:\xampp\htdocs\myproject\app\controllers\IndexController.php(28): PDODb->getOne('manifet')
4 C:\xampp\htdocs\myproject\app\controllers\IndexController.php(88): IndexController->login_user('sam', 'admin', false)
5 C:\xampp\htdocs\myproject\system\Router.php(196): IndexController->login(Array)
6 C:\xampp\htdocs\myproject\system\Router.php(109): Router->run('index/login/')
7 C:\xampp\htdocs\myproject\index.php(106): Router->init()