Showing posts with label Framework. Show all posts
Showing posts with label Framework. Show all posts

Yii Framework Generating Code with Gii

Yii Framework Generating Code with Gii


Yii Framework Generating Code with Gii Yii Framework is the Auto generating Code MVC Patters Module View Controller Any one type this Code Module or View or Controller another two auto generating the Code is very code friendly Framework.

Yii Framework Generating Code with Gii
Yii Framework Generating Code with Gii


Gii

Configuration Gii File first Config/web.php 

$config = [ ... ];

if (YII_ENV_DEV) {
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
    ];
}

decode gii file is enable this code

'gii' => [
    'class' => 'yii\gii\Module',
    'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*', '192.168.178.20'] // adjust this to your needs
],
Next, click on the "Preview" button. You will see a list of files to be generated, as shown below.

gii Code Generator




Codeigniter Frameworks

Codeigniter Frameworks

Codeigniter Frameworks is a powerful PHP Frameworks with a very small footprint, built for developer and very easily learn in Codeigniter Frameworks. Basic Introduction of Codeigniter Framework  Please Click Here   

Codeigniter Frameworks
Codeigniter Frameworks


Best Features of Codegniter

  • Model-View-Controller System(MVC)
  • Light Wight
  • Full Featured database classes with support for several platforms
  • Form and Data Validation
  • Active Record Databasupport
  • FTP Class
  • Session Management
  • Security and XSS Filtering
  • Email Sending Class. Support Attachments, HTML/Text email, and Multiple Protocols
  • Localization
  • Pagination and Image manipulation LibraryC
  • Search Engine Friendly URL's
Codeigniter Session Storage

Codeigniter Session Storage is very simpley and easily storage Login Authentication Username storage session Read More

Important Codeigniter Tutorial


Security Features of Codeigniter Frameworks 

1.Codeigniter Seacurity Features First Remote code Execution <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?> This Ensures that the PHP Files is not accessible directly by manipulating or running a script, which would compromise the system.

2.SQL injection: This type of attack is highly common on the web. A SQL injection occurs when an attacker exploits the front-end and the post data to retrieve secure data from the database. According to CodeIgniter manual, it becomes evident that your web application is automatically safe from SQL injection as the POST data is retrieved in the controller using $this->input->post (‘’); which is automatically filtered by CodeIgniter.  CodeIgniter User Manual excerpt proves this fact: “Beyond simplicity, a major benefit to using the Active Record features is that it allows you to create database independent applications, since the query syntax is generated by each database adapter. It also allows for safer queries, since the values are escaped automatically by the system.”

3,XSS Attacks: An XSS or Cross Site scripting attack is unarguably the common reason for the demise of web applications. A XSS attack works by a hacker crafting a malicious URL into the browser in order to compromise the security of the application. CodeIgniter has a built in XSS filter which is initialized automatically. In order to double check the security threats against XSS attacks, a Firefox add-on called XXS Me (download here) can be used to test the sample application against 96 different types of attacks. The results are shown in the image below. It shows that the all form input fields were not found unencoded, which means the XSS filter within CodeIgniter did its job.

Codeigniter Session Storage

Codeigniter Session Storage


Codeigniter Session Storage
Codeigniter Session Storage
Codeigniter Session Storage is Very simpley and easly storage Login authentication  Username stored session. Codeigniter Login form
using this code:

$this->session->set_userdata() 

I just found that setting sess_encrypt_cookie to FALSE fixed the chrome logout issue.

Session Storage Config settings following Code.

$config['sess_encrypt_cookie'] = FALSE

$config['sess_match_useragent'] = FALSE;

$config['sess_expiration'] = 8600;


$this->session->set_userdata('user_session', $user_session_data);

$autoload['libraries'] = array("session");

$this->load->library('session');

Model

 function Login($email,$pass){
         $this->db->where('username' ,$email);
         $this->db->where('password',$pass);
         $query=$this->db->get('users');  
     if ($query->num_rows == 1) {        
    return true;  
     }    
     return FALSE;
    }

Controller:

   function varification(){
            $this->load->model('login_model');
    $email=$this->input->post('email');
    $pass=$this->input->post('pass');
    $success=$this->login_model->Login($email,$pass);
    if ($success) {
                 $data = array(
                       'user_name' => $rows->username,
                       'logged_in' => TRUE,
                      'validated' => true
                 );
                $this->session->set_userdata($data);
                redirect ('site/index');
    } else{ // incorrect id or password
             redirect ('site/login');
            }
    }

Simple Login with CodeIgniter in PHP

Simple Login with CodeIgniter in PHP

Simple Login with CodeIgniter
Simple Login with CodeIgniter 

CodeIgniter is an open source web application MVC structure Framework built in PHP designed to make your life as a programmer easier.  CodeIgniter allowing good speed and good performance when the site up and running. CodeIgniter details already previous post discussed CodeIgniter.

CodeIgniter Login  Database



CREATE TABLE `users` (
 `id` tinyint(4) NOT NULL AUTO_INCREMENT,
 `username` varchar(10) NOT NULL,
 `password` varchar(100) NOT NULL,
 PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;



insert into users (username, password) values ('dev2tricks', MD5('secret'));
                                                                 or
insert into users (username, password) values ('dev2tricks', base64('secret'));

Configure CodeIgniter

Database Access

Update the file application/config/database.php in your CodeIgniter installation with your database info:


$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'yourdbusername';
$db['default']['password'] = 'yourdbpassword';
$db['default']['database'] = 'yourdbname';


Default Controller

We need to tell CodeIgniter to land into our login page instead of the default welcome page.  Update the file application/config/routes.php in your CodeIgniter installation with you controller’s name.  We’ll call our landing controller login.

$route['default_controller'] = "login";

Libraries

In the file application/config/autoload.php you can configure the default libraries you want to load in all your controllers.

$autoload['libraries'] = array('database','session');
$autoload['helper'] = array('url');


 Model (application/models/user.php)

<?php

Class User extends CI_Model
{
 function login($username, $password)
 {
   $this -> db -> select('id, username, password');
   $this -> db -> from('users');
   $this -> db -> where('username', $username);
   $this -> db -> where('password', MD5($password));
   $this -> db -> limit(1);

   $query = $this -> db -> get();

   if($query -> num_rows() == 1)
   {
     return $query->result();
   }
   else
   {
     return false;
   }
 }
}
?>



 Login Controller (application/controllers/login.php)



<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {

 function __construct()
 {
   parent::__construct();
 }

 function index()
 {
   $this->load->helper(array('form'));
   $this->load->view('login');
 }

}

?>


Login View (application/views/login.php)


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
   <title>Simple Login with CodeIgniter</title>
 </head>
 <body>
   <h1>Simple Login with CodeIgniter</h1>
   <?php echo validation_errors(); ?>
   <?php echo form_open('verifylogin'); ?>
     <label for="username">Username:</label>
     <input type="text" size="20" id="username" name="username"/>
     <br/>
     <label for="password">Password:</label>
     <input type="password" size="20" id="passowrd" name="password"/>
     <br/>
     <input type="submit" value="Login"/>
   </form>
 </body>
</html>


Login Controller (application/controllers/login.php)



<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class VerifyLogin extends CI_Controller {

 function __construct()
 {
   parent::__construct();
   $this->load->model('user','',TRUE);
 }

 function index()
 {
   //This method will have the credentials validation
   $this->load->library('form_validation');

   $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
   $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');

   if($this->form_validation->run() == FALSE)
   {
     //Field validation failed.  User redirected to login page
     $this->load->view('login_view');
   }
   else
   {
     //Go to private area
     redirect('home', 'refresh');
   }

 }

 function check_database($password)
 {
   //Field validation succeeded.  Validate against database
   $username = $this->input->post('username');

   //query the database
   $result = $this->user->login($username, $password);

   if($result)
   {
     $sess_array = array();
     foreach($result as $row)
     {
       $sess_array = array(
         'id' => $row->id,
         'username' => $row->username
       );
       $this->session->set_userdata('logged_in', $sess_array);
     }
     return TRUE;
   }
   else
   {
     $this->form_validation->set_message('check_database', 'Invalid username or password');
     return false;
   }
 }
}
?>

and Codeigniter database Table access insert,update delete click here


Codeigniter Insert Update Delete

PHP Codeigniter framework.

Codeigniter is one of the Framework and the basic principles of MVC architecture. Codeigniter Insert Update Delete Follows example code.

Codeigniter Insert Update Delete
Codeigniter Insert Update Delete

Codeigniter Insert Update Delete

View


<div id="codeignitersample" class="modal fade" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">

                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                <h4 class="modal-title" id="myModalLabel">New Entry</h4>
                            </div>
                            <div class="modal-body">
                                <div id="testmodal" style="padding: 5px 20px;">
                                    <form id="antoform" class="form-horizontal " role="form">


                                      <input type="hidden" disabled="true" class="form-control" id="txtDate" name="txtDate">
                               
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">Task Title</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control" id="title" name="title">
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">Description</label>
                                            <div class="col-sm-9">
                                                <textarea class="form-control" style="height:55px;" id="descr" name="descr"></textarea>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default antoclose" data-dismiss="modal">Close</button>
                                <button type="button" id="btnAddTask" class="btn btn-primary antosubmit">Save changes</button>
                            </div>
                        </div>
                    </div>
                </div>


Model


<?php

defined('BASEPATH') or exit('Error!');

class Appmodel extends CI_Model
{

public function __construct(){
# code...
parent::__construct();
$this->load->database();
}
public function addTask($title,$details,$date){

$task_details = array('task_id'=>mt_rand(1,9999999999),
  'task_name'=>$title,
  'task_details'=>$details,
  'date'=>$date
            );
return $this->db->insert('task',$task_details);
}
public function allTask(){

$sql = $this->db->get("task");
return $sql->result_array();
}
public function deleteTask($id){
$this->db->where('task_id',$id);

return $this->db->delete('task');

}
public function editTask($title,$details,$id){
$new_taskdetails=array('task_name'=>$title,'task_details'=>$details);
$this->db->where('task.task_id',$id);
return $this->db->update('task',$new_taskdetails);
}
}


Controller


<?php
defined('BASEPATH') or exit('Error!');
/**
*
*/
class App extends CI_Controller{

private $data;

public function __construct(){

parent::__construct();
$this->load->library(array('session','form_validation','mydateconverter'));
$this->load->helper(array('url'));
$this->load->model('appmodel');

}
public function index(){
$this->data['page_title'] = "Dev2tricks ! ";
$this->load->view('ui/tpl/head',$this->data);
$this->data['tasks']=$this->appmodel->allTask();
$this->load->view('ui/home',$this->data);


}
//ajax event!
public function addtask(){

   $response = $this->appmodel->addTask($this->input->post('title'),
$this->input->post('description'),
$this->mydateconverter->convertDate($this->input->post('date')));
echo $response;

}
//ajax event!

public function deletetask(){
$response = $this->appmodel->deleteTask($this->input->get('id'));
echo $response;
}

//ajax event!
public function editask(){
$response = $this->appmodel->editTask($this->input->post('title'),
$this->input->post('description'),
$this->input->post('id')
);
echo $response;
}

}


Database File


CREATE TABLE `cii` (
  `id` int(11) NOT NULL auto_increment,
  `cii_id` int(11) NOT NULL,
  `cii_name` varchar(255) NOT NULL,
  `cii_details` text NOT NULL,
  `date` varchar(100) NOT NULL,
  PRIMARY KEY  (`id`)
)

Introduction to codeigniter

Introduction to codeigniter

Introduction to Codeigniter
Introduction to Codeigniter

Introduction


Codeigniter is one of the Framework and the basic principles of MVC architecture. MVC Format Module Control View It will show you how a basic codeigniter application is constructed in step-by-step fashion.

  1. Codeigniter is Most Used Module Active Record basic database queries.
  2. Form Validation is Used
  3. Site Url Passing Method Routhing basics

why use codeigniter

Useful Documentation

Codeigniter most advantage CI over any other framework is it's documentation.  CIs documentation is 10 times better than other framework documentation I have come cross and I strongly think thats because CI is backed by a company and not just a community.  EllisLab, the company behind CI, takes a lot of pride in CI and they have big plans for it and thats why they don’t have a problem in spending the time that is necessary to come up with quality documentation for the user community.

Database abstraction and more.

Every decent framework has a database abstraction layer nowadays and CI is no exception. You can easily create insert, update and delete statements without needing to write raw SQL. Handle connections to multiple databases within one application and connect to any of the following database types: MySQL (4.1+), MySQLi, MS SQL, Postgre, Oracle, SQLite, or ODBC. CI also lets you manipulate your database like add/remove columns from tables, create new tables and remove old ones using it’s new database forge library.

No installation necessary.

Believe it or not, one of the hardest things I have experienced with trying new frameworks is installing them. I am not a fan of UNIX command line so I tend to look for tools that I can install and use by just uploading files to a directory. CI fits this requirement nicely. No need for PEAR packages or server modifications to get the framework up and running. Just upload the files to your server and your off.

MVC Architecture

The model, view, controller architecture is nothing new. It seems like all the coding frameworks are MVC nowadays, and if they aren’t it can be configured easily. I have had experience building large apps the procedural way and every time they end up with unmanageable spaghetti code. The MVC way of doing things offers nice code separation and keeps things clean. Some frameworks force you to do things by the books but CI lets you use MVC in a way that makes sense you. If that means ignoring models all together then so be it. Codeigniter Module


Trojan Will attack over 50000 systems - Java

Hi viewers,

shot

One of the shocking news.

A cross-platform remote access Trojan thats being openly sold as a service to all types of attackers, from opportunistic cybercriminals to cyberespionage groups, has been used to attack more than 500,000 systems over the past three years.

The RAT (Remote Access Tool/Trojan), which depending on the variant is known as Adwind, AlienSpy, Frutas, Unrecom, Sockrat, jRat or JSocket, is evidence of how successful the malware-as-a-service model can be for malware creators.

Adwind is written in Java, so it can run on any OS that has a Java runtime installed including Windows, Mac OS X, Linux and Android. The Trojan has been continuously developed since at least 2012 and is being sold out in the open via a public website.

Like most Trojans, Adwind can be used to remotely control infected computers; to steal files, key strokes and saved passwords; to record audio and video through the computers webcam and microphone and more. Because it has a modular architecture, users can also install plug-ins that extend its functionality.

The Adwind author, who researchers from Kaspersky Lab believe to be a Spanish-speaking individual, is selling access to the RAT on a subscription-based model, with prices ranging from $25 for 15 days to $300 a year. The buyers get technical support, obfuscation services to evade antivirus detection, virtual private network accounts and free scans with multiple antivirus engines to ensure that their sample is not detected when deployed.

Kaspersky Lab estimates that since 2013, attackers have attempted to infect over 440,000 systems with various versions of Adwind. Between August and January alone, attackers used the RAT in around 200 spear-phishing campaigns that have reached over 68,000 users.

The latest incarnation of Adwind was launched in June 2015 under the name JSocket and is still being sold.

In 2015, Russia was the most attacked country, with UAE and Turkey again near the top, along with the USA, Turkey and Germany, the Kaspersky researchers said in a blog post.

They estimated that by the end of 2015 there were around 1,800 Adwind/JSocket users, putting the developers annual revenue at over $200,000. The large number of users makes it hard to build an attacker profile. The RAT could be used by anyone from low-level scammers to cyberspies and private individuals looking to monitor their partners or spouses.

In December, researchers working with the Citizen Lab at the University of Torontos Munk School of Global Affairs documented the activities of a group of attackers that targeted politicians, journalists and public figures from several South American countries. An earlier version of Adwind, called AlienSpy, was listed as one of the malware tools used by the group.

Kaspersky Lab itself started a detailed investigation into Adwind after a financial institution in Singapore received the RAT via rogue emails that were purporting to come from a major Malaysian bank. This was part of a targeted attack that the company believes was launched by a suspect of Nigerian origin who focuses on financial institutions.

Despite several attempts to take down and stop the Adwind developers from distributing the malware, Adwind has survived for years and has been through rebranding and operational expansion that ranged from the provision of additional plugins for the malware to its own obfuscation tool and a even a warranty for FUD (fully undetected malware) to customers, the Kaspersky researchers said in a research paper.

Since Adwind is written in Java, it is distributed as a JAR (Java Archive) file and needs the Java Runtime Environment (JRE) to run. One possible method to prevent its installation is to change the default application for handling JAR files to something like Notepad. This will prevent the codes execution and will just result in a notepad window with gibberish text in it.

Of course, if JRE is not needed by other applications installed on a computer or by websites visited by its users, then it should be removed. Unfortunately thats not possible in most business environments, as Java is still a major programming language for business applications.

How to Slim Framework Image Upload

Slim Framework is Micro Framework Similer to core php base. The Slim Framework doesn't have database functionality by default so you can just use core php for that.  And if you do not know how that works Follow Some code.

slim

Image Upload


$app->get("/upload", function () use ($app) {

   $app->view()->setData('username', null);
   $app->render('upload.php');


});


Image Upload Session Authentication:

$app->post("/upload",function () use ($app){
if(isset($_POST['submit']))
{
//$app->request()->$_FILES['picture']['name'];
echo $_FILES['picture']['name'];
echo $_FILES['picture']['size'];
$tmpname = $_FILES['picture']['tmp_name'];
$_SESSION['name'] = "img/".$_FILES['picture']['name'];
move_uploaded_file($tmpname,$_SESSION['name'] );
$uploaddir="/xampp/htdocs/OAuth/Slim/assets/img";
echo '<img src="'.$_SESSION['name'].'">';
}
});

Slim Framework Session Login and sign Up

Slim Framework is Micro Framework Simple code and very powerful web applications and Api.


Micro Framework you can use this middleware to implement HTTP Basic Authentication.By default middleware authenticates array of username and password.  You can also againt database or any other datasource by providing custom authenticator.

Slim Framework Simple Login Authentication Code and Session

<?php
session_cache_limiter(false);
session_start();
require 'class/Slim/Slim.php';
//$app = new SessionCookie();
\Slim\Slim::registerAutoloader();

    $pos = strpos( $_SERVER['PHP_SELF'], '/index.php');
   global $Url;
   $Url = substr( $_SERVER['PHP_SELF'], 0, $pos);
require 'template/View.php';
$View = new View();
$app = new \Slim\Slim([
//'templates.path' => 'assets',
'templates.path' =>  'template','debug'=>true,
'view' => $View
]);
$app->add(new \Slim\Middleware\SessionCookie(array('secret' => 'myappsecret')));

$app->get('/',function()use ($app){
if(empty($_SESSION['username']))
{
$login = strpos( $_SERVER['PHP_SELF'], '/index.php');
    $baseUrl = substr( $_SERVER['PHP_SELF'], 0, $login);
$app->render('Login.php',array('baseUrl' => $baseUrl ));
}
else{
if(isset($_SESSION['secret']))
{
$app1 =(Apps::find_by_client_secret($_SESSION['secret']));
$token = Authtoken::find_by_user_id_and_app_id($_SESSION['id'],$app1->app_id);
if(!empty($token->authorization_code))
{
$_SESSION['secret']=null;
$app->response->redirect($app1->redirect_url.'?token='.$token->authorization_code);

}
}else{
$app->response->redirect('addapp');}

}
});

$routeHelper = function (\Slim\Route $route) {
    echo "Current route is " . $route->getName();if (!isset($_SESSION['username'])) {
            $_SESSION['urlRedirect'] = $app->request()->getPathInfo();
            $app->flash('error', 'Login required');
             // $app->redirect($Url);
        }
};
$user = function ($app) {
    return function () use ($app) {
global $Url;
  // echo "Current route is " . $route->getCurrentRoute();
        if (!isset($_SESSION['username'])) {
            $_SESSION['urlRedirect'] = $app->request()->getPathInfo();
            $app->flash('error', 'Login required');
             $app->redirect($Url);
        }
    };
};


Slim Framework View Specify Template or Layout

$View->setLayout('layout.php');

Slim Framework Simple Registration Model code:


$app->post('/signup',function()use ($app){
//echo 'Hai Im Work Us Slim Framework';
global $Url;

$reg =  new Client();
$username = $app->request()->post('username');
$reg->firstname =  $app->request()->post('firstname');
$reg->lastname =  $app->request()->post('lastname');
$reg->email =  $app->request()->post('email');
$reg->username =  $app->request()->post('username');
$reg->password =  $app->request()->post('password');
//$reg->confirmpassword =  $app->request()->post('confirmpassword');
$reg->dob =  $app->request()->post('dob');
$reg->gender =  $app->request()->post('gender');
$reg->mobilenumber =  $app->request()->post('mobilenumber');
$reg->country =  $app->request()->post('country');
if($reg->is_valid())
{
$reg->save();
}
else
{
$app->flash('error', 'dob '.$reg->errors->on('dob'));
//$app->flash('error', 'email '.$reg->errors->on('email'));
//$app->flash('error', 'mobilenumber '.$reg->errors->on('mobilenumber'));

 $app->response->redirect($Url);
}
 
});






Simple Ionic App

Welcome This My First App for Ionic Framework

Ionic Framework is new Programming Language related to angularjs same structor and advanced script is Ionic and Looking very nice and faster loading my first simple App for ionic framework.

This App Create to "Welcome This My First App for Ionic Framework" couple different variations to get started towards your first ionic App.


HTML Code:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
   <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <link href="http://code.ionicframework.com/1.0.0/css/ionic.min.css" rel="stylesheet">
    <script src="http://code.ionicframework.com/1.0.0/js/ionic.bundle.js"></script>
  </head>
  <body>
 Welcome This My First App for Ionic Framework
  </body>
</html>

App Module

Module Make this an Ionic App similarly Angularjs Concept.

<body ng-app="ionicApp">
angular.module('ionicApp', ['ionic']);

<link href="http://code.ionicframework.com/1.0.0/css/ionic.min.css" rel="stylesheet">
<script src="http://code.ionicframework.com/1.0.0/js/ionic.bundle.js"></script>
<script src="app.js"></script>

Directives


<ion-header-bar class="bar-stable">
 <h1 class="title">Welcome This My First App for Ionic Framework</h1>
</ion-header-bar>

<ion-content class="padding">
 <p>How is My app</p>
</ion-content>