Wednesday, April 8, 2015

Pagination Issue in Codeigniter [solved]

There is many students face problem in Pagination library in CI
CodeIgniter

Please update the following code and your problem resolved


public function index($index=1)
    {
        $per_page=2;   // set accorrding to requiremnet
       if($index==1){
           $index=0;
       }
         
         $this->load->model("MODLE_NAME");
            $user_data['user_data']=$this->Model_name->select($per_page,$index);
            $t=$this->Model_name;
            $table_name=$t::table_name;
            $query = $this->db->get($table_name);
            $row_count=$query->num_rows();
   // pagination     
       $this->load->library('pagination');

            $config['base_url'] = base_url().'admin/controller_function/index/';
            $num_rows_pagination=$row_count;
            $config['total_rows'] = $num_rows_pagination;
            $config['per_page'] = $per_page;
             $config['uri_segment'] = 4;
               // pagination formating
                    $config['full_tag_open'] = "<br><ul class='pagination'>";
                    $config['full_tag_close'] ="</ul>";
                    $config['num_tag_open'] = '<li>';
                    $config['num_tag_close'] = '</li>';
                    $config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
                    $config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
                    $config['next_tag_open'] = "<li>";
                    $config['next_tagl_close'] = "</li>";
                    $config['prev_tag_open'] = "<li>";
                    $config['prev_tagl_close'] = "</li>";
                    $config['first_tag_open'] = "<li>";
                    $config['first_tagl_close'] = "</li>";
                    $config['last_tag_open'] = "<li>";
                    $config['last_tagl_close'] = "</li>";
            
            $this->pagination->initialize($config); 
            $user_data['pagination']= $this->pagination->create_links();
            $user_data['total_row']=$row_count;
            $user_data['page'] = 'controller_function';
        $this->load->view('admin/Manage/view_page',$user_data);   // Customize according its to view panel
       
   }
 
                           //---------------WARNING------------ 
 
//================= YOUR MODEL and Controller According to your Project ================ 

Monday, April 6, 2015

validation for web URL and Email

This is code for validation for web URL and Email

use this page as is it and get your full Validation Page 

like and share

 follow on  github


 
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title>validate email and url</title>
<link rel="stylesheet" href="css/bootstrap.css" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
<style>
.error{
font-family: cursive;
font-size: 10px;
color: red;
margin-bottom: 10px;
}
</style>
</head>
<body id="html_body">
<div class="row" style="padding: 5px;margin: 2px;">
<div class="step2 col-md-12" style="margin-bottom:10px">
<div class="heading"><h2><strong> Check Email and url </strong></h2></div>
<form action="" method="post" id="register-form" novalidate="novalidate">
<div class="content col-md-12" style="border: solid 1px #eaeaea;padding: 10px;">
<div class="content col-md-12">
<div class="form-group col-md-12" >
<label for="width" class="col-sm-4" >Email-Id</label>
<div class="col-sm-8" >
<input type="email" name="emailid" class="form-control" id="email" placeholder="admin@php999.com " required="required">
</div>
</div>
<div class="col-sm-8 col-sm-offset-4 error email"></div>
</div>
<div class="content col-md-12">
<div class="form-group col-md-12" >
<label for="width" class="col-sm-4" >Website</label>
<div class="col-sm-8" >
<input type="text" name="website" class="form-control" id="website" placeholder="www.php999.blogspot.in " required="required">
</div>
</div>
<div class="col-sm-8 col-sm-offset-4 error website"></div>
</div>
</div>
</form>
</div>
<div class="content col-md-12">
<div class="col-md-3" style="float:right;">
<button class="btn" style="background-color:#fe8409;" id="get-code" type="" name="preview">GET CODE!</button>
</div>
</div>
<div class="col-md-12" id="html-block" style="margin:10px;display:none">
<textarea id="html-content" rows="8" cols="55"></textarea>
</div>
</div>
<script>
$('#get-code').click(function(e){
var email = $('#email').val();
var email_status=validateEmail(email);
// alert("email_status="+email_status);
var website = $('#website').val();
// alert(website);
var website_status=validateWeb(website);
// alert("website_status="+website_status);
if(email_status==false){
$('.email').html('Please enter your a valid email address...');
} else if(website_status==false){
$('.website').html('Please enter a valid url ');
} else {
$('.email').html('');
$('.website').html('');
// alert("tick tok");
var htmlcode = $('#html_body').html();
$('#html-content').val(htmlcode);
$('#html-block').css('display','block');
e.preventDefault();
}
});
</script>
<script>
function validateEmail(email){
var emailReg = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
var valid = emailReg.test(email);
if(!valid) {
return false;
} else {
return true;
}
}
function validateWeb(web){
var webReg = new RegExp(/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:[\w-]*)\.\w{2,}$/);
//var webReg = new RegExp(/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:[\w-]*)\.\w{2,}$);
var valid = webReg.test(web);
if(!valid) {
return false;
} else {
return true;
}
}
</script>
<div class="row">
<span class="glyphicon glyphicon-barcode"> 2015&COPY; himmsrathore | <a target="_blank" href="http://php999.blogspot.in">php999 </a></span></div>
</body>
//  
</html>
 
 

Saturday, April 4, 2015

How can I prevent SQL-injection in PHP?

How can I prevent SQL-injection in PHP?

Use prepared statements and parameterized queries.

<?php
// Using PDO:

    $stmt = $pdo->prepare('SELECT * FROM Table_name WHERE uname = :uname');

    $stmt->execute(array('uname' => $name));

    foreach ($stmt as $row) {
        // do something with $row
    }

//    Using MySQLi:

    $stmt = $dbConnection->prepare('SELECT * FROM employees WHERE name = ?');
    $stmt->bind_param('s', $name);

    $stmt->execute();

    $result = $stmt->get_result();
    while ($row = $result->fetch_assoc()) {
        // do something with $row
    }
?>

Correctly setting up the connection

Note that when using PDO to access a MySQL database real prepared statements are not used by default. To fix this you have to disable the emulation of prepared statements. An example of creating a connection using PDO is:

                                                                                           
                                                                                           
$dbConnection = new PDO('mysql:dbname=dbtest;host=127.0.0.1;charset=utf8', 'user', 'pass');
$dbConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);                            
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);                    
                                                                                           
                                                                                           
 
In the above example the error mode isn't strictly necessary, but it is advised to add it. This way the script will not stop with a Fatal Error when something goes wrong. And it gives the developer the chance to catch any error(s) which are thrown as PDOExceptions.
What is mandatory however is the first setAttribute() line, which tells PDO to disable emulated prepared statements and use real prepared statements. This makes sure the statement and the values aren't parsed by PHP before sending it to the MySQL server (giving a possible attacker no chance to inject malicious SQL).
Although you can set the charset in the options of the constructor, it's important to note that 'older' versions of PHP (< 5.3.6) silently ignored the charset parameter in the DSN.

Explanation

What happens is that the SQL statement you pass to prepare is parsed and compiled by the database server. By specifying parameters (either a ? or a named parameter like :name in the example above) you tell the database engine where you want to filter on. Then when you call execute, the prepared statement is combined with the parameter values you specify.
The important thing here is that the parameter values are combined with the compiled statement, not an SQL string. SQL injection works by tricking the script into including malicious strings when it creates SQL to send to the database. So by sending the actual SQL separately from the parameters, you limit the risk of ending up with something you didn't intend. Any parameters you send when using a prepared statement will just be treated as strings (although the database engine may do some optimization so parameters may end up as numbers too, of course). In the example above, if the $name variable contains 'Sarah'; DELETE FROM employees the result would simply be a search for the string "'Sarah'; DELETE FROM employees", and you will not end up with an empty table.
Another benefit with using prepared statements is that if you execute the same statement many times in the same session it will only be parsed and compiled

 

Thursday, April 2, 2015

Disable click outside of bootstrap model area to close modal

Disable click outside of bootstrap model area to close modal

making a bootstrap project, with a couple of Bootstrap 'Modals'. someone  trying to customize some of the default features.

they want to disable click on outside of model area to close modal

$('#myModal').modal({
    backdrop: 'static',
    keyboard: false  // to prevent closing with Esc button (if you want this too)
})
 
happy Coding :)

Friday, March 27, 2015

How to connect from windows command prompt to mysql command line

The cd in your question is invalid 


cd CD:\MYSQL\bin\
 
You can't cd to CD:\ anything, because CD:\ isn't a valid directory in Windows. CD: would indicate a drive, except that drives are restricted to a single letter between A and Z

If your \MYSQL\BIN is on drive C:, then your commands need to be:


C:\>cd \MYSQL\Bin

C:\MYSQL\Bin>mysql -u root -p admin

-
 
If you're not already on C: (which you'll know by looking at the prompt in the cmd window), or your MySQL folder is on another drive (for instance, D:), change to that drive too:


C:\> cd /d D:\MYSQL\Bin

D:\MYSQL\Bin>mysql -u root -p admin

-
 
 
The .exe after mysql is optional, since .exe is an executable extension on Windows. If you type mysql, Windows will automatically look for an executable file with that name and run it if it finds it.

Saturday, March 21, 2015

create an animated scroll to top

In this tutorial you will learn how you can create an animated scroll to top button with jQuery.

create the button.


 
<a href="#" class="scrollToTop">Top</a> 
 
//----------------------------------------------------
// CSS  PART
// ---------------------------------------------------
 
.scrollToTop{
 width:100px; 
 height:130px;
 padding:10px; 
 text-align:center; 
 background: whiteSmoke;
 font-weight: bold;
 color: #444;
 text-decoration: none;
 position:fixed;
 top:75px;
 right:40px;
 display:none;
 background: url('arrow_up.png') no-repeat 0px 20px;
}
.scrollToTop:hover{
 text-decoration:none;
}
 
 //-----------------------
//  Jquery part  
//---------------------------- 
 
$(document).ready(function(){
 
 //Check to see if the window is top if not then display button
 $(window).scroll(function(){
  if ($(this).scrollTop() > 100) {
   $('.scrollToTop').fadeIn();
  } else {
   $('.scrollToTop').fadeOut();
  }
 });
 
 //Click event to scroll to top
 $('.scrollToTop').click(function(){
  $('html, body').animate({scrollTop : 0},800);
  return false;
 });
 
});
 
 


 

Friday, March 20, 2015

Remove nginx and re activate apache

Remove nginx and re activate apache

 
//First, you need to stop nginx so it releases port 80 so that apache2 can listen to it later on.
-------------------------------------
sudo service nginx stop                                                           

//Next, if nginx was installed with apt-get, removing it would be as simple as

sudo apt-get remove nginx

//Instead, you can also use

sudo apt-get purge nginx

//First one removes all package files, while the second also removes the configuration files.
//If you intend to use nginx later on with the configuration you did, use remove. Else, I would suggest using purge.

//After removing nginx, you can restart apache to make sure it is listening to port 80.

sudo apache2ctl restart

//If you had removed apache before installing nginx, you can re-install it with

sudo apt-get install apache2 
 
 

How to Host a Laravel Project on Hostinger’s hPanel: A Step-by-Step Guide

How to Host a Laravel Project on Hostinger’s hPanel: A Step-by-Step Guide If you're looking to host a Laravel project on Hostinger’s hPa...