Archive for rajamm

Codeigniter .htaccess for godaddy and other servers

Godaddy.com Codeigniter Installation / Configuration:

Having just struggled with this issue myself, this seems to be the shortest path to proper performance on Godaddy. This is entirely based on other people’s posts but, I didn’t really see this all in one place so I thought I do just that.

Without Htaccess: (Change in the config.php)

$config['index_page'] = "index.php?";
$config['uri_protocol'] = "QUERY_STRING";

So, Now You should now be able to access everything as such:(without htaccess)

http://yourdomain.com/index.php?controller/action/etc

Codeigniter with htaccess:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?$1 [L]

You should now be able to access everything as such:

http://yourdomain.com/controller/action/etc

For other servers:(With htaccess)

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1

You can see the difference now that i have colored with red.

Hope this will help some one.

Instagram curl -F to request an access_token

I have been working with the Instagram API for my client project, So below is the code snippet to get userid (if user logged with instagram).
I got the reference code from here (http://instagram.com/developer/authentication/) and the below one is i have tried with the php language.

Info about Curl -F -> curl is a linux utility that simulates web requests. Issuing a curl -F command issues a http request with form submission data.

$curl_attr = array(“client_id”=>$instagram_client_id, “client_secret”=>$instagram_client_secret, “grant_type”=>”authorization_code”, “redirect_uri”=>”Your Redirect URI”,”code”=>$insta_access_code);

$curl_output = curl_download(‘https://api.instagram.com/oauth/access_token’,$curl_attr);

function curl_download($Url,$fields){
$fields_string = “”;
if (!function_exists(‘curl_init’)){
die(‘Sorry cURL is not installed!’);
}
foreach($fields as $key=>$value) { $fields_string .= $key.’=’.$value.’&’; }
rtrim($fields_string, ‘&’);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}

I will update this post with full api soon.

Simple steps to set Master / Slave replication in MySQL Database

Why i have to do master-slave replication using MySQL?

1. One of the biggest advantages to have master-slave set up in MySQL is to be able to use master for all of the inserts, update and delete queries and slave for select queries. This will most probably speed up your application without having to diving into optimizing all the queries or buying more hardware.

2. Do backups from slave: One of the advantages people overlook is that you can use MySQL slave to do backups from. That way site is not affected at all when doing backups.

Goal: Master DB – Use db only for insert,delete and updated queries
Slave DB – Use db only for select queries

There are several Master-Slave replication available in MySQL. Below is the one of the best Master-Slave replication.

Note:

1. Below configuration is only for a single database replication.
2. Do the step 1 and step 2 in your master server and step 3 and step 4 slave servers.
3. Before doing all steps, you must create database and repective tables in your master and slave server.

Step 1: (Activate binary(bin) log in MySQL)

vi /etc/my.cnf
===============
log-bin = mysql-bin
binlog-do-db = databasename // give your database name
server-id = 1 // unique id depend upon your servers

Step 2: (Creating a new user in Master)

In mysql… login as root user. Read more

Execute php codes in your WordPress Page without Plug-ins!

Below are the simple steps to create a WordPress Page with capability to execute php code without any wordpress plug-ins!

Step1 :  Goto your theme directory and create a page  template as follows in the screen shot!

Step 2:  Save this file in your current theme directory.
Read more

Cross-domain communications with JSONP using JavaScript and jQuery!

Asynchronous JavaScript and XML (Ajax) is the key technology driving the new generation of Web sites, popularly termed as Web 2.0 sites.Ajax allows for data retrieval in the background without interfering with the display and behavior of the Web application. Data is retrieved using the XMLHttpRequest function, which is an API that lets client-side JavaScript make HTTP connections to remote servers.

This approach, however, does not allow cross-domain communication because of restrictions imposed by the browser. If you try to request data from a different domain, you will get a security error.

The same-origin policy limitations:

The same-origin policy prevents a script loaded from one domain from getting or manipulating properties of a document from another domain. That is, the domain of the requested URL must be the same as the domain of the current Web page.

How to resolve?

Technique 1:

One relatively simple way to overcome this limitation is to have the Web page request data from the Web server it originates from, and to have the Web server behave as a proxy relaying the request to the actual third-party servers. Although widely used, this technique isn’t scalable.

Technique 2:

Another way is to use frame elements to create new areas in the current Web page, and to fetch any third-party content using GET requests. After being fetched, however, the content in the frames would be subject to the same-origin policy limitations.

Technique 3 (Using JSONP):

A more promising way to overcome this limitation is to insert a dynamic script element in the Web page, one whose source is pointing to the service URL in the other domain and gets the data in the script itself. When the script loads, it executes.
It works because the same-origin policy doesn’t prevent dynamic script insertions and treats the scripts as if they were loaded from the domain that provided the Web page. But if this script tries to load a document from yet another domain, it will fail. Fortunately, you can improve this technique by adding JavaScript Object Notation (JSON) to the mix.

JSONP Using Javasript:

Your client-side code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
<head>
<title>jsonp</title>
</head>
<body>
<span></span>
<script>
//this function is the callback, it needs to be a global variable
function readResponse(response){
document.getElementsByTagName('SPAN')[0].innerHTML = response.time + ' is from  php file';
console.log(response);
}
(function(){
//note the "readResponse" at the end
var src = 'http://www.your-cross-domain.com/index.php?id=18&callback=readResponse',
script = document.createElement('SCRIPT');
script.src = src;
document.body.appendChild(script);
})();

</script>
</body>
</html>

Your server-side coding:

<?php
$array = array("time"=>time());
if($_GET['callback']){
header('Content-type: application/json');
echo $_GET['callback']."(".json_encode($array).")";
exit();
}
?>

JSONP using jQuery:

<!DOCTYPE html>
<html>
<head>
<style>img{ height: 100px; float: left; }</style>
<script src=”http://code.jquery.com/jquery-latest.js”></script>
</head>
<body>
<div id=”images”>
</div>
<script>
$.getJSON(“http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?”, {
tags: “cat”,
tagmode: “any”,
format: “json”
}, function (data) {
$.each(data.items, function (i, item) {
$(“<img/>”).attr(“src”, item.media.m).appendTo(“#images”);
if (i == 3) return false;
});
});
</script>
</body>
</html>

Need RSS feed parser for a wordpress site?

Importing and displaying external RSS feeds on your site is a great way to share your online activity with your visitors. If you are active on Flickr, Delicious, Twitter, or Tumblr, your visitors will enjoy staying current with your updates. Many social media sites provide exclusive feeds for user-generated content that may be imported and displayed on virtually any web page. In this article, you will learn three ways to import and display feed content on your WordPress-powered website — without installing yet another plugin.

  • Importing and displaying feeds with WordPress & Magpie
  • What is magpie?
    MagpieRSS is an XML-based (expat) RSS parser in PHP. WordPress uses Magpie to parse RSS and Atom feeds and display them on your website. Magpie parses feeds for two different WordPress functions.

    • wp_rss() – fetches and parses feeds for instant
    • fetch_rss() – fetches and parses feeds for advanced

    Ref Site: Readmore

    ADDING ADDITIONAL IMAGES IN THE PRODUCT DETAILS PAGES -Virtuemart tips

    If you are new to the virtue mart shopping cart software, the following steps will help you to add additional product images in Product details page.

    Assumptions:
    You are using,

    • Joomla 1.5 or Joomla 1.0.x
    • Virtue Mart 1.1.0 stable.

    Steps to add additional images in Product details page:

    1. Go  to  virtue mart  admin panel
    2. Choose “choose extended layout” <helps easy navigation>
    3. List out your products.
    4. Click on media button. A new popup will be opened.
    5. Click the new button to add additional images
    6. Choose additional image s as option, give appropriate height and width for the image
    7. Click on save button. That’s all

    I  am not sure about, it will work for lower version of virtue mart also. Please check and gimme a feed back to this post.

    The following pictures help you for easy understanding.

    ImageShack

    ImageShack

    ImageShack

    ImageShack

    ImageShack

    ImageShack

    Customizing the Read More link with WordPress

    If you have set your WordPress site to display post excerpts on the front or home page, you will want visitors to click on the title or a link to encourage them to continue reading your post or article, right? WordPress makes this technique easy, and customizable.

    Here is the steps:

    • Go to wordpress admin panel –> Design tab –> Theme Editor.
    • Select Main Index template (index.php) to edit it
    • Find the line  “<?php the_content(‘Read the rest of this entry &raquo;’); ?>”
    • And replace it with the following code.

    <?php

    $content = get_the_content($more_link_text, $stripteaser, $more_file);
    if(strlen($content)>500) // chanage 500 as per your needs
    {
    $part_msg=substr($content, 0, 500);// chanage 500 as per your needs
    echo ‘<p>’.$part_msg.’… ‘;
    ?>
    <br /><br />
    <a href=”<? comments_link(); ?>”>Read More…</a></div>
    <?php
    echo ‘</p>’;
    }
    else
    {
    echo ‘<p>’.$content.’</p></div>’;
    }

    ?>

    Where “500″ represents number of characters that you want to show.

    If you cannot able to make the above changes with the wordpress theme editor, use your ftp.

    Here is the template directory

    /public_html/blog/wp-content/themes

    or

    /www/blog/wp-content/themes

    where blog is the directory where i installed my wordpress

    Magic with htaccess file – Increase execution time, session expiry time and file upload size limit

    <IfModule mod_php5.c>
    php_value post_max_size 5M
    php_value upload_max_filesize 5M
    php_value memory_limit 300M
    php_value max_execution_time 259200
    php_value max_input_time 259200
    php_value session.gc_maxlifetime 1200
    </IfModule>

    php_value memory_limit 300M – Set higher default php_value memory_limit in .htaccess

    upload_max_filesize 5M - it increases default upload limit. The default upload limit is 2MB. the above htaccess increase increases file limit 2mb to 5 mb

    php_value max_execution_time:

    Set the number of seconds a script is allowed to run. If this is reached,
    the script returns a fatal error. The default limit is 30 seconds or, if it
    exists, the max_execution_time value defined in the configuration file. If
    seconds is set to zero, no time limit is imposed.

    php_value session.gc_maxlifetime:

    The session.gc_maxlifetime only sets the age of the session files that will be deleted when

    garbage collection runs.

    If you have a busy web site with a lot of sessions being created, garbage collection will

    run based on session.gc_probability/session.gc_divisor. Despite this being called

    “probability” I tested this and it is strictly a count. Using the default

    gc_probability/gc_divisor of 1/100, this means that garbage collection will run every 100

    new sessions (Edit: Actually this occurs within the session_start() coding and would count

    re-started sessions as well) and delete any existing session files that are older than the

    session.gc_maxlifetime. There is no file locking on the session files, so active session

    files will be deleted and things like users getting logged out will occur.

    If this is on shared hosting and the session files are all kept in the default location and

    someone else is using a smaller session.gc_maxlifetime or a more frequent

    gc_probability/gc_divisor, then any of the session files will get deleted based on the

    lowest value of gc_maxlifetime and the most frequent gc_probability/gc_divisor.

    You need to increase session.gc_maxlifetime or make session.gc_divisor larger and if this is

    on shared hosting, set session.save_path to be a location within your web space.