Special Offer - Get $90 Discount and Host Your Dream Web Site @ Dreamhost for 1 Year Click Here. Promo Code SLJ345
Back To Top
WordPress Web Application Development
Develop Powerfull Web Applications Using Cutting Edge WordPress Development Techniques

URL Handling Isssue In Codeigniter Facebook Application Development

on 2011/11/14 4:25 AM stored in: Uncategorized and tagged:

URL Handling Issue in Codeigniter Facebook App Development


Recently my friends were working on a Facebook Application using codeigniter php framework and they had some issues in handling facebook urls with codeigniter. Cogeigniter was configured to handle URL’s by setting uri_protocol paremeter to ‘AUTO‘ in the config file, which is the default value. In facebook applications , our application loads inside an iframe. When facebook changes its application URL, our application also got the facebook query string. Take a look at the following code.

 

Actual Facebook URL – http://apps.facebook.com/innovativephp/?ref=bookmarks

 

URL Received for our application – https://innovativephp.com/Facebook_APP/?ref=bookmarks

 

Since the query strings are set to false in default codeigniter configuration, the application url will redirect to the 404 page. So every time fb provides a query string in the url, our application showed the 404 page. You can avoid this issue by using one of 2 methods given below.

Resolving URL Issues using URI Protocol and Query Strings



We were able to fix this issue by changing the configuration values of uri_protocol and enable_query_strings parameters. Set the configuration file as following code.

$config['uri_protocol'] = "REQUEST_URI";
$config['enable_query_strings'] = TRUE;

Above code will enable query strings in codeigniter URL’s and use $_SERVER['REQUEST_URI'] for URL manipulation. Although this solved the 404 page displaying issue, we had another problem in displaying uploaded images. After the new configurations all the uploaded images names got x and y values in their image names dynamically. So we had to move to the solution given below. If you are using this method make sure to check all functionality of your system after using this method.

Resolving URL Issues using Modified Request URI



Since the above method had some issues in loading images I used this method to solve our problem. This is not a best practice or recommended method. Since we don’t use query strings in our application we changed the $_SERVER['REQUEST_URI'] for request url’s which contain query strings from facebook app. Use the method at your own risk and feel free to comment on another solution or security risks in this solution. Code needed for this method is shown below.

$config['uri_protocol'] = "REQUEST_URI";
$config['enable_query_strings'] = FALSE;

Insert the following code to top of your index.php file located at root folder of your application.

$url_parts = explode('?',$_SERVER['REQUEST_URI']);
$_SERVER['REQUEST_URI'] = $url_parts[0];

The query string part will be removed in this method. Make sure you don’t have ‘?’ mark in your own application url’s if you are going to use this method.

2 Responses to “URL Handling Isssue In Codeigniter Facebook Application Development”

  1. Samuel Godkin Says:

    I like the design of your website! It looks really nice.

  2. Wordpress Says:

    After research some of the blogs in your web site now, and I really like your way associated with running a blog. I bookmarked this to my save web site list and will be examining right back quickly. Could you take a look at my web site as well and let me know what you believe.

Leave a Reply

Follow Us On Facebook