Saturday, May 17, 2014

Restrict image access from browser using HTACCESS



 When we want to restrict the image access from the browser other than the page, add the below code in htaccess file to apply.


RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost [NC] 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost.*$ [NC] 
RewriteRule \.(gif|jpg|png)$ - [F]

localhost need to be replaced by the domain name where the application is hosted. 

NOTE: Above code works in Apache (LINUX) not in windows

Monday, April 28, 2014

Redirect to maintenance page using HTACCESS



 Redirecting the whole site to maintenance page using HTACCESS

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^111\.11\.1\.11
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ http://www.domainname.com/maintenance.html [R=307,L]


Rewrite condition mentioned is to stop the redirection for that particular domain.

RewriteCond %{REMOTE_ADDR} !^111\.11\.1\.11

"maintenance.html" is the page where you want to redirect the website.

Sunday, December 1, 2013

Value of CKeditor using Javascript


To get the value of the CKeditor content using Javascript or jQuery. We need to use the below syntax.

CKEDITOR.instances['article_long_desc'].getData().length => It provides the length of the content in the editor

CKEDITOR.instances['article_long_desc'].getData() => It retrieves the value of the Textarea


Where "article_long_desc" is the textarea name


Monday, November 18, 2013

Random values from an Array using php

Below is the function to pick random values from an existing array

function array_pick_random($arr, $number = 1) {
    shuffle($arr);
   
    $r = array();
    for ($i = 0; $i < $number; $i++) {
        $r[] = $arr[$i];
    }
    return $number == 1 ? $r[0] : $r;
}

In the above function '$arr' is the Array which we want to get the random values.

'$number' is the number of array elements need to return.

Function returns an array if '$number' contains more than 1.