Friday, 9 September 2016
Compress HTML output in Codeigniter
Compress HTML output
Hello friends today i'm sharing code of compress html output in codeIgniter.
To remove useless white spaces and extra stuff from generated HTML, except for JS.
Step 1 : Add the compress hook in config/hooks.php
$config['enable_hooks'] = TRUE;
Step 2 : Add in compress hook to config/hooks.php
$hook['display_override'][] = array( 'class' => '', 'function' => 'compress', 'filename' => 'compress.php', 'filepath' => 'hooks' );Step 3 : define 'display_override'
<?php if( ! defined('BASEPATH'))exit('No direct script access allowed');function compress() { ini_set("pcre.recursion_limit", "16777"); $CI =& get_instance(); $buffer = $CI->output->get_output(); $re = '%# Collapse whitespace everywhere but in blacklisted elements. (?> # Match all whitespans other than single space. [^\S ]\s* # Either one [\t\r\n\f\v] and zero or more ws, | \s{2,} # or two or more consecutive-any-whitespace. ) # Note: The remaining regex consumes no text at all... (?= # Ensure we are not in a blacklist tag. [^<]*+ # Either zero or more non-"<" {normal*} (?: # Begin {(special normal*)*} construct < # or a < starting a non-blacklist tag. (?!/?(?:textarea|pre|script)\b) [^<]*+ # more non-"<" {normal*} )*+ # Finish "unrolling-the-loop" (?: # Begin alternation group. < # Either a blacklist start tag. (?>textarea|pre|script)\b | \z # or end of file. ) # End alternation group. ) # If we made it here, we are not in a blacklist tag. %Six'; $new_buffer = preg_replace($re, " ", $buffer); // We are going to check if processing has working if ($new_buffer === null) { $new_buffer = $buffer; } $CI->output->set_output($new_buffer); $CI->output->_display(); } /* Location: ./system/application/hooks/compress.php */
Reference By : Jérôme Jaglale
ENJOY : )By :- RAJA MAHIYARIYA MAHER(tHuNdEr^fR0G)
Thursday, 14 July 2016
Top 3 useful tricks of CodeIgniter
Hi all of you, today i'll share you some codeigniter top tricks.
1 there is an optional perameter in $this->uri->segment
when you see http://website.com/controller/method/perameter vs http://website.com/controller/method/ in action ? that time we use that type of code.....
$variable = $this->uri->segment(3)
there are an optional second one peraemeter that permits set your default value
$variable = $this->uri->segment(3,'SecondPerameter')
2 Codeigniter View can return as data with a third perameter
$variable = $this->load->view('viewpage',$data,TRUE);
$PDF = build_pdf($page);
3 Every Library can have a configuration file
I can try to keep my library configuration option out of my controllers where possible. suddenly codeigniter lets us seamlessly move that information into application/config widout missing any steps,you need to name your configuration file the same as the library and you are set that,this is the simple example for email library.here is the application/config/email,php file include in every bit of code which one is distibutes
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
$config['protocol'] = '****';
$config['smtp_host'] = '*****************';
$config['smtp_user'] = 'username';
$config['smtp_pass'] = 'password';
$config['smtp_port'] = '80';
?>
if the third pareameter allows you to suppress errors in the event that config file done not exist
$this->config->load('blog_settings', FALSE, TRUE);
ENJOY : )
By :- RAJA MAHIYARIYA MAHER(tHuNdEr^fR0G)
Tuesday, 5 July 2016
Disable text selection in web page using CSS
Hi there, today i m share code for disable text selection using css, there are not require jquery or javascript.you can disable text selection in whole page or user defined div,
this code will disable text selection for whole page.im using .body for disable text select for whole page
.body
{
-webkit-touch-callout: none; /* For IOS Safari */
-webkit-user-select: none; /* For Safari/Opera/Chrome */
-khtml-user-select: none; /* For Konqueror */
-moz-user-select: none; /* For Firefox */
-ms-user-select: none; /* For Internet Explorer/Edge */ user
-select: none; /* For non-prefixed version */
}
this code will disable text selection for div.
.div
{
-webkit-touch-callout: none; /* For IOS Safari */
-webkit-user-select: none; /* For Safari/Opera/Chrome */
-khtml-user-select: none; /* For Konqueror */
-moz-user-select: none; /* For Firefox */
-ms-user-select: none; /* For Internet Explorer/Edge */ user
-select: none; /* For non-prefixed version */
}
this code will disable text selection for whole page.im using .body for disable text select for whole page
.body
{
-webkit-touch-callout: none; /* For IOS Safari */
-webkit-user-select: none; /* For Safari/Opera/Chrome */
-khtml-user-select: none; /* For Konqueror */
-moz-user-select: none; /* For Firefox */
-ms-user-select: none; /* For Internet Explorer/Edge */ user
-select: none; /* For non-prefixed version */
}
this code will disable text selection for div.
.div
{
-webkit-touch-callout: none; /* For IOS Safari */
-webkit-user-select: none; /* For Safari/Opera/Chrome */
-khtml-user-select: none; /* For Konqueror */
-moz-user-select: none; /* For Firefox */
-ms-user-select: none; /* For Internet Explorer/Edge */ user
-select: none; /* For non-prefixed version */
}
Tuesday, 21 June 2016
Get IP, OS name and Browser Name using JQuery - JavaScript
- Here i create one html file, in the click event of button, i called some simple javascript and jquery code for get IP address of current system, operating system name and browser name of system in pop up,
- you can use this code in your login page of web-site, and get all details of users that login in your created system,you can also store these details and login time also and manage users by perfect security,
- just copy and paste this code in your html page and hit the run,
Here is the code :
<html>
<head>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script type="text/javascript" src="http://l2.io/ip.js?var=myip"></script>
<!-------- this link is for get ip in myip name variable --------->
</head>
<body>
<div class="row">
<div class="col-md-4 col-md-offset-5" style="margin-top: 25%">
<input type="button" name="LoginButton" id="LoginButton" class="btn btn-primary" data-toggle="modal" data-target="#myModal" value="Click Me!" style="width: 150px;">
</div>
</div>
<div class="modal fade " id="myModal" role="dialog">
<div class="modal-dialog modal-md">
<div class="modal-content">
<div class="modal-header" align="center">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Get OS Name,Browser Name AND IP</h4>
</div>
<div class="modal-body">
<span>Your Operation System Name : </span><b><span id="OSsystem"></span></b><br/>
<span>Your Browser Name : </span><b><span id="BrowserName"></span></b><br/>
<span>Your IP Address : </span><b><span id="IPaddress"></span></b><br/>
</div>
<div class="modal-footer" align="center">
<a href="http://www.promptwebsolution.com">www.promptwebsolution.com</a>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
$("#LoginButton").click(function () {
//------------------------------------ To Get Browser Name------------------------>
if (navigator.userAgent.search("MSIE") >= 0) {
var browser = "InternetExplorer";
} else if (navigator.userAgent.search("Chrome") >= 0) {
var browser = "Chrome";
} else if (navigator.userAgent.search("Firefox") >= 0) {
var browser = "Firefox";
} else if (navigator.userAgent.search("Safari") >= 0 && navigator.userAgent.search("Chrome") < 0) {
var browser = "Safari";
} else if (navigator.userAgent.search("Opera") >= 0) {
var browser = "Opera";
}
//------------------------------------- To get OS ------------------------------------>
var OSName = "Unknown OS";
if (navigator.appVersion.indexOf("Win") != -1)
OSName = "Windows";
if (navigator.appVersion.indexOf("Mac") != -1)
OSName = "MacOS";
if (navigator.appVersion.indexOf("X11") != -1)
OSName = "UNIX";
if (navigator.appVersion.indexOf("Linux") != -1)
OSName = "Linux";
var ip = myip;
$("#OSsystem").html(OSName);
$("#BrowserName").html(browser);
$("#IPaddress").html(ip);
});
</script>
</html>
ENJOY : )
Code By :- RAJA MAHIYARIYA MAHER(tHuNdEr^fR0G)
Wednesday, 15 June 2016
Display data with AngularJS include Pagination and search
1. index.php
- this is the simple .php file and you need to copy paste below code in it.
- mention the comment in index.php for display table field name.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Prompt Websolution</title>
<script src="http://code.angularjs.org/1.0.0rc9/angular-1.0.0rc9.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<script data-require="ui-bootstrap@*" data-semver="0.12.1" src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.12.1.min.js"></script>
</head>
<body>
<div ng-app="myApp">
<div ng-controller="GridContrl">
<br /><br /><br />
<div class="col-md-6">
<div>{{TotalRecord}}</div>
<div class="input-group">
<input type="text" name="txtSearch" class="form-control" ng-model="txtSearch" placeholder="Search anything..." ng-change="search()" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-search"></span>
</span>
</div>
<table class="table table-striped pagination-sm">
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="data in filteredData">
<td ng-bind="$index + 1"></td><!--- index wise id --->
<td ng-bind="data.firstname"></td><!--- write your table field name wichone you want to display --->
<td ng-bind="data.lastname"></td>
</tr>
</tbody>
</table>
<pagination ng-model="currentPage" total-items="TotalRecord" max-size="maxSize" boundary-links="true" items-per-page="numPerPage" ng-disabled="ngDisabled">
</pagination>
</div>
</div>
</div>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="../Scripts/Grid/mygetdatascript.js"></script>
</body>
</html>
2.1 - if you use CI then put url of controllername and function name like:
-> $http.get("/controllername/functionname?searchText=" + txtSearch + "&Begin=" + begin),
2.2 - if you use simple core php then put the php file name like :
-> $http.get("PHPfilename.php?searchText=" + txtSearch + "&Begin=" + begin),
var app = angular.module("myApp", ['ui.bootstrap']);
app.controller("GridContrl", function ($scope, $http) {
$scope.filteredData = [], $scope.currentPage = 1, $scope.numPerPage = 25, $scope.maxSize = 5,$scope.ngDisabled = true;
var firsttime = true;
$scope.zbPagination = function () {
$scope.$watch('currentPage + numPerPage', function () {
var begin = (($scope.currentPage - 1) * $scope.numPerPage)
, end = begin + $scope.numPerPage;
console.log("Begin:: " + begin + " End:: " + end);
if (firsttime == false) {
$scope.getData($scope.txtSearch, begin, false);
}
firsttime = false;
});};
$scope.getData = function (txtSearch, begin, callPaging) {
$http.get("/controller/function?searchText=" + txtSearch + "&Begin=" + begin).then(function (response) {
$scope.TotalRecord = response.data.TotalRecord;
$scope.filteredData = response.data.returnData;
if (callPaging) {
$scope.zbPagination();
}
});
$scope.search = function () {
$scope.currentPage = 1;
$scope.getData($scope.txtSearch, 0, false);
};};
$scope.txtSearch = "";
$scope.getData($scope.txtSearch, 0,true);
});
here, i put the third php file for get idea, make sure that you have to get data in json format like :
3. PHPindex.php
$Query = $this->db->query(" select * from tablename ");
$data = $Query->result();
$this->response($data);
output like :
{"data":[
{"firstName":"Raj", "lastName":"Maher"},
{"firstName":"Ravi", "lastName":"Patel"},
{"firstName":"Jems", "lastName":"Patel"}
]}
Friday, 22 April 2016
Using google API to get Auto Complete address
Here is the simple way to get full address from using the google API if you want to use your private API and copy the key and paste in <script> tag that placed at bottom of page.
(<script src="https://maps.googleapis.com/maps/api/js?key=[YOUR GOOGLE API KEY]&libraries=places&callback=initAutocomplete" async defer></script>)
STEP 1 (optional): click on this url for generate the new google api key,
https://developers.google.com/maps/documentation/javascript/get-api-key
STEP 2 : write this code in your .html file and run !. simple :)
<!DOCTYPE html>
<html>
<head>
<title>Place Autocomplete - Prompt WebSolution</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
</head>
<body>
<div style="width:80%;margin:0 auto; padding-top:10%">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h3>
Auto Complete address form google api.
</h3>
</div>
<div class="col-md-5 col-md-offset-3">
<input id="autocomplete" placeholder="Enter your address" onFocus="geolocate()" type="text" class="form-control" >
</div>
<div class="col-md-5 col-md-offset-3">
<input id="street_number" disabled="true" placeholder="Residential Address" type="text" class="form-control">
</div>
<div class="col-md-3 col-md-offset-3">
<input id="administrative_area_level_1" disabled="true" type="text" placeholder="State" class="form-control">
</div>
<div class="col-md-2">
<input id="postal_code" disabled="true" type="text" placeholder="Pin Code" class="form-control">
</div>
<div class="col-md-5 col-md-offset-3">
<input id="route" disabled="true" type="text" placeholder="Road Area" class="form-control">
</div>
<div class="col-md-3 col-md-offset-3">
<input id="country" disabled="true" type="text" placeholder="Road Area" class="form-control">
</div>
<div class="col-md-2">
<input id="locality" disabled="true" placeholder="City" type="text" class="form-control">
</div>
</div>
</div>
<script>
var placeSearch, autocomplete;
var componentForm = {
street_number: 'short_name',
route: 'long_name',
locality: 'long_name',
administrative_area_level_1: 'short_name',
country: 'long_name',
postal_code: 'short_name'
};
function initAutocomplete() {
autocomplete = new google.maps.places.Autocomplete(
/** @type {!HTMLInputElement} */
(document.getElementById('autocomplete')),
{types: ['geocode']});
autocomplete.addListener('place_changed', fillInAddress);
}
function fillInAddress() {
var place = autocomplete.getPlace();
for (var component in componentForm) {
document.getElementById(component).value = '';
document.getElementById(component).disabled = false;
}
for (var i = 0; i < place.address_components.length; i++) {
var addressType = place.address_components[i].types[0];
if (componentForm[addressType]) {
var val = place.address_components[i][componentForm[addressType]];
document.getElementById(addressType).value = val;
}
}
}
function geolocate() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
var geolocation = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
var circle = new google.maps.Circle({
center: geolocation,
radius: position.coords.accuracy
});
autocomplete.setBounds(circle.getBounds());
});
}
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB6CcO8XlwhhkAUO8AN8nDwVMSRHOdThGc&libraries=places&callback=initAutocomplete" async defer></script>
</body>
</html>
Friday, 1 April 2016
Redirect non-www to www using .htaccess
Lots of people wants to redirect their web sites from non-www domain to www but can’t find the right way. So Don't need to worry, here is the solution to do that using .htaccess file.
Non-www to www redirect
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
#Example :(http://yourswebsite.com to http://www.yourwebsite.com)
</IfModule>
www to non-www redirect
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$[NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
#Example :(http://www.yourswebsite.com to http://yourwebsite.com)
</IfModule>
Enjoy ! :)
Prompt Web Solution. Powered by Blogger.