URL Handling Issue in Codeigniter Facebook App Development
Actual Facebook URL – http://apps.facebook.com/innovativephp/?ref=bookmarks
URL Received for our application – http://www.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;
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.