How to get query string values in JavaScript

Hi, Getting query string value in Php is easy you can use global variable like $_GET, $_POST, $_REQUEST. But in case of JavaScript. How you can get it. Here is a simple method you can use to get the value of a query string with JavaScript:

function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
}


Use

// query string like : http://www.xyz.com/?location=lorem&city=&ipsum
  var location = getParameterByName('location'); // "lorem"

What is difference between SOAP and REST web services ?

There are many differences between SOAP and RESTful web services.

SOAP REST
SOAP is a protocol. REST is an architectural style.
SOAP stands for Simple Object Access Protocol. REST stands for Representational State Transfer.
SOAP can’t use REST because it is a protocol. REST can use SOAP web services because it is a concept and can use any protocol like HTTP, SOAP.
JAX-WS (Java API for XML Web Services) is the java API for SOAP web services. JAX-RS(Java API for RESTful Web Services) is the java API for RESTful web services.
SOAP defines standards to be strictly followed. REST does not define too much standards like SOAP.
SOAP permits XML data format only. REST permits different data format such as Plain text, HTML, XML, JSON etc.
SOAP defines its own security. RESTful web services inherits security measures from the underlying transport.
SOAP requires more bandwidth and resource than REST. REST requires less bandwidth and resource than SOAP.
SOAP uses services interfaces to expose the business logic. REST uses URI to expose business logic.
SOAP is slower than REST. REST is much more lightweight and faster.
SOAP is less preferred than REST. REST more preferred than SOAP.

How to increase maximum upload and PHP Memory limit in wordpress

WordPress has a modest limit for uploading images, videos, and other files. It is a similar story for your PHP memory limit. PHP memory limit helps you run plugins and scripts. If you run a website full of content sometime this could be a big problem when php limits exhausted. You may receive “Fatal error: Allowed memory size of 12345678 bytes exhausted” error.

In this article, we will show you how to increase the maximum file upload size in wordPress and increase php memory limit.

Theme Functions File:

There are cases where we have seen that just by adding the following code in the theme function file, you can increase the upload size in wordpress:

@ini_set( 'upload_max_size' , '64M' );
@ini_set( 'post_max_size', '64M');
@ini_set( 'max_execution_time', '300' );
@ini_set( 'WP_MEMORY_LIMIT', '96M' );

PHP.ini File:
In case of shared host you will not see php.ini file. Create php.ini file and add following code. Upload it in the root folder of the website

upload_max_filesize = 100M
post_max_size = 200M
memory_limit = 300M
file_uploads = On
max_execution_time = 180

htaccess File:
You have another option for increasing uploading size and increasing memory limit through htaccess file. Add following code in your htaccess file and upload root folder of the website.

php_value upload_max_filesize 64M
php_value post_max_size 200M
php_value memory_limit 300M
php_value max_execution_time 180
php_value max_input_time 180

wp-config.php File:
Try to editing wp-config file of the wordpress add the following to the very top of the file and save the file.

define( 'upload_max_size' , '64M' );
define( 'post_max_size', '64M');
define( 'max_execution_time', '300' );
define( 'WP_MEMORY_LIMIT', '96M' );

Url Encoder/decoder

Some time as a developer you need to encode or decode url for your purpose.

See example of encoded url:

https%3A%2F%2Fwww.google.co.in%2F%3Fgfe_rd%3Dcr%26ei%3DvUsXV572BuXI8Afb-Iv4BA%26gws_rd%3Dssl

Now you want to check what is the argument in above url. Now you need to decode it. click on below link. This is a online tool for encoding or decoding any type of url.

Click here

Paste encoded url in textbox and click on decode button. It will replace decoded url in text area.

1

See the example of decoded url

https://www.google.co.in/?gfe_rd=cr&ei=vUsXV572BuXI8Afb-Iv4BA&gws_rd=ssl

You can encode or decode any type of url here.

Prevent script injection

For protect your WordPress blog from script injection, and unwanted code of _REQUEST and /or GLOBALS. I found this code on wprecipes. Simple copy and paste the code below to your .htaccess in the root which helps is script injection.

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|[|%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|[|%[0-9A-Z]{0,2})
RewriteRule ^(.*)$ index.php [F,L]

Blocking Search Engine Spiders from Indexing the Admin Section

Search engine spiders crawl over your entire WordPress site and index every content. For stop hacking sensitive information We can disallow search engines to index the admin section which contains all the sensitive information. The easiest way to prevent the crawlers from indexing the admin directory, is to create a robots.txt file in your root directory. Then place the following code in the file:

#
User-agent: *
Disallow: /cgi-bin
Disallow: /wp-admin
Disallow: /wp-includes
Disallow: /wp-content/plugins/
Disallow: /wp-content/cache/
Disallow: /wp-content/themes/
Disallow: */trackback/
Disallow: */feed/
Disallow: /*/feed/rss/$
Disallow: /category/*

Not So in wordpress site. We can disallow crawler for any type of project. Simply write “Disallow: / directoryname” in robot.txt and upload the file in root of the project.

Preventing SQL Injection:

SQL injection is one of the most common vulnerabilities in applications on the web today. This article will show you how to prevent SQL injection on your website using Prepared Statements in PHP.

You can handle all escape characters smartly in scripting languages like PERL and PHP. The MySQL extension for PHP provides the function mysql_real_escape_string() to escape input characters that are special to MySQL.

if (get_magic_quotes_gpc())
{
$name = stripslashes($name);
}
$name = mysql_real_escape_string($name);
mysql_query("SELECT * FROM users WHERE name='{$name}'");

The LIKE Quandary:

To address the LIKE quandary, a custom escaping mechanism must convert user-supplied % and _ characters to literals. Use addcslashes(), a function that let's you specify a character range to escape.

$sub = addcslashes(mysql_real_escape_string("%something_"), "%_");
// $sub == %something_
mysql_query("SELECT * FROM messages WHERE subject LIKE '{$sub}%'");

SQL Injection:


If you take user input through a webpage and insert it into a MySQL database, there's a chance that you have left yourself wide open for a security issue known as SQL Injection. This lesson will teach you how to help prevent this from happening and help you secure your scripts and MySQL statements.

Injection usually occurs when you ask a user for input, like their name and instead of a name they give you a MySQL statement that you will unknowingly run on your database.

Never trust user provided data, process this data only after validation; as a rule, this is done by pattern matching. In the example below, the username is restricted to alphanumerical chars plus underscore and to a length between 8 and 20 chars - modify these rules as needed.

f (preg_match("/^w{8,20}$/", $_GET['username'], $matches))
{
$result = mysql_query("SELECT * FROM users
WHERE username=$matches[0]");
}
else
{
echo "username not accepted";
}

To demonstrate the problem, consider this excerpt:

// supposed input
$name = "Qadir'; DELETE FROM users;";
mysql_query("SELECT * FROM users WHERE name='{$name}'");

The function call is supposed to retrieve a record from the users table, where the name column matches the name specified by the user. Under normal circumstances, $name would only contain alphanumeric characters and perhaps spaces, such as the string ilia. But here, by appending an entirely new query to $name, the call to the database turns into disaster: the injected DELETE query removes all records from users.

Fortunately, if you use MySQL, the mysql_query() function does not permit query stacking or executing multiple queries in a single function call. If you try to stack queries, the call fails.

However, other PHP database extensions, such as SQLite and PostgreSQL, happily perform stacked queries, executing all of the queries provided in one string and creating a serious security problem.

Create Social Sharing Links in less than 5 minute

Create Facebook share links, Twitter “tweet this” links, Google Plus share links, LinkedIn share links, Pinterest “pin this” links and email “mailto” links that will work anywhere — even inside emails!

Facebook Share Link

URL Only

https://www.facebook.com/sharer/sharer.php?u=http://linkloops.in

HTML Link

<a href="https://www.facebook.com/sharer/sharer.php?u=http://linkloops.in">Share on Facebook</a>

Twitter Share Link

URL Only

https://twitter.com/home?status=http://linkloops.in

HTML Link

<a href="https://twitter.com/home?status=http://linkloops.in">Share on Twitter</a>

 

Google Plus Share Link

URL Only

https://plus.google.com/share?url=http://linkloops.in

HTML Link

<a href="https://plus.google.com/share?url=http://linkloops.in">Share on Google+</a>

 

LinkedIn Share Link

URL Only

https://www.linkedin.com/shareArticle?mini=true&url=http://linkloops.in&title=&summary=&source=

HTML Link

<a href="https://www.linkedin.com/shareArticle?mini=true&url=http://linkloops.in&title=&summary=&source=">Share on LinkedIn</a>

 

Pinterest Share Link

URL Only

https://pinterest.com/pin/create/button/?url=&media=http://linkloops.in&description=

 

HTML Link

<a href="https://pinterest.com/pin/create/button/?url=&media=http://linkloops.in&description=">Pin on Pinterest</a>

 

Email

URL Only

mailto:info@linkloops.in?&cc=sknirbhay10gmail.com&subject=Share ink&body=testing%20body%20

 

HTML Link

<a href="mailto:info@linkloops.in?&cc=sknirbhay10gmail.com&subject=Share ink&body=testing%20body%20">Send Email</a>

Create image with dynamic text using php

In this post we use two functions such as watermark_text() and watermark_image() to generate text and images watermarks on images. Integrate this to your web project upload image system dynamic text and produce flyer image.

$font_path = "GeosansLight.ttf";
$font_bold = "Typo Grotesk Demo.otf";
$font_size = 20;       // in pixcels

$fly_name="Hi, I am ".$_SESSION['name'];
  $looking="Looking for";
  $accom= $_POST['accomodation']. " | " .$_POST['furnished'];
  $location_f = $_POST['location'].", ".$cityname;
  $rent_f = "Rent Rs ".$_POST['rent'];
  $tenant_type_f=$_POST['tenant_type'];

function watermark_image($oldimage_name, $new_image_name){
global $image_path;
list($owidth,$oheight) = getimagesize($oldimage_name);
$width = 200;  
$height = 300; 
$im = imagecreatetruecolor($width, $height);
$img_src = imagecreatefromjpeg($oldimage_name);
imagecopyresampled($im, $img_src, 0, 0, 0, 0, $width, $height, $owidth, $oheight);
$watermark = imagecreatefrompng($image_path);
list($w_width, $w_height) = getimagesize($image_path);        
pos_x = $width - $w_width; 
$pos_y = $height - $w_height;
imagecopy($im, $watermark, $pos_x, $pos_y, 0, 0, $w_width, $w_height);
imagejpeg($im, $new_image_name, 100);
imagedestroy($im);
return true;
}




function watermark_text($oldimage_name, $new_image_name){
global $font_path,$font_bold, $font_size, $location_f,$fly_name,$looking,
$tenant_type_f,$accom,$rent_f;
list($owidth,$oheight) = getimagesize($oldimage_name);
$width = 2300;  
$height = 300;    		
$image = imagecreatetruecolor($width, $height);
$image_src = imagecreatefromjpeg($oldimage_name);
imagecopyresampled($image, $image_src, 0, 0, 0, 0, $width, $height, $owidth, $oheight);
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
$yellow = imagecolorallocate($image, 255, 240, 125);
imagettftext($image, 18, 0, 10, 40, $white, $font_bold, $location_f);
imagettftext($image, 18, 0, 30, 90, $black, $font_path, $fly_name);
imagettftext($image, 22, 0, 50, 130,$black, $font_path, $looking);
imagettftext($image, 28, 0, 50, 175, $white, $font_bold, $tenant_type_f);
imagettftext($image, 14, 0, 50, 210, $black, $font_path, $accom);
imagettftext($image, 22, 0, 50, 250, $yellow, $font_bold, $rent_f);
imagejpeg($image, $new_image_name, 100);
imagedestroy($image);
return true;
}
$demo_image= "";

imagettftext — GD library image function used to Write text to the image using TrueType fonts.

imagecolorallocate — Allocate a color for an image.It takes four arguments, Image and RGB color format.

Image formation

$oldimg = "images/flyer_rent.jpg";
$new_name = "uploads/images/flyer_rent_".$_REQUEST[busiid].".jpg";
if(watermark_text($oldimg, $new_name))
$demo_image = $new_name;
echo <img src="'.$demo_image.'" />;

Out Put
flyer_rent_16