<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;Ak4CR3w8fip7ImA9WhRRFE4.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005</id><updated>2011-11-27T16:09:26.276-08:00</updated><category term="Google Maps" /><category term="PHP Validation" /><category term="Distance Calculator -- Google Map" /><category term="jQuery" /><category term="PHP Files" /><category term="PHP Classes" /><category term="CURL" /><category term="Javascript" /><category term="PHP Regular Expression" /><category term="PHP Tips" /><category term="PHP Video" /><category term="YouTube API" /><category term="XML" /><category term="CodeIgniter" /><category term="CSV" /><category term="Xpath" /><category term="PHP Design Patterns" /><category term="Gmail Login using curl" /><category term="PHP Database" /><category term="Ajax" /><category term="ExtJs" /><category term="PHP Strings" /><category term="Twitter API" /><category term="Yahoo calendar using curl" /><category term="PHP Comet" /><category term="PHP Date and Time" /><category term="PHP REST" /><category term="PHP Arrays" /><category term="Url Rewrite" /><category term="MySql" /><category term="ImageMagick using PHP" /><category term="cakePHP" /><category term="JSON" /><category term="Facebook" /><category term="XML using PHP" /><title>Sudhir Bastakoti's Blog for PHP, JQuery, Ajax</title><subtitle type="html" /><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://leaveurdream.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>88</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/blogspot/MJNuf" /><feedburner:info uri="blogspot/mjnuf" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;CEcESX05fCp7ImA9WhdSFkg.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005.post-8046657307317624577</id><published>2011-07-25T20:43:00.001-07:00</published><updated>2011-07-25T20:46:48.324-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-25T20:46:48.324-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="PHP Files" /><title>Caching in PHP</title><content type="html">The term Caching refers to storing of data for later usage. Commonly used data can be cached it can be accessed faster and caching in PHP can be easier task as well, if you know what you are doing. Following code snippet demonstrates &lt;strong&gt;File Caching&lt;/strong&gt; in php in which data is written to the file by caching process.&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt; class CacheFile {&lt;br /&gt;  protected $fPointer;&lt;br /&gt;  protected $fileName;&lt;br /&gt;  protected $expirationTime;&lt;br /&gt;  protected $tempFileName;&lt;br /&gt;  &lt;br /&gt;  //constructor function&lt;br /&gt;  //pass in the filename along with optional expiration&lt;br /&gt;  public function __construct($fileName, $expiration = false) {&lt;br /&gt;   $this-&gt;fileName = $fileName;&lt;br /&gt;   $this-&gt;expirationTime = $expiration;&lt;br /&gt;   $this-&gt;tempFileName = "$filename.".getmypid();&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  public function get() {&lt;br /&gt;   //check for expiration  and return contents of cache file&lt;br /&gt;   if($this-&gt;expirationTime) {&lt;br /&gt;    //get the file status&lt;br /&gt;    $status = @stat($this-&gt;fileName);&lt;br /&gt;    if($status[9]) {&lt;br /&gt;     //check the filetime&lt;br /&gt;     if(($modified + $this-&gt;expirationTime) &lt; time()) {&lt;br /&gt;      @unlink($this-&gt;fileName);&lt;br /&gt;      return false;&lt;br /&gt;     }&lt;br /&gt;    }&lt;br /&gt;   }&lt;br /&gt;   return file_get_contents($this-&gt;fileName);&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  public function put($fileBuffer) {&lt;br /&gt;   if(($this-&gt;fPointer == fopen($this-&gt;tempFileName, 'w')) == false) {&lt;br /&gt;    return false;&lt;br /&gt;   }&lt;br /&gt;   fwrite($this-&gt;fPointer, $fileBuffer);&lt;br /&gt;   fclose($this-&gt;fPointer);&lt;br /&gt;   rename($this-&gt;tempFileName, $this-&gt;fileName);&lt;br /&gt;   return true;&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  //remove the cache file&lt;br /&gt;  public function remove() {&lt;br /&gt;   @unlink($this-&gt;fileName);&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  //start the caching process&lt;br /&gt;  public function startOutputBuffer() {&lt;br /&gt;   if(($this-&gt;fPointer = fopen($this-&gt;tempFileName, 'w')) == false) {&lt;br /&gt;    return false;&lt;br /&gt;   }&lt;br /&gt;   ob_start();&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  //end the caching process&lt;br /&gt;  public function endOutputBuffer() {&lt;br /&gt;   //get the output bufer contents&lt;br /&gt;   $bufferContents = ob_get_contents();&lt;br /&gt;   ob_end_flush();&lt;br /&gt;   if(strlen($bufferContents)) {&lt;br /&gt;    fwrite($this-&gt;fPointer, $bufferContents);&lt;br /&gt;    fclose($this-&gt;fPointer);&lt;br /&gt;    rename($this-&gt;tempFileName, $this-&gt;fileName);&lt;br /&gt;    return true;&lt;br /&gt;   }&lt;br /&gt;   else {&lt;br /&gt;    fclose($this-&gt;fPointer);&lt;br /&gt;    @unlink($this-&gt;tempFileName);&lt;br /&gt;    return false;&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And the File Cache class cane be used as follows:&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt; &lt;?php&lt;br /&gt;  require_once('CacheFile.php');&lt;br /&gt;  $cacheData = CacheFile($pathToCacheFile);&lt;br /&gt;  //check if the string exists in cache&lt;br /&gt;  if($string = $cacheData-&gt;get()) {&lt;br /&gt;   var_dump($string);&lt;br /&gt;  }&lt;br /&gt;  else {&lt;br /&gt;   //start caching process&lt;br /&gt;   $cacheData-&gt;startOutputBuffer();&lt;br /&gt; ?&gt;&lt;br /&gt;   //your page data included here&lt;br /&gt; &lt;?php&lt;br /&gt;   $cacheData-&gt;endOutputBuffer();&lt;br /&gt;  }&lt;br /&gt; ?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In this way we can implement Caching in php.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2821308795243888005-8046657307317624577?l=leaveurdream.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/xY2a2vQobmNNnq-bm4Gx_SqRJQw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/xY2a2vQobmNNnq-bm4Gx_SqRJQw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/xY2a2vQobmNNnq-bm4Gx_SqRJQw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/xY2a2vQobmNNnq-bm4Gx_SqRJQw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/MJNuf/~4/ECLbg1UaRzs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/8046657307317624577/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=2821308795243888005&amp;postID=8046657307317624577" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/8046657307317624577?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/8046657307317624577?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/MJNuf/~3/ECLbg1UaRzs/caching-in-php.html" title="Caching in PHP" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://leaveurdream.blogspot.com/2011/07/caching-in-php.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEQEQHc6eyp7ImA9WhZUEkg.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005.post-3910208586541125611</id><published>2011-06-04T22:37:00.000-07:00</published><updated>2011-06-04T22:38:21.913-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-04T22:38:21.913-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="cakePHP" /><title>Override CakePHP model's find method</title><content type="html">By default CakePHP's find method of model allows us to use four types of find, viz&lt;br /&gt;"all", "first", "count" and "list", but in some cases we need to find something using&lt;br /&gt;some other type, like find all the pending blog posts of a user.&lt;br /&gt;&lt;br /&gt;In such case we can just override the cakePHP's model find method in our model to suit our needs. Lets say we have a model named Post for posts table in database. So, our overridden model would look like:&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt; class Post extends AppModel {&lt;br /&gt;  //relationships&lt;br /&gt;  var $belongsTo = array('User');&lt;br /&gt;  &lt;br /&gt;  function find($type, $queryData = array()) {&lt;br /&gt;   switch($type) {&lt;br /&gt;    case "pending":&lt;br /&gt;     //field is_published is tinyint with value 1 OR 0 for published or pending respectively&lt;br /&gt;     $pending = $this-&gt;find('all', array('conditions'=&gt;array('Post.is_published' =&gt; 0), 'contain' =&gt; array('User')));&lt;br /&gt;     return $pending;&lt;br /&gt;    break;&lt;br /&gt;    default:&lt;br /&gt;    //call the default find method with all related parameters&lt;br /&gt;    return parent::find($type, $queryData);&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;So now in function of our controller, we can use this as:&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt; //get the id of logged in user&lt;br /&gt; $userId = $this-&gt;Auth-&gt;user('id');&lt;br /&gt; $pendingPosts = $this-&gt;Post-&gt;find('pending', array('user_id' =&gt; $userId));&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And thats it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2821308795243888005-3910208586541125611?l=leaveurdream.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/A2sABn8qx5V5cZ0AT_FWzrp3KKI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/A2sABn8qx5V5cZ0AT_FWzrp3KKI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/A2sABn8qx5V5cZ0AT_FWzrp3KKI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/A2sABn8qx5V5cZ0AT_FWzrp3KKI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/MJNuf/~4/H9koWMdTm5w" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/3910208586541125611/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=2821308795243888005&amp;postID=3910208586541125611" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/3910208586541125611?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/3910208586541125611?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/MJNuf/~3/H9koWMdTm5w/override-cakephp-models-find-method.html" title="Override CakePHP model's find method" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total><feedburner:origLink>http://leaveurdream.blogspot.com/2011/06/override-cakephp-models-find-method.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0EAQnw4eSp7ImA9WhZVGEk.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005.post-2001740742869566968</id><published>2011-05-31T05:35:00.000-07:00</published><updated>2011-05-31T05:40:43.231-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-31T05:40:43.231-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Javascript" /><title>Image Browse And Upload feature in ckEditor</title><content type="html">ckEditor version 3.6 "by default", may be previous versions as well hides the file browse and upload function, but its quite easy to make them display if we know where to change it. &lt;br /&gt;Go to folder &lt;span style="font-weight:bold;"&gt;ckeditor\plugins\image\dialogs\&lt;/span&gt;, in there you will find a file &lt;span style="font-weight:bold;"&gt;image.js&lt;/span&gt;, open it in editor and search the file for &lt;span style="font-weight:bold;"&gt;id:'Upload'&lt;/span&gt;, you will see that, its set as id:'Upload',hidden:false, set it as id:'Upload',hidden:true, and refresh your page where you have added ckEditor, you will be able to see the &lt;span style="font-weight:bold;"&gt;Upload&lt;/span&gt; tab with &lt;span style="font-weight:bold;"&gt;Browse&lt;/span&gt; button in it.&lt;br /&gt;&lt;br /&gt;Thats it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2821308795243888005-2001740742869566968?l=leaveurdream.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/KZ1CrIXfi1W6VepEB5jSDsRp9pU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/KZ1CrIXfi1W6VepEB5jSDsRp9pU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/KZ1CrIXfi1W6VepEB5jSDsRp9pU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/KZ1CrIXfi1W6VepEB5jSDsRp9pU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/MJNuf/~4/12DZCJHR4YU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/2001740742869566968/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=2821308795243888005&amp;postID=2001740742869566968" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/2001740742869566968?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/2001740742869566968?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/MJNuf/~3/12DZCJHR4YU/image-browse-and-upload-feature-in.html" title="Image Browse And Upload feature in ckEditor" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>2</thr:total><feedburner:origLink>http://leaveurdream.blogspot.com/2011/05/image-browse-and-upload-feature-in.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUMARXg_cSp7ImA9WhZVEk0.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005.post-4092443074046692661</id><published>2011-05-23T20:22:00.000-07:00</published><updated>2011-05-23T20:24:04.649-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-23T20:24:04.649-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Javascript" /><title>Javascript Functions Flexibility</title><content type="html">In Javascript, everything is an object. Functions in Javascript are said to be first-class objects, that can be passed as arguments to other functions, stored as variables, created at run-time,etc.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Anonymous functions without parameters that run immediately.&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;(function() {&lt;br /&gt; var one = 1;&lt;br /&gt; var two = 2;&lt;br /&gt; alert(one+two);&lt;br /&gt;})();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In above anonymous function, the parenthesis at the end indicates that this function will be run immediately without being assigned to any variable.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Anonymous functions with parameters that run immediately.&lt;/span&gt;&lt;br /&gt;The parenthesis at the end can have some parameters as well. Such as,&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;(function(one, two) {&lt;br /&gt; alert(one+two);&lt;br /&gt;})(1, 2);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Or, if you want to assign the value to some variable then,&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;var three = (function(one, two) {&lt;br /&gt;    alert(one+two);&lt;br /&gt;})(1, 2);&lt;br /&gt;alert(three); //and output is 3&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Assign Attribute to Functions in Javascript&lt;/span&gt;&lt;br /&gt;In Javascript we can modify classes after they have been defined and objects after they have been created. Lets take an analogy, we have a car class,&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt; function Car(name, model) {&lt;br /&gt;  this.name = name;&lt;br /&gt;  this.model = model;&lt;br /&gt; }&lt;br /&gt; Car.prototype = {&lt;br /&gt;  getName: function() {&lt;br /&gt;   return this.name;&lt;br /&gt;  },&lt;br /&gt;  getModel: function() {&lt;br /&gt;   return this.model;&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt; //instantiate the class now&lt;br /&gt; var benz = new Car('Benz', 1969);&lt;br /&gt; var bmw = new Car('Bmw', 1984);&lt;br /&gt; &lt;br /&gt; //now modify the class&lt;br /&gt; Car.prototype.getPrice = function() {&lt;br /&gt;  return "Price for " + this.getName() + "is " + 20000;&lt;br /&gt; };&lt;br /&gt; &lt;br /&gt; //now modify the specific object instance&lt;br /&gt; benz.showPrice = function() {&lt;br /&gt;  alert(this.getPrice());&lt;br /&gt; };&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In above example, we added a new function getPrice() after two object instances for the class are created. And, benz object instance gets showPrice() function in addition to other functions of the class, but bmw object instance wont get the showPrice() function in this case. This feature is called Object Mutability.&lt;br /&gt;This is just few examples that tend to focus on flexibility of javascript functions.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2821308795243888005-4092443074046692661?l=leaveurdream.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/8aCFpJAehXcJfj2syv6RF4nFSZw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8aCFpJAehXcJfj2syv6RF4nFSZw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/8aCFpJAehXcJfj2syv6RF4nFSZw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8aCFpJAehXcJfj2syv6RF4nFSZw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/MJNuf/~4/lKRQgTAAFME" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/4092443074046692661/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=2821308795243888005&amp;postID=4092443074046692661" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/4092443074046692661?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/4092443074046692661?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/MJNuf/~3/lKRQgTAAFME/javascript-functions-flexibility.html" title="Javascript Functions Flexibility" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://leaveurdream.blogspot.com/2011/05/javascript-functions-flexibility.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEECSXk5fyp7ImA9WhZWEEU.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005.post-4287894887990911066</id><published>2011-05-10T21:00:00.000-07:00</published><updated>2011-05-10T21:04:28.727-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-10T21:04:28.727-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="CodeIgniter" /><category scheme="http://www.blogger.com/atom/ns#" term="PHP REST" /><title>REST client library using CodeIgniter</title><content type="html">Using REST in applications makes life easier to some extent. And using REST in codeigniter can be easier. There exist some REST libraries in codeigniter but somehow they seem to have lots of code and features which is not required in my case. I'm not degrading existing codeigniter REST libraries, they are excellent codes&lt;br /&gt;developed by experts, but i wanted a simple REST client using Codeigniter, so thought of coding my own.&lt;br /&gt;Following is the code for REST client library in codeIgniter, that suits simple needs.&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed'); &lt;br /&gt; &lt;br /&gt;class Rest_Lib {&lt;br /&gt; &lt;br /&gt; private $useCurl;&lt;br /&gt; private $userAgent = "Rest";&lt;br /&gt; &lt;br /&gt; /*&lt;br /&gt;  * constructor function&lt;br /&gt;  */&lt;br /&gt; function Rest_Lib() {&lt;br /&gt;     //check if curl function exists&lt;br /&gt;     if(function_exists('curl_init')) {&lt;br /&gt;  $this-&gt;useCurl = TRUE;   &lt;br /&gt;     }&lt;br /&gt;     else {&lt;br /&gt;  $this-&gt;useCurl = FALSE;&lt;br /&gt;     }&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; /*&lt;br /&gt;  * GET method&lt;br /&gt;  * @param string $url : this is the service url&lt;br /&gt;  * @param array $arr: this is the key value&lt;br /&gt;  * @return string : resulting response of GET method&lt;br /&gt;  */&lt;br /&gt; public function get($url, $arr) {&lt;br /&gt;     $str = '?';&lt;br /&gt;     if(is_array($arr)) {&lt;br /&gt;  foreach($arr as $key =&gt; $value) {&lt;br /&gt;   $str .= urlencode($key) . '=' . urlencode($value) . '&amp;';&lt;br /&gt;  }&lt;br /&gt;     }&lt;br /&gt;     else {&lt;br /&gt;  $str .= $arr;&lt;br /&gt;     }&lt;br /&gt;     $url .= $str;&lt;br /&gt;     if($this-&gt;useCurl) {&lt;br /&gt;  $ch = curl_init();&lt;br /&gt;  curl_setopt($ch, CURLOPT_URL, $url);&lt;br /&gt;  curl_setopt($ch, CURLOPT_HTTPGET, TRUE);&lt;br /&gt;  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);&lt;br /&gt;  $response = curl_exec($ch);&lt;br /&gt;  curl_close($ch);&lt;br /&gt;     } &lt;br /&gt;     else {&lt;br /&gt;  $options = array(&lt;br /&gt;  'http' =&gt; array(&lt;br /&gt;         'method' =&gt; 'GET',&lt;br /&gt;  'header' =&gt; 'User-Agent:' . $this-&gt;userAgent . '\r\n' &lt;br /&gt;  )&lt;br /&gt;  );&lt;br /&gt;  //create and return stream context with options&lt;br /&gt;  $streamContext = stream_context_create($options);&lt;br /&gt;  $fh = file_open($url, 'r', FALSE, $streamContext);&lt;br /&gt;  $response = fpassthru($fh);&lt;br /&gt;  fclose($fh);&lt;br /&gt;     } &lt;br /&gt;     return $response;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; /*&lt;br /&gt;  * POST method&lt;br /&gt;  * @param string: $url: service url&lt;br /&gt;  * @param string $postData: request data&lt;br /&gt;  * @return response&lt;br /&gt;  */&lt;br /&gt; public function post($url, $postData) {&lt;br /&gt;  if($this-&gt;useCurl) {&lt;br /&gt;   $curlHeaders = array(&lt;br /&gt;    'Content-Type: application/x-www-form-urlencoded'&lt;br /&gt;   );&lt;br /&gt;   $ch = curl_init();&lt;br /&gt;   curl_setopt($ch, CURLOPT_HTTPHEADER, $curlHeaders);&lt;br /&gt;   curl_setopt($ch, CURLOPT_URL, $url);&lt;br /&gt;   curl_setopt($ch, CURLOPT_POST, TRUE);&lt;br /&gt;   curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);&lt;br /&gt;   curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);&lt;br /&gt;   curl_setopt($ch, CURLOPT_USERAGENT, $this-&gt;userAgent);&lt;br /&gt;   $response = curl_exec($ch);&lt;br /&gt;   curl_close($ch);&lt;br /&gt;  }&lt;br /&gt;  else {&lt;br /&gt;   $options = array(&lt;br /&gt;    'http' =&gt; array(&lt;br /&gt;     'method' =&gt; 'POST',&lt;br /&gt;     'header' =&gt; 'User-Agent: ' . $this-&gt;userAgent . '\r\n',&lt;br /&gt;     'Content-Type: application/x-www-form-urlencoded' . '\r\n',&lt;br /&gt;     'Content-Length: ' . strlen($postData) . '\r\n',&lt;br /&gt;     'Content' =&gt; $postData&lt;br /&gt;    )&lt;br /&gt;   );&lt;br /&gt;   $streamContext = stream_context_create($options);&lt;br /&gt;   $fh = file_open($url, 'r', FALSE, $streamContext);&lt;br /&gt;   $response = fpassthru($fh);&lt;br /&gt;   fclose($fh);&lt;br /&gt;  }&lt;br /&gt;  return $response;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; /*&lt;br /&gt;  * PUT method&lt;br /&gt;  * &lt;br /&gt;  */&lt;br /&gt; public function put($url, $putData) {&lt;br /&gt;  if($this-&gt;useCurl) {&lt;br /&gt;   $fh = fopen('php://memory', 'rw');&lt;br /&gt;   fwrite($fh, $putData);&lt;br /&gt;   rewind($fh);&lt;br /&gt;   &lt;br /&gt;   $ch = curl_init();&lt;br /&gt;   curl_setopt($ch, CURLOPT_USERAGENT, $this-&gt;userAgent);&lt;br /&gt;   curl_setopt($ch, CURLOPT_INFILE, $fh);&lt;br /&gt;   curl_setopt($ch, CURLOPT_INFILESIZE, strlen($putData));&lt;br /&gt;   curl_setopt($ch, CURLOPT_TIMEOUT, 10);&lt;br /&gt;   curl_setopt($ch, CURLOPT_PUT, TRUE);&lt;br /&gt;   curl_setopt($ch, CURLOPT_URL, $url);&lt;br /&gt;   curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);&lt;br /&gt;   $response = curl_exec($ch);&lt;br /&gt;   curl_close($ch);&lt;br /&gt;   fclose($fh);&lt;br /&gt;  }&lt;br /&gt;  else {&lt;br /&gt;   $options = array(&lt;br /&gt;    'http' =&gt; array(&lt;br /&gt;     'method' =&gt; 'PUT',&lt;br /&gt;     'header' =&gt; 'User-Agent: ' . $this-&gt;userAgent . '\r\n',&lt;br /&gt;     'Content-Type: application/x-www-form-urlencoded' . '\r\n',&lt;br /&gt;     'Content-Length: ' . strlen($putData) . '\r\n',&lt;br /&gt;     'Content' =&gt; $putData &lt;br /&gt;    )&lt;br /&gt;   );&lt;br /&gt;   $context = stream_context_create();&lt;br /&gt;   $fh = file_open($url, 'r', FALSE, $context);&lt;br /&gt;   $response = fpassthru($fh);&lt;br /&gt;   fclose($fh);&lt;br /&gt;  }&lt;br /&gt;  return $response;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; /*&lt;br /&gt;  * DELETE method&lt;br /&gt;  */&lt;br /&gt; public function delete($url, $arr) {&lt;br /&gt;  $str = '?';&lt;br /&gt;  if(is_array($arr)) {&lt;br /&gt;   foreach($arr as $key =&gt; $value) {&lt;br /&gt;    $str .= urlencode($key) . '=' . urlencode($value) . '&amp;';&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;  else {&lt;br /&gt;   $str .= $arr;&lt;br /&gt;  }&lt;br /&gt;  $url .= $str;&lt;br /&gt;  if($this-&gt;useCurl) {&lt;br /&gt;   $ch = curl_init();&lt;br /&gt;   curl_setopt($ch, CURLOPT_URL, $url);&lt;br /&gt;   curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'delete');&lt;br /&gt;   curl_setopt($ch, CURLOPT_USERAGENT, $this-&gt;userAgent);&lt;br /&gt;   $response = curl_exec($ch);&lt;br /&gt;   curl_close($ch);&lt;br /&gt;  }&lt;br /&gt;  else {&lt;br /&gt;   $options = array(&lt;br /&gt;    'http' =&gt; array(&lt;br /&gt;     'method' =&gt; 'DELETE',&lt;br /&gt;     'header' =&gt; 'User-Agent: ' . $this-&gt;userAgent . '\r\n'&lt;br /&gt;    )&lt;br /&gt;   );&lt;br /&gt;   $context = stream_context_create($options);&lt;br /&gt;   $fh = file_open($url, 'r', FALSE, $context);&lt;br /&gt;   $response = fpassthru($fh);&lt;br /&gt;   fclose($fh);&lt;br /&gt;  }&lt;br /&gt;  return TRUE;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2821308795243888005-4287894887990911066?l=leaveurdream.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/oBforr4EXg5gBTfeouxc4BTUnoU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/oBforr4EXg5gBTfeouxc4BTUnoU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/oBforr4EXg5gBTfeouxc4BTUnoU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/oBforr4EXg5gBTfeouxc4BTUnoU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/MJNuf/~4/LU3ZgdTJFVI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/4287894887990911066/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=2821308795243888005&amp;postID=4287894887990911066" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/4287894887990911066?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/4287894887990911066?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/MJNuf/~3/LU3ZgdTJFVI/rest-client-library-using-codeigniter.html" title="REST client library using CodeIgniter" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>2</thr:total><feedburner:origLink>http://leaveurdream.blogspot.com/2011/05/rest-client-library-using-codeigniter.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUEDRHg4cCp7ImA9WhZXFUs.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005.post-208003849079141967</id><published>2011-05-04T20:50:00.000-07:00</published><updated>2011-05-04T20:54:35.638-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-04T20:54:35.638-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="ImageMagick using PHP" /><title>How to ImageMagick using PHP</title><content type="html">ImageMagick can be used to create and edit images dunamically and display the results online or locally at our desired URLs. It offers lots of features, such as crop, resize, rotate, flip, blur, sharpen, inserting texts, and lots more, using its syntax properly.&lt;br /&gt;And we can do all this stuffs using PHP. In order to use ImageMagick with PHP we can use PHP's function for executing external programs, which is exec and system. Other such functions also exist in PHP but the two mentioned above have the highest&lt;br /&gt;priority.&lt;br /&gt;The usage format is:&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;    echo exec(string command [, array &amp;output ]);&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In its simplest form, ImageMagick can be used as:&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;    $firstImg = "test.bmp";&lt;br /&gt;    $finalResult = "test2.png";&lt;br /&gt;    exec("path_tp_image_magick\imagemagick\convert {$firstImg} {$finalResult}");&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Basically, the above function converts test.bmp to test2.png, i.e changes the file format.&lt;br /&gt;Some of the basic stuffs that can be done using ImageMagick&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Stuff 1: How to get width and height of image using ImageMagick in php&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;    $dimensionsArr = array();&lt;br /&gt;    $inputImage = "full_path_to_input_image.jpg";&lt;br /&gt;    //get image width and height&lt;br /&gt;    exec("full_path_to_image_magick/identify -format \"%w\n\%h\" {$inputImage}", $dimensionsArr);&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In above case width and height of image are stored in $dimensionsArr array.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Stuff 2: How to Watermark an Image using ImageMagick in PHP&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;    $inputImage = "full_path_to_input_image.jpg";&lt;br /&gt;    $waterMarkText = "Watermark Me";&lt;br /&gt;    $outputImage = "full_path_to_output_image.jpg";&lt;br /&gt;    exec("full_path_to_image_magick/composite -watermark 30% -gravity northeast {$inputImage} {$waterMarkText} {$outputImage}");&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Stuff 3: Crop an image using ImageMagick in PHP&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;    $firstImg = "first.jpg";&lt;br /&gt;    $output = "cropped.jpg";&lt;br /&gt;    exec("E:\wamp\www\im\imagemagick\convert {$firstImg} -crop 120x80+160+80 {$output}");&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In above code what we did is we cropped an image "first.jpg" to set width of 120px and height of 80px and the cropping is started from 160x80 coordinate. Or a better way of cropping images can be done as:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;    $firstImg = "first.jpg";&lt;br /&gt;    $output = "cropped.jpg";&lt;br /&gt;    exec("E:\wamp\www\im\imagemagick\convert {$firstImg} -shave 120x80 {$output}");&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;What above code does is, it cuts the borders with the values we defined in width X height parameters.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Stuff 4: Rotate Image using ImageMagick in PHP&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;    $firstImg = "first.jpg";&lt;br /&gt;    $rotated = "rotated.bmp";&lt;br /&gt;    exec("E:\wamp\www\im\imagemagick\convert {$firstImg} -rotate 90 {$output}");&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Above code we used value -rotate 90 to rotate the image at 90 degrees, and saved the output in bmp&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Stuff 5: Resize an image using ImageMagick in PHP&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;    exec("E:\wamp\www\im\imagemagick\convert first.jpg -resize 10% -sample 500% first_new.png");&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The above code resizes first.jpg to 10% of its actual size with sampling at 500% and saves to "first_new.png"&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Stuff 6: Extract frames from animated image using ImageMagick in php&lt;/span&gt;&lt;br /&gt;One of the exciting feature that ImageMagick has is, we can extract the frames from an animated image file.&lt;br /&gt;For that we can write a simple one-line command as:&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;    $animatedImage ="animated.gif";&lt;br /&gt;    exec("E:\wamp\www\im\imagemagick\convert {$animatedImage} +adjoin animated_Image%02d.gif");&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The above code extracts frames from the animated image "animated.gif" and saves it as "animated_Image1.gif", "animated_Image2.gif", etc for each frame.&lt;br /&gt;&lt;br /&gt;These are just some of the features that ImageMagick offers, there's lot more to check out. Above code snippets can act as a good start prior to delving into the ImageMagick commands in detail.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2821308795243888005-208003849079141967?l=leaveurdream.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/vKDftJVR2GC-0-_lYHqL2eH2zls/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vKDftJVR2GC-0-_lYHqL2eH2zls/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/vKDftJVR2GC-0-_lYHqL2eH2zls/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vKDftJVR2GC-0-_lYHqL2eH2zls/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/MJNuf/~4/Rnr_tX1dU5c" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/208003849079141967/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=2821308795243888005&amp;postID=208003849079141967" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/208003849079141967?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/208003849079141967?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/MJNuf/~3/Rnr_tX1dU5c/how-to-imagemagick-using-php.html" title="How to ImageMagick using PHP" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://leaveurdream.blogspot.com/2011/05/how-to-imagemagick-using-php.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEMCSXg-fyp7ImA9WhZSGE0.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005.post-7667589660181527494</id><published>2011-04-02T21:44:00.000-07:00</published><updated>2011-04-02T21:54:28.657-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-04-02T21:54:28.657-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="CURL" /><category scheme="http://www.blogger.com/atom/ns#" term="PHP Tips" /><title>Login to Yahoo mobile using curl</title><content type="html">Once i had to login to yahoo mobile for some calendar events manipulation, but since yahoo does not have any api for doing such stuffs so thought of giving it a try using curl. After some tests and hit &amp; triali was able to login yo yahoo mobile&lt;br /&gt;using curl and do my necessary calendar events manipulation.&lt;br /&gt;Below is the code snippet for logging in to yahoo mobile using curl.&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;    $mCookie = "mcookie.cookie";&lt;br /&gt;    $reffer = "http://m.yahoo.com/calendar";&lt;br /&gt;    $mUrl = "http://m.yahoo.com/calendar";&lt;br /&gt;    $ch = curl_init();&lt;br /&gt;    curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false );&lt;br /&gt;    curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, 0 );&lt;br /&gt;    curl_setopt($ch, CURLOPT_URL, $mUrl);&lt;br /&gt;    curl_setopt($ch, CURLOPT_GET, 1);&lt;br /&gt;    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);&lt;br /&gt;    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);&lt;br /&gt;    curl_setopt($ch, CURLOPT_COOKIEFILE, $mCookie);&lt;br /&gt;    curl_setopt($ch, CURLOPT_COOKIEJAR, $mCookie);&lt;br /&gt;    $mRes = curl_exec($ch);&lt;br /&gt; &lt;br /&gt;    //get the hidden fields&lt;br /&gt; &lt;br /&gt;   preg_match_all ( "/id=\"LoginModel\" action=\"(.*)\"/", $mRes, $formActionArr);&lt;br /&gt;   preg_match_all ( "/name=\"_authurl\" value=\"(.*?)\"/", $mRes, $authUrlArr);&lt;br /&gt;   preg_match_all ( "/name=\"_done\" value=\"(.*?)\"/", $mRes, $doneArr);&lt;br /&gt;   preg_match_all ( "/name=\"_ts\" value=\"(.*?)\"/", $mRes, $tsArr);&lt;br /&gt;   preg_match_all ( "/name=\"_crumb\" value=\"(.*?)\"/", $mRes, $crumbArr);&lt;br /&gt;&lt;br /&gt;   $authUrl = $authUrlArr[1][0];&lt;br /&gt;   $doneUrl = $doneArr[1][0];&lt;br /&gt;   $ts = $tsArr[1][0];&lt;br /&gt;   $crumb = $crumbArr[1][0];&lt;br /&gt;   $signIn = urlencode("Sign In");&lt;br /&gt;   $username = "yahoo_username";&lt;br /&gt;   $password = "yahoo_password";&lt;br /&gt;   $loginUrl = "https://mlogin.yahoo.com/w/login/auth?.ts=".$ts."&amp;_httpHost=m.yahoo.com&amp;.intl=NP&amp;.lang=en";&lt;br /&gt;   $postFields = "_authurl=".$authUrl."&amp;_done=".$doneUrl."&amp;_sig=&amp;_src=&amp;_ts=".$ts."&amp;_crumb=".$crumb."&amp;_pc=&amp;_send_userhash=0&amp;_appdata=&amp;_partner_ts=&amp;_is_ysid=&amp;_page=secure&amp;_next=&amp;id=".$username."&amp;password=".$password."&amp;__submit=".$signIn;&lt;br /&gt; &lt;br /&gt;   //now post the hidden fields &lt;br /&gt;  curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false );&lt;br /&gt;  curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, 0 );&lt;br /&gt;  curl_setopt($ch, CURLOPT_URL, $loginUrl);&lt;br /&gt;  curl_setopt($ch, CURLOPT_POST, 1);&lt;br /&gt;  curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);&lt;br /&gt;  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);&lt;br /&gt;  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);&lt;br /&gt;  curl_setopt($ch, CURLOPT_COOKIEFILE, $mCookie);&lt;br /&gt;  curl_setopt($ch, CURLOPT_COOKIEJAR, $mCookie);&lt;br /&gt;  curl_setopt($ch, CURLOPT_REFERER, $reffer);&lt;br /&gt;  $postRes = curl_exec($ch);&lt;br /&gt;  echo $postRes;&lt;br /&gt;  //we are logged in now&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Thats it, Hope this helps someone.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2821308795243888005-7667589660181527494?l=leaveurdream.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/lWUf27aENm2WyJk-nhCxHsaQ7EQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lWUf27aENm2WyJk-nhCxHsaQ7EQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/lWUf27aENm2WyJk-nhCxHsaQ7EQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lWUf27aENm2WyJk-nhCxHsaQ7EQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/MJNuf/~4/ShciEIm1Z_8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/7667589660181527494/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=2821308795243888005&amp;postID=7667589660181527494" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/7667589660181527494?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/7667589660181527494?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/MJNuf/~3/ShciEIm1Z_8/login-to-yahoo-mobile-using-curl.html" title="Login to Yahoo mobile using curl" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total><feedburner:origLink>http://leaveurdream.blogspot.com/2011/04/login-to-yahoo-mobile-using-curl.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkMHRnY5cSp7ImA9WhZTGUg.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005.post-7953470622440044921</id><published>2011-03-24T01:08:00.001-07:00</published><updated>2011-03-24T01:13:57.829-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-24T01:13:57.829-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="ExtJs" /><title>How To Display Data in a Grid using ExtJS</title><content type="html">Grids in ExtJs are one of the most widely used components. Grids provide a better way to present your data to the end-users in an easy-to-understand manner. ExtJs Grids are user friendly, and have different customization options and events so that it can be used in your own way.&lt;br /&gt;ExtJs Grids are similar to spreadsheets containing rows and columns. So, in order to display data in grid using ExtJs we need two Ext components.&lt;br /&gt;1) A Grid Panel, for displaying data&lt;br /&gt;2) A Store, which is like database to keep track of the data.&lt;br /&gt;&lt;br /&gt;Now we write the javascript code for displaying data in grid&lt;br /&gt;&lt;pre name="code" class="js"&gt;&lt;br /&gt;//load the required extjs files and inside script tag add the following&lt;br /&gt;Ext.onReady(function() {&lt;br /&gt;    //first we need to add data store which is to be displayed in the grid&lt;br /&gt;   //so adding the data store for the grid&lt;br /&gt;var firstStore = new Ext.data.Store({&lt;br /&gt;//now add the relevant data&lt;br /&gt;data: [&lt;br /&gt; [&lt;br /&gt;  "Sudhir Bastakoti",&lt;br /&gt;  "1983-01-17",&lt;br /&gt;  "Male",&lt;br /&gt;  "sudhirbas@gmail.com",&lt;br /&gt;  "sudhir.bastakoti"&lt;br /&gt; ],&lt;br /&gt; [&lt;br /&gt;  "John Doe",&lt;br /&gt;  "1978-02=04",&lt;br /&gt;  "Male",&lt;br /&gt;  "john@doe.com",&lt;br /&gt;  "john.doe"&lt;br /&gt; ],&lt;br /&gt; [&lt;br /&gt;  "Joane Doe",&lt;br /&gt;  "1985-05-24",&lt;br /&gt;  "Female",&lt;br /&gt;  "joane@doe.com",&lt;br /&gt;  "joane.doe"&lt;br /&gt; ]&lt;br /&gt;], //end of add data&lt;br /&gt;//now add a reader; in this case we are using Array Reader of ExtJs to read the data&lt;br /&gt;    reader: new Ext.data.ArrayReader({id: 'id'}, [&lt;br /&gt; 'id',&lt;br /&gt; 'full_name',&lt;br /&gt; {name: 'birth_date', type: 'date', dateFormat: 'Y-m-d'},&lt;br /&gt; 'gender',&lt;br /&gt; 'email',&lt;br /&gt; 'skype'&lt;br /&gt;    ]  &lt;br /&gt;}); //end data store&lt;br /&gt;  &lt;br /&gt;//finally display the Grid Panel&lt;br /&gt; var firstGrid = new Ext.grid.GridPanel({&lt;br /&gt; renderTo: document.body, //grid in body; ID of a div can also be used&lt;br /&gt; frame: true, //just adds a border to Grid Panel, not compulsory though&lt;br /&gt; title: 'User Information', //as the name suggests; title of Grid&lt;br /&gt; height: 200,&lt;br /&gt; width: 250,&lt;br /&gt; store: firstStore, //name of data store that contains data and reader confs&lt;br /&gt; columns: [&lt;br /&gt;  {header: "User Name", dataIndex: 'full_name'},&lt;br /&gt;  {header: "Birth Date", dataIndex: 'birth_date', renderer:    Ext.util.Format.dateRenderer('m/d/Y')},&lt;br /&gt;  {header: "Gender", dataIndex: 'gender'},&lt;br /&gt;  {header: "User Email", dataIndex: 'email', sortable: true},&lt;br /&gt;  {header: "Skype Add", dataIndex: 'skype'},&lt;br /&gt; ] //enf of column field&lt;br /&gt;});&lt;br /&gt;});&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Add above javascript code in your html file and run in browser , you will be &lt;br /&gt;seeing a grid with data added from store.&lt;br /&gt;&lt;br /&gt;'renderer' in column field is for data formatting. In our case its used to format date to m-d-Y format. We can use some callback function instead of that. The grid has lots of built-in features which can be checked in ExtJs Manual.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2821308795243888005-7953470622440044921?l=leaveurdream.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/LRdulJW1kP-YMGfFBgigHMQQIkA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/LRdulJW1kP-YMGfFBgigHMQQIkA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/LRdulJW1kP-YMGfFBgigHMQQIkA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/LRdulJW1kP-YMGfFBgigHMQQIkA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/MJNuf/~4/pFWtlQft46Q" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/7953470622440044921/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=2821308795243888005&amp;postID=7953470622440044921" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/7953470622440044921?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/7953470622440044921?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/MJNuf/~3/pFWtlQft46Q/how-to-display-data-in-grid-using-extjs.html" title="How To Display Data in a Grid using ExtJS" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://leaveurdream.blogspot.com/2011/03/how-to-display-data-in-grid-using-extjs.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUACRnY6eip7ImA9WhZTFk0.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005.post-3599232772955173509</id><published>2011-03-19T23:48:00.000-07:00</published><updated>2011-03-19T23:49:27.812-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-19T23:49:27.812-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="PHP Tips" /><title>Secure a page using php</title><content type="html">By default php script runs on port 80 unless changed, but i had to secure a page so that it could run only on secure port i.e. 443. So what i did was used a code to force to run a page on secure port i.e. https which uses port 443, Here's what i did:&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;    $serverPort  = $_SERVER['HTTP_PORT'];&lt;br /&gt;    //check if its not secure port&lt;br /&gt;    if("443" != $serverPort) {&lt;br /&gt; header("Location: https://".$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);&lt;br /&gt; exit;&lt;br /&gt;    }&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;So, the above code ensures that the page runs under https i.e. port 443 and&lt;br /&gt;is securely displayed. Hope it helps someone.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2821308795243888005-3599232772955173509?l=leaveurdream.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/U6rvUKH3IL1B9eStQ6MTKqbyKjg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/U6rvUKH3IL1B9eStQ6MTKqbyKjg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/U6rvUKH3IL1B9eStQ6MTKqbyKjg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/U6rvUKH3IL1B9eStQ6MTKqbyKjg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/MJNuf/~4/z035DS6Dhxg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/3599232772955173509/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=2821308795243888005&amp;postID=3599232772955173509" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/3599232772955173509?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/3599232772955173509?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/MJNuf/~3/z035DS6Dhxg/secure-page-using-php.html" title="Secure a page using php" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>3</thr:total><feedburner:origLink>http://leaveurdream.blogspot.com/2011/03/secure-page-using-php.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0EARns7cSp7ImA9Wx9bGUs.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005.post-4387850761519074615</id><published>2011-02-28T22:34:00.000-08:00</published><updated>2011-02-28T22:40:47.509-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-28T22:40:47.509-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="CodeIgniter" /><category scheme="http://www.blogger.com/atom/ns#" term="PHP Tips" /><title>Working with question mark in url in codeigniter routing</title><content type="html">Once i was working with Paypal payment integration (subscriptions) with codeigniter. Got the subscription part working but i was having problem when paypal redirected to my site after a successful payment. &lt;br /&gt;&lt;br /&gt;My return url after successful payment from paypal was controller_name/get_success,&lt;br /&gt;but Paypal added some extra info in this url and made it like:&lt;br /&gt;&lt;b&gt;controller_name/get_success?auth=some_auth_code&lt;/b&gt;&lt;br /&gt;Since i had used &lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;     $config["enable_query_string"] = FALSE;&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;this caused me problem, it was showing a 404 page. I tried fixing this problem with routing like,&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;    $route["controller_name/get_success\?(:any})] = "controller_name/get_success";&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;but this didnt work at all.&lt;br /&gt;So, after some searching, i came up with a solution, and it was using &lt;a href="http://codeigniter.com/user_guide/general/hooks.html"&gt;hooks&lt;/a&gt;. Though we could use pre_controller hooks, but i opted using a pre_system hook, as:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Step 1:&lt;/b&gt;&lt;br /&gt;//Inside application/config/config.php&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;    $config['enable_hooks'] = TRUE;&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;b&gt;Step 2:&lt;/b&gt;&lt;br /&gt;//inside application/config/hooks.php&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;$hook['pre_system'] = array(&lt;br /&gt;   'function' =&gt; 'remove_the_stuff',&lt;br /&gt;   'filename' =&gt; 'remove_get.php',&lt;br /&gt;   'filepath' =&gt; 'hooks'&lt;br /&gt;        );&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;b&gt;Step 3:&lt;/b&gt;&lt;br /&gt;Created remove_get.php file inside application/hooks&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;    function remove_the_stuff() {&lt;br /&gt;       if (isset($_GET['auth'])) {&lt;br /&gt;       define('AUTH', $_GET['auth']);&lt;br /&gt;    unset($_GET);&lt;br /&gt;       } &lt;br /&gt;    }&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;b&gt;Step 4:&lt;/b&gt;&lt;br /&gt;Set up the uri_protocol in application/config/config.php&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;    $config["uri_protocol"] = "REQUEST_URI";&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And thats it, its working without any problems.Hope this is useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2821308795243888005-4387850761519074615?l=leaveurdream.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/IbvyGYPlXqiPOAGSsajM1SrhO6g/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/IbvyGYPlXqiPOAGSsajM1SrhO6g/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/IbvyGYPlXqiPOAGSsajM1SrhO6g/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/IbvyGYPlXqiPOAGSsajM1SrhO6g/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/MJNuf/~4/cAnmG3pPxF4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/4387850761519074615/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=2821308795243888005&amp;postID=4387850761519074615" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/4387850761519074615?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/4387850761519074615?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/MJNuf/~3/cAnmG3pPxF4/working-with-question-mark-in-url-in.html" title="Working with question mark in url in codeigniter routing" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total><feedburner:origLink>http://leaveurdream.blogspot.com/2011/02/working-with-question-mark-in-url-in.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUUNQ34yeSp7ImA9Wx9UGE4.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005.post-8547629315450689735</id><published>2011-02-15T22:20:00.000-08:00</published><updated>2011-02-15T22:21:32.091-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-15T22:21:32.091-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="CURL" /><category scheme="http://www.blogger.com/atom/ns#" term="PHP Tips" /><title>Login to Hyves using cURL</title><content type="html">Logging in to hyves using the API provided by them are great, but i had a different situation where i needed to login to hyves using curl. For this i googled through&lt;br /&gt;but could not get any resources. So i thought of creating it on my own.&lt;br /&gt;&lt;br /&gt;The code connects to hyves with curl. Its simple, we just need to use appropriate curl options getting hidden field name::value pairs from the hyves login page along with the form action. And we are done.&lt;br /&gt;&lt;br /&gt;So here's the code.&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;//function to get hidden field name:value pairs from html page&lt;br /&gt;function getHidden($formAsString) {&lt;br /&gt; $hidEles="";&lt;br /&gt; $doc=new DOMDocument();&lt;br /&gt; $doc-&gt;loadHTML($string_bulk);&lt;br /&gt; $xpath=new DOMXPath($doc);&lt;br /&gt; $query="//input[@type='hidden']";&lt;br /&gt; $hidData=$xpath-&gt;query($query);&lt;br /&gt; foreach($hidData as $field) {&lt;br /&gt;  //type cast the value to string&lt;br /&gt;  $name=(string) $field-&gt;getAttribute('name');&lt;br /&gt;  $value=(string) $field-&gt;getAttribute('value');&lt;br /&gt;  $hidEles[$name]=$value;&lt;br /&gt; }&lt;br /&gt; return $hidEles;&lt;br /&gt;}&lt;br /&gt;//hyves mobile page url for login&lt;br /&gt;$hyvesUrl = "http://www.hyves.nl/mini/?l1=mo";&lt;br /&gt;$ch = curl_init();&lt;br /&gt;curl_setopt($ch, CURLOPT_URL, $hyvesUrl);&lt;br /&gt;curl_setopt($ch, CURLOPT_POST, false);&lt;br /&gt;curl_setopt($ch, CURLOPT_HTTPGET ,true);&lt;br /&gt;curl_setopt($ch, CURLOPT_HEADER, false);&lt;br /&gt;curl_setopt($ch, CURLOPT_REFERER, '');&lt;br /&gt;curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);&lt;br /&gt;curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);&lt;br /&gt;$homepage = curl_exec($ch);&lt;br /&gt;&lt;br /&gt;//get the action value of the login form&lt;br /&gt;$searchStr = "/class=\"form\" action=\"(.*?)\"/"; &lt;br /&gt;preg_match($searchStr, $page, $matches);&lt;br /&gt;$frmAction = $matches[1];&lt;br /&gt; &lt;br /&gt;//get the hidden field name:value pairs from login page&lt;br /&gt;$eles=getHiddenElements($homepage);&lt;br /&gt;$eles['auth_username']="hyves-username";&lt;br /&gt;$eles['auth_password']="hyves-password";&lt;br /&gt;$eles['login']='Login';&lt;br /&gt;&lt;br /&gt;//prepare post values&lt;br /&gt;$els='';&lt;br /&gt;$flag = false;&lt;br /&gt;foreach ($eles as $name=&gt;$value) {&lt;br /&gt; if ($flag) &lt;br /&gt;  $els.='&amp;';&lt;br /&gt; $els.="{$name}=".urlencode($value);&lt;br /&gt; $flag = true;        &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//now post the login form&lt;br /&gt;$ch = curl_init();&lt;br /&gt;curl_setopt($ch, CURLOPT_URL, $form_action);&lt;br /&gt;curl_setopt($ch, CURLOPT_POSTFIELDS,$els);&lt;br /&gt;curl_setopt($ch, CURLOPT_POST, 1);&lt;br /&gt;curl_setopt($ch, CURLOPT_HEADER, 0);&lt;br /&gt;curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);&lt;br /&gt;curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);&lt;br /&gt;curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");&lt;br /&gt;curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");&lt;br /&gt;curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);&lt;br /&gt;$resLogin = curl_exec($ch);    &lt;br /&gt;echo $resLogin;&lt;br /&gt;//and you are loggedin&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;So, in this way you can login to hyves using curl, and after logging in you can do&lt;br /&gt;lots of other stuffs, like add new tips, blogs, send message, etc.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2821308795243888005-8547629315450689735?l=leaveurdream.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/79i3Y20ViuSSl9wcKk9aODsBVQo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/79i3Y20ViuSSl9wcKk9aODsBVQo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/79i3Y20ViuSSl9wcKk9aODsBVQo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/79i3Y20ViuSSl9wcKk9aODsBVQo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/MJNuf/~4/lOmzVFeOLIQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/8547629315450689735/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=2821308795243888005&amp;postID=8547629315450689735" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/8547629315450689735?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/8547629315450689735?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/MJNuf/~3/lOmzVFeOLIQ/login-to-hyves-using-curl.html" title="Login to Hyves using cURL" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://leaveurdream.blogspot.com/2011/02/login-to-hyves-using-curl.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEUDRXg9cCp7ImA9Wx9UF0g.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005.post-9026856035347629494</id><published>2011-02-14T23:41:00.001-08:00</published><updated>2011-02-14T23:51:14.668-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-14T23:51:14.668-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Xpath" /><category scheme="http://www.blogger.com/atom/ns#" term="PHP Tips" /><title>How to get all hidden elements from a form using php</title><content type="html">I always had problem getting all the hidden elements of a form when using cURL. So thought of making a function that extracts all the hidden elements from a form when passed as a string.&lt;br /&gt;Here's the function&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;  function getHidden($form) {&lt;br /&gt;     $hiddenElements="";&lt;br /&gt;     $doc=new DOMDocument();&lt;br /&gt;     $doc-&gt;loadHTML($form);&lt;br /&gt;     $xpath=new DOMXPath($doc);&lt;br /&gt;&lt;br /&gt;     //use xPATH for quering the hidden elements in a form passes as string $form&lt;br /&gt;     $qry="//input[@type='hidden']";&lt;br /&gt;     $xData=$xpath-&gt;query($qry);&lt;br /&gt;&lt;br /&gt;     //loop thru all the data&lt;br /&gt;     foreach($xData as $value) {&lt;br /&gt;         //typecast the name and values as string to avoid xml object&lt;br /&gt;         $eleName=(string) $value-&gt;getAttribute('name');&lt;br /&gt;         $eleValue=(string) $value-&gt;getAttribute('value');&lt;br /&gt;         $hiddenElements[$eleName]=$eleValue;&lt;br /&gt;     }&lt;br /&gt;     return $hiddenElements;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And thats it. The above function can be useful while doing a cURL using php to get form fields. Hope this helps someone&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2821308795243888005-9026856035347629494?l=leaveurdream.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/EDCmOaR0xs9vQ-toszEJErqYwgo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/EDCmOaR0xs9vQ-toszEJErqYwgo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/EDCmOaR0xs9vQ-toszEJErqYwgo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/EDCmOaR0xs9vQ-toszEJErqYwgo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/MJNuf/~4/6bRkBZ2r2Xw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/9026856035347629494/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=2821308795243888005&amp;postID=9026856035347629494" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/9026856035347629494?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/9026856035347629494?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/MJNuf/~3/6bRkBZ2r2Xw/how-to-get-all-hidden-elements-from.html" title="How to get all hidden elements from a form using php" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://leaveurdream.blogspot.com/2011/02/how-to-get-all-hidden-elements-from.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUAGRXwzcSp7ImA9Wx9VGE8.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005.post-7263150849009332599</id><published>2011-02-04T04:47:00.001-08:00</published><updated>2011-02-04T04:48:44.289-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-04T04:48:44.289-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Facebook" /><category scheme="http://www.blogger.com/atom/ns#" term="CURL" /><title>Facebook Share using cURL &amp; PHP</title><content type="html">I required a php script for facebook share using curl, found some but none of them worked for me. Found one script that was close to working, so i changed and added some codes in it and finally got it working. So following code snippet can be used for facebook share using curl in php.&lt;br /&gt;&lt;br /&gt;The following code uses m.facebook.com for using the share feature. It first logs in a valid facebook user, gets the page after logging in, extracts hidden field values and form action used for posting message, then finally shares the message using curl.&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt; $status = 'YOUR MESSAGE HERE';&lt;br /&gt; $login_email = 'YOUR-EMAIL-ADDRESS';&lt;br /&gt; $login_pass = 'YOUR-FACEBOOK-PASS';&lt;br /&gt; &lt;br /&gt; //curl to login to facebook&lt;br /&gt; $ch = curl_init();&lt;br /&gt; curl_setopt($ch, CURLOPT_URL, 'https://login.facebook.com/login.php?m&amp;amp;next=http%3A%2F%2Fm.facebook.com%2Fhome.php');&lt;br /&gt; curl_setopt($ch, CURLOPT_POSTFIELDS,'email='.urlencode($login_email).'&amp;pass='.urlencode($login_pass).'&amp;login=Login');&lt;br /&gt; curl_setopt($ch, CURLOPT_POST, 1);&lt;br /&gt; curl_setopt($ch, CURLOPT_HEADER, 0);&lt;br /&gt; curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);&lt;br /&gt; curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);&lt;br /&gt; curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");&lt;br /&gt; curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");&lt;br /&gt; curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);&lt;br /&gt; curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");&lt;br /&gt; curl_exec($ch);&lt;br /&gt;&lt;br /&gt; //get the page after logging in successfully&lt;br /&gt; curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/home.php');&lt;br /&gt; curl_setopt($ch, CURLOPT_POST, 0);&lt;br /&gt; curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);&lt;br /&gt; $page = curl_exec($ch);&lt;br /&gt; &lt;br /&gt; //get hidden values&lt;br /&gt; $searchStr = "/name=\"post_form_id\" value=\"(.*?)\"/";&lt;br /&gt; preg_match($searchStr, $page, $matches);&lt;br /&gt; $post_form_id = $matches[1]; &lt;br /&gt; &lt;br /&gt; $searchStr2 = "/name=\"fb_dtsg\" value=\"(.*?)\"/"; &lt;br /&gt; preg_match($searchStr2, $page, $matches1);&lt;br /&gt; $fbDtsg = $matches1[1];&lt;br /&gt; &lt;br /&gt; $searchStr3 = "/name=\"charset_test\" value=\"(.*?)\"/"; &lt;br /&gt; preg_match($searchStr3, $page, $matches2);&lt;br /&gt; $charsetTest = $matches2[1];&lt;br /&gt; &lt;br /&gt; //get the posting url&lt;br /&gt; $searchStr4 = "/id=\"composer_form\" action=\"(.*?)\"/"; &lt;br /&gt; preg_match($searchStr4, $page, $matches3);&lt;br /&gt; $frmAction = $matches3[1];&lt;br /&gt; &lt;br /&gt; //final post url&lt;br /&gt; $postStatUrl = 'http://m.facebook.com'.$frmAction;&lt;br /&gt; &lt;br /&gt; //finally post your message&lt;br /&gt; curl_setopt($ch, CURLOPT_URL, $postStatUrl);&lt;br /&gt; curl_setopt($ch, CURLOPT_POSTFIELDS,'charset_test='.$charsetTest.'&amp;fb_dtsg='.$fbDtsg.'&amp;post_form_id='.$post_form_id.'&amp;status='.$status.'&amp;update=Share');&lt;br /&gt; curl_setopt($ch, CURLOPT_POST, 1);&lt;br /&gt; curl_setopt($ch, CURLOPT_HEADER, 0);&lt;br /&gt; curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);&lt;br /&gt; curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);&lt;br /&gt; curl_exec($ch);&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And thats it. Share it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2821308795243888005-7263150849009332599?l=leaveurdream.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/BOcorh3Be3kdEsvR_UzLYC4ftyM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BOcorh3Be3kdEsvR_UzLYC4ftyM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/BOcorh3Be3kdEsvR_UzLYC4ftyM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BOcorh3Be3kdEsvR_UzLYC4ftyM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/MJNuf/~4/kTAH3lCXu3M" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/7263150849009332599/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=2821308795243888005&amp;postID=7263150849009332599" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/7263150849009332599?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/7263150849009332599?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/MJNuf/~3/kTAH3lCXu3M/facebook-share-using-curl-php.html" title="Facebook Share using cURL &amp; PHP" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://leaveurdream.blogspot.com/2011/02/facebook-share-using-curl-php.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CE4BQnk-fip7ImA9Wx9VF0Q.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005.post-6689065737971317671</id><published>2011-02-03T20:10:00.000-08:00</published><updated>2011-02-03T20:15:53.756-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-03T20:15:53.756-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="PHP Tips" /><title>Writing Distributable Code in PHP</title><content type="html">Several stuffs should be taken care of when you are working in a team,&lt;br /&gt;or writing code for public release. Those stuffs can be:&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;br /&gt;a) Code should be easily readable.&lt;br /&gt;b) Code should be extendable.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Well, that's what came to my mind for now. Debugging or extending someone else's code can be the toughest and frustrating task if the previous developer have not coded keeping above two points in mind.&lt;br /&gt;&lt;br /&gt;So, if you want to stop troubling other's and yourself of-course, then you should make hebit of writing distributable code. The terminology 'distributable code' means nothing but following a good programming practice. At first, following a programming practice may tend to be uneasy, but as you keep on working you make it a habit.&lt;br /&gt;&lt;br /&gt;Following are some of the programming practice that can be followed.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;1)Select a Coding Standard&lt;/span&gt;&lt;br /&gt;A coding standard can be:&lt;br /&gt;a) Naming conventions (for files, variables, classes, etc)&lt;br /&gt;b) Setting indentation rules&lt;br /&gt;c) Commenting well and documentation&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;2)Writing Code in OOP&lt;/span&gt;&lt;br /&gt;Start habit of Object oriented programming. Though experts say OOP tends to be costly to an application performance. But, comparitively they are cheaper then&lt;br /&gt;web developers. Object Oriented code can be easily reused and extended. Though OOP may not give performance hike but it definitely give's you the faster better code as compared to slower better code. &lt;br /&gt;&lt;br /&gt;So, write Distributable code and help yourself and others.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2821308795243888005-6689065737971317671?l=leaveurdream.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/c_XzM4UlvGrJn5FETyTn6wEV-u0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/c_XzM4UlvGrJn5FETyTn6wEV-u0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/c_XzM4UlvGrJn5FETyTn6wEV-u0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/c_XzM4UlvGrJn5FETyTn6wEV-u0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/MJNuf/~4/6i-Jj0E-CVM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/6689065737971317671/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=2821308795243888005&amp;postID=6689065737971317671" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/6689065737971317671?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/6689065737971317671?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/MJNuf/~3/6i-Jj0E-CVM/writing-distributable-code-in-php.html" title="Writing Distributable Code in PHP" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total><feedburner:origLink>http://leaveurdream.blogspot.com/2011/02/writing-distributable-code-in-php.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A08CRX87eSp7ImA9Wx9VEk0.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005.post-7726836610314349929</id><published>2011-01-28T02:07:00.000-08:00</published><updated>2011-01-28T02:17:44.101-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-01-28T02:17:44.101-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="PHP Arrays" /><title>Check value exists in multidimensional array</title><content type="html">Most of the times we are playing with arrays in php. And it can be troublesome when we have to check for value in multidimensional array. I get into such a situation every often. I used to loop through the array to check for the existence of value.&lt;br /&gt;&lt;br /&gt;So, i thought of making a function that checked for the existence of a value in a multi array. I am much happier using this function rather than looping through arrays making my time worse.&lt;br /&gt;&lt;br /&gt;Following code simplifies checking of a value in multi-array in php.&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;    //function to check if a values exists in multidimensional array&lt;br /&gt;    function in_multi($searchFor, $array) {&lt;br /&gt;        foreach($array as $key =&gt; $value) {&lt;br /&gt;            if($value == $searchFor) {&lt;br /&gt;                return true;&lt;br /&gt;            }&lt;br /&gt;            else {&lt;br /&gt;                if(is_array($value)) if(in_multi($searchFor, $value)) return true;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        return false;&lt;br /&gt;    }&lt;br /&gt;    //test array&lt;br /&gt;    $testArr = array(&lt;br /&gt;        0   =&gt;  array(&lt;br /&gt;            0 =&gt;  array(&lt;br /&gt;                "10"   =&gt; 20,&lt;br /&gt;                "20"    =&gt;  40&lt;br /&gt;            ),&lt;br /&gt;            1   =&gt;  array(&lt;br /&gt;                "a" =&gt;  555,&lt;br /&gt;                "b" =&gt; 152&lt;br /&gt;            )&lt;br /&gt;        ),&lt;br /&gt;        1   =&gt;  array(&lt;br /&gt;            0   =&gt;  999,&lt;br /&gt;            1   =&gt; 2024&lt;br /&gt;        )&lt;br /&gt;    );&lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;    $isThere = in_multi(152, $testArr);&lt;br /&gt;    if($isThere) {&lt;br /&gt;        echo "Found";&lt;br /&gt;    }&lt;br /&gt;    else {&lt;br /&gt;        echo "Not Found";&lt;br /&gt;    }&lt;br /&gt;?&gt;&lt;br /&gt;And we are done.&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2821308795243888005-7726836610314349929?l=leaveurdream.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/fjYNGZZgQR-Tsd3qt5TP-8k0TDM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/fjYNGZZgQR-Tsd3qt5TP-8k0TDM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/fjYNGZZgQR-Tsd3qt5TP-8k0TDM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/fjYNGZZgQR-Tsd3qt5TP-8k0TDM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/MJNuf/~4/xAL2eZZ3c3w" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/7726836610314349929/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=2821308795243888005&amp;postID=7726836610314349929" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/7726836610314349929?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/7726836610314349929?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/MJNuf/~3/xAL2eZZ3c3w/check-value-exists-in-multidimensional.html" title="Check value exists in multidimensional array" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total><feedburner:origLink>http://leaveurdream.blogspot.com/2011/01/check-value-exists-in-multidimensional.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEAEQXY9eSp7ImA9Wx9VEU8.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005.post-5655778970030851588</id><published>2011-01-27T03:09:00.000-08:00</published><updated>2011-01-27T03:11:40.861-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-01-27T03:11:40.861-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="PHP Tips" /><title>How to Sync php calendar events to Outlook 2007</title><content type="html">I found lots of sites that showed how to sync events from my custom calendar to&lt;br /&gt;Microsoft Outlook 2007 using PHP. But could not make any of it work my way. I&lt;br /&gt;somehow managed to make it work. Microsoft Outlook 2007 uses iCal files, i.e.&lt;br /&gt;Internet Calendar files, so with the help of some sites searched using Google&lt;br /&gt;I created an iCal file adding my customs calendar events in it.&lt;br /&gt;Here is the code snippet for the same.&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;$userTimeZoneName = "America/New_York";&lt;br /&gt;$userTimeZoneAbbr = "GMT";&lt;br /&gt;$eventSummary = "This is summary of event";&lt;br /&gt;&lt;br /&gt;$eventStartDate = date("Ymd", time());  //like 20110112&lt;br /&gt;$eventStartTime = date("His", time());  // like 163000&lt;br /&gt;$eventEndDate = "20110128";     //you can set your own end date in Ymd format&lt;br /&gt;$eventEndTime = "1223000";      //you can set your own end time in His format&lt;br /&gt;&lt;br /&gt;$eventDescription = "Some event description here";&lt;br /&gt;$eventsLocation = "Nepal, Kathmandu";&lt;br /&gt;$eventId = "20";     //this can be your event id&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$ical = "BEGIN:VCALENDAR\n";&lt;br /&gt;$ical .= "PRODID:-//Sudhir/SudhirWebCal//NONSGML v1.0//EN\n";&lt;br /&gt;$ical .= "VERSION:2.0\n";&lt;br /&gt;$ical .="CALSCALE:GREGORIAN\n";&lt;br /&gt;$ical .="METHOD:PUBLISH\n";&lt;br /&gt;$ical .="X-WR-CALNAME:SudhirCal\n";&lt;br /&gt;$ical .="X-WR-TIMEZONE:".$userTimeZoneName."\n";&lt;br /&gt;$ical .="X-WR-CALDESC:Commonfig Events\n";&lt;br /&gt;$ical .="X-PUBLISHED-TTL:PT5M\n";&lt;br /&gt;$ical .="BEGIN:VTIMEZONE\n";&lt;br /&gt;$ical .="TZID:".$userTimeZoneName."\n";&lt;br /&gt;$ical .="X-LIC-LOCATION:".$userTimeZoneName."\n";&lt;br /&gt;$ical .="BEGIN:DAYLIGHT\n";&lt;br /&gt;$ical .="TZOFFSETFROM:+0000\n";&lt;br /&gt;$ical .="TZOFFSETTO:+0100\n";&lt;br /&gt;$ical .="TZNAME:".$userTimeZoneAbbr."\n";&lt;br /&gt;$ical .="DTSTART:19700329T010000\n";&lt;br /&gt;$ical .="RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU\n";&lt;br /&gt;$ical .="END:DAYLIGHT\n";&lt;br /&gt;$ical .="BEGIN:STANDARD\n";&lt;br /&gt;$ical .="TZOFFSETFROM:+0100\n";&lt;br /&gt;$ical .="TZOFFSETTO:+0000\n";&lt;br /&gt;$ical .="TZNAME:GMT\n";&lt;br /&gt;$ical .="DTSTART:19701025T020000\n";&lt;br /&gt;$ical .="RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU\n";&lt;br /&gt;$ical .="END:STANDARD\n";&lt;br /&gt;$ical .="END:VTIMEZONE\n";&lt;br /&gt;$ical .="BEGIN:VEVENT\n";&lt;br /&gt;$ical .="SUMMARY:".$eventSummary."\n";&lt;br /&gt;$ical .="DTSTART:".$eventStartDate."T".$eventStartTime."\n";&lt;br /&gt;$ical .="DTEND:".$eventEndDate."T".$eventEndTime."\n";&lt;br /&gt;$ical .="DESCRIPTION;ENCODING=QUOTED-PRINTABLE:".str_replace("\r", "=0D=0A",$eventDescription)."\n";&lt;br /&gt;$ical .= "LOCATION:".$eventsLocation."\n";&lt;br /&gt;$ical .="UID:".sha1($eventStartDate.$eventId)."example.com\n";&lt;br /&gt;$ical .="LAST-MODIFIED:20110119T123850Z\n";&lt;br /&gt;$ical .="STATUS:PRIVATE\n";&lt;br /&gt;$ical .="END:VEVENT\n";&lt;br /&gt;$ical .="END:VCALENDAR";&lt;br /&gt;&lt;br /&gt;//the line X-PUBLISHED-TTL:PT5M; sets the outlook calendar refresh time to 5 minutes&lt;br /&gt;//so all your events will be automatically synchronized &lt;br /&gt;//to your outlook calendar every 5 minutes t&lt;br /&gt;//this can be increased to 2 hours like X-PUBLISHED-TTL:PT120M;&lt;br /&gt;&lt;br /&gt;echo $ical;&lt;br /&gt;&lt;br /&gt;//this will output the events in outlook calendar format&lt;br /&gt;?&gt;&lt;br /&gt;The above code can be added inside a function and can be accessed using a link like&lt;br /&gt;webcal://yourdomain.com/your_function_for_ical&lt;br /&gt;In this way we can create calendar files for outlook 2007 and synchronize events of&lt;br /&gt;custom PHP calendar with Microsoft Outlook 2007 calendar.&lt;br /&gt;Hope it helps someone.&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2821308795243888005-5655778970030851588?l=leaveurdream.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/hrH5PrbxoWIWGhzFq6VAM67GOVA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hrH5PrbxoWIWGhzFq6VAM67GOVA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/hrH5PrbxoWIWGhzFq6VAM67GOVA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hrH5PrbxoWIWGhzFq6VAM67GOVA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/MJNuf/~4/4Rngij2SPuo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/5655778970030851588/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=2821308795243888005&amp;postID=5655778970030851588" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/5655778970030851588?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/5655778970030851588?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/MJNuf/~3/4Rngij2SPuo/how-to-sync-php-calendar-events-to.html" title="How to Sync php calendar events to Outlook 2007" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://leaveurdream.blogspot.com/2011/01/how-to-sync-php-calendar-events-to.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkAFRnk9cSp7ImA9Wx9VEU8.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005.post-2704003442726075283</id><published>2011-01-27T02:35:00.000-08:00</published><updated>2011-01-27T02:38:37.769-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-01-27T02:38:37.769-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="jQuery" /><title>Coverflow effect with Jquery</title><content type="html">I was searching for a Apple's like coverflow effect using jQuery, and got into the following post in stackoverflow.&lt;br /&gt;Here's the link,&lt;br /&gt;http://stackoverflow.com/questions/67207/apple-cover-flow-effect-using-jquery-or-other-library&lt;br /&gt;&lt;br /&gt;Put it out with a perdurable&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2821308795243888005-2704003442726075283?l=leaveurdream.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/R2TI8nggrJ11TK6OXnS7dk_MAvw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/R2TI8nggrJ11TK6OXnS7dk_MAvw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/R2TI8nggrJ11TK6OXnS7dk_MAvw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/R2TI8nggrJ11TK6OXnS7dk_MAvw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/MJNuf/~4/VdJZjyZD1Fs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/2704003442726075283/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=2821308795243888005&amp;postID=2704003442726075283" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/2704003442726075283?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/2704003442726075283?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/MJNuf/~3/VdJZjyZD1Fs/coverflow-effect-with-jquery.html" title="Coverflow effect with Jquery" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://leaveurdream.blogspot.com/2011/01/coverflow-effect-with-jquery.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ak8HQHw5eip7ImA9Wx9QF00.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005.post-5033143842084152742</id><published>2010-12-30T03:29:00.001-08:00</published><updated>2010-12-30T03:33:51.222-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-30T03:33:51.222-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Url Rewrite" /><category scheme="http://www.blogger.com/atom/ns#" term="PHP Regular Expression" /><title>Basic url rewrite example</title><content type="html">URL that is readable looks nice. But despite efforts by developers, sometimes for instance, using a Content Management System (CMS) serve url's in the format like,&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;http://www.testthis.com/list_products?cat_name=Shirts&amp;cat_id=8&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now, this is really a bad url, and is prevelant with dynamic pages. Some of the problems of such url's are:&lt;br /&gt;1) It exposes the type of data, query string to malicious users.&lt;br /&gt;2) The characters such as question mark and ampersand can be troublesome.&lt;br /&gt;3) Such url's wont be indedxed by search engines.&lt;br /&gt;&lt;br /&gt;Solution to this is, above url can be mapped to something like this;&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;http://www.testthis.com/products/Shirts/8&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Looks much better. And in order to do such mapping, we need url rewriting.&lt;br /&gt;Apache's mod_rewrite gives us the ability to rewrite urls. Url rewrite can be&lt;br /&gt;done to redirect from old to new address, clean up dirty url's, as mentioned above.&lt;br /&gt;This makes our url's search engine friendly which means search engines can index such urls.&lt;br /&gt;&lt;br /&gt;For url rewrite, we create a file .htaccess at the root of our project, and add following line.&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;RewriteEngine On&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Basic Redirects&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Lets say we moved all of our files from an older location to a new one, now we want to redirect all the links to current location. For that we can do the following.&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;RewriteEngine On&lt;br /&gt;RewriteRule ^old\.html$ new.html&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;What the above rule does, is, it simple redirect from old.html to new.html page.&lt;br /&gt;The ^ sign indicates Start of the url to be matched. If this character is removed, then our rule would also match hold.html&lt;br /&gt;The $ sign indicates end of the string to be matched. In this case users would not know a redirect has occured from old.html to new.html&lt;br /&gt;&lt;br /&gt;But lets say you want users to know that redirect has occured, that means you want to force a redirect. In  such case you can do as,&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;RewriteEngine On&lt;br /&gt;RewriteRule ^old\.html$ new.html [R]&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Using Regular Expressions in Url Rewrite&lt;/span&gt;&lt;br /&gt;The full strength of mod_rewrite can be felt at expense of complexity. Using regular expressions for url rewrite, you can have rules for set or urls, and have redirection for all to actual pages. &lt;br /&gt;For example, &lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;http://www.testthis.com/list_book?bookId=20&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now, we can rewrite this kind or url to make it friendly, as,&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;RewriteEngine On&lt;br /&gt;RewriteRule ^book/([0-9][0-9])/$ list_book.php?bookId=$1&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;So above rule will create urls such as, &lt;span style="font-weight:bold;"&gt;http://www.testthis.com/book/8&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;But if a user types in like, http://www.testthis.com/book/8, our url rewrite rule wont work, as the slash at the end is missing, so to prevent such problems, we can do as,&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;RewriteEngine On&lt;br /&gt;RewriteRule ^book/([0-9][0-9])/$ book/$1/ [R]&lt;br /&gt;RewriteRule ^book/([0-9][0-9])/$ list_book.php?bookId=$1&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now, if a user enters something like book/12, our first rules comes in to add a slash at the end,then second&lt;br /&gt;rule comes into play.&lt;br /&gt;&lt;br /&gt;Regular expressions in url rewrite can be expanded by using modifiers, that allow you to match url with indefinite number of characters. Lets say, our url is like,&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;http://www.testthis.com/list_book?bookId=220&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Our rule wont match this, as we have checked against two digits only, so we should use modifiers in this case.&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;RewriteEngine On&lt;br /&gt;RewriteRule ^book/([0-9]+)$ book/$1/ [R]&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;+ indicates one or more of the preceeding characters or range.&lt;br /&gt;* means 0 or more preceeding characters or range&lt;br /&gt;&lt;br /&gt;So, above rule will match both book/1 and book/3000&lt;br /&gt;&lt;br /&gt;In this way we can use mod_rewrite to rewrite url. These are just an introductory examples. There's a lot more way to move ahead in url rewriting and regular expressions. I hope this basic url rewrite post can be of some help to others.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2821308795243888005-5033143842084152742?l=leaveurdream.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/pArxphYggztXrnJULZbJhNHTAtU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pArxphYggztXrnJULZbJhNHTAtU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/pArxphYggztXrnJULZbJhNHTAtU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pArxphYggztXrnJULZbJhNHTAtU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/MJNuf/~4/ekpYb1uEu2o" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/5033143842084152742/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=2821308795243888005&amp;postID=5033143842084152742" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/5033143842084152742?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/5033143842084152742?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/MJNuf/~3/ekpYb1uEu2o/basic-url-rewrite-example.html" title="Basic url rewrite example" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total><feedburner:origLink>http://leaveurdream.blogspot.com/2010/12/basic-url-rewrite-example.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkQMQX0zeip7ImA9Wx9QFU0.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005.post-5981499175425402993</id><published>2010-12-27T19:49:00.001-08:00</published><updated>2010-12-27T19:53:00.382-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-27T19:53:00.382-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="PHP Arrays" /><category scheme="http://www.blogger.com/atom/ns#" term="PHP Tips" /><title>Excel to Array in PHP</title><content type="html">Customer's data can come from various sources, and making it easier for them to get the data into our system means we are increasing our customer's count. So, our code should support importing of data from different sources.&lt;br /&gt;And one of the common sources can be Excel. So, we need to create an interface for customers so that they can load data from excel to our database.&lt;br /&gt;Instead of spending hours entering data into forms, users can simply use tools such as excel to load data from excel using php.&lt;br /&gt;In the following code, we load data from excel in php, read it and display the data back to the users. The displaying of data part can be replaced by inserting the loaded excel data to database to suit individual needs. And we are&lt;br /&gt;using XML to do this.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Let's say we have a form "form.php" as:&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt; &lt;form method="post" enctype="multipart/form-data" action="do_act.php"&gt;&lt;br /&gt;  File:&lt;br /&gt;  &lt;input type="file" name="excelFle" /&gt;&lt;br /&gt;  &lt;input type="submit" /&gt;&lt;br /&gt; &lt;/form&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now after user adds an excel file and uploads it, following code "do_act.php" is executed,&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt; $dataArr = array();&lt;br /&gt; if($_FILES["excelFle"]["tmp_name"]) {&lt;br /&gt;  $xmlDom = DOMDocument::load($_FILES["excelFle"]["tmp_name"]);&lt;br /&gt;  $allRows = $xmlDom-&gt;getElementsByTagName('Row');&lt;br /&gt;  //loop through each of the row element&lt;br /&gt;  foreach($allRows as $row) {&lt;br /&gt;   $cells = $row-&gt;getElementsByTagName('Cell');&lt;br /&gt;   $rowData = array();&lt;br /&gt;   foreach($cells as $cell) {&lt;br /&gt;    $rowData []= $cell-&gt;nodeValue;&lt;br /&gt;   }&lt;br /&gt;   $dataArr []= $rowData;&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; //so now you can check for the array of data as:&lt;br /&gt; echo "&lt;pre&gt;";&lt;br /&gt; print_r($dataArr);&lt;br /&gt; echo "&lt;/pre&gt;";&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2821308795243888005-5981499175425402993?l=leaveurdream.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/_G2MXst7-n6H8v2TzM_cIMHiZPg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_G2MXst7-n6H8v2TzM_cIMHiZPg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/_G2MXst7-n6H8v2TzM_cIMHiZPg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_G2MXst7-n6H8v2TzM_cIMHiZPg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/MJNuf/~4/_gkk4qZA6Ik" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/5981499175425402993/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=2821308795243888005&amp;postID=5981499175425402993" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/5981499175425402993?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/5981499175425402993?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/MJNuf/~3/_gkk4qZA6Ik/excel-to-array-in-php_27.html" title="Excel to Array in PHP" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://leaveurdream.blogspot.com/2010/12/excel-to-array-in-php_27.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkUAQHg-cSp7ImA9Wx9QFU0.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005.post-6390217862174364564</id><published>2010-12-27T19:49:00.000-08:00</published><updated>2010-12-27T19:50:41.659-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-27T19:50:41.659-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="PHP Arrays" /><category scheme="http://www.blogger.com/atom/ns#" term="PHP Tips" /><title>Excel to Array in PHP</title><content type="html">Customer's data can come from various sources, and making it easier for them to get the data into our system means we are increasing our customer's count. So, our code should support importing of data from different sources.&lt;br /&gt;And one of the common sources can be Excel. So, we need to create an interface for customers so that they can load data from excel to our database.&lt;br /&gt;Instead of spending hours entering data into forms, users can simply use tools such as excel to load data from excel using php.&lt;br /&gt;In the following code, we load data from excel in php, read it and display the data back to the users. The displaying of data part can be replaced by inserting the loaded excel data to database to suit individual needs. And we are&lt;br /&gt;using XML to do this.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Let's say we have a form "form.php" as:&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt; &lt;form method="post" enctype="multipart/form-data" action="do_act.php"&gt;&lt;br /&gt;  File:&lt;br /&gt;  &lt;input type="file" name="excelFle" /&gt;&lt;br /&gt;  &lt;input type="submit" /&gt;&lt;br /&gt; &lt;/form&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now after user adds an excel file and uploads it, following code "do_act.php" is executed,&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt; $dataArr = array();&lt;br /&gt; if($_FILES["excelFle"]["tmp_name"]) {&lt;br /&gt;  $xmlDom = DOMDocument::load($_FILES["excelFle"]["tmp_name"]);&lt;br /&gt;  $allRows = $xmlDom-&gt;getElementsByTagName('Row');&lt;br /&gt;  //loop through each of the row element&lt;br /&gt;  foreach($allRows as $row) {&lt;br /&gt;   $cells = $row-&gt;getElementsByTagName('Cell');&lt;br /&gt;   $rowData = array();&lt;br /&gt;   foreach($cells as $cell) {&lt;br /&gt;    $rowData []= $cell-&gt;nodeValue;&lt;br /&gt;   }&lt;br /&gt;   $dataArr []= $rowData;&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; //so now you can check for the array of data as:&lt;br /&gt; echo "&lt;pre&gt;";&lt;br /&gt; print_r($dataArr);&lt;br /&gt; echo "&lt;/pre&gt;";&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2821308795243888005-6390217862174364564?l=leaveurdream.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/tz_s3RjkPUA4vr-P9AgYn9sHuk8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/tz_s3RjkPUA4vr-P9AgYn9sHuk8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/tz_s3RjkPUA4vr-P9AgYn9sHuk8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/tz_s3RjkPUA4vr-P9AgYn9sHuk8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/MJNuf/~4/mZrnsTwGQ20" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/6390217862174364564/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=2821308795243888005&amp;postID=6390217862174364564" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/6390217862174364564?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/6390217862174364564?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/MJNuf/~3/mZrnsTwGQ20/excel-to-array-in-php.html" title="Excel to Array in PHP" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://leaveurdream.blogspot.com/2010/12/excel-to-array-in-php.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUICQXk9fyp7ImA9Wx9QEEw.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005.post-7081650766829674109</id><published>2010-12-22T03:20:00.000-08:00</published><updated>2010-12-22T03:32:40.767-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-22T03:32:40.767-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="PHP Tips" /><title>Dynamic functions in CodeIgniter Model</title><content type="html">Using dynamic function can be of great ease at times. Since i was developing some project on codeIgniter, i thought of giving it a try to create dynamic functions in codeigniter model. The following code is just a startup, if this works out good then will add more of the functions in it.&lt;br /&gt;Functions can be created on the fly using PHP's magic method __call(). As per php.net this method is triggered when invoking methods that are not accessible in object context.&lt;br /&gt;So, in codeIgniter as there are controllers, views and models. I thought of adding a model that would create dynamic functions, which can then be accessed by controllers.&lt;br /&gt;The code snippet is just a test.&lt;br /&gt;I created a Test_model.php file as:&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;class Test_model extends Model {&lt;br /&gt;   private $id = 0;&lt;br /&gt;   private $table;&lt;br /&gt;   private $fields = array();&lt;br /&gt;   function  Test_model() {&lt;br /&gt;            parent::Model();&lt;br /&gt;        }&lt;br /&gt;        //setup the tablename and field names&lt;br /&gt;        function set_up_table($table, $fields) {&lt;br /&gt;            $this-&gt;table = $table;&lt;br /&gt;            foreach($fields as $key) {&lt;br /&gt;                $this-&gt;fields[$key] = null;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        //magic method to set and get&lt;br /&gt;        function __call($method, $args) {&lt;br /&gt;            if(preg_match("/set_(.*)/", $method, $exists)) {&lt;br /&gt;                if(array_key_exists($exists[1], $this-&gt;fields)) {&lt;br /&gt;                    $this-&gt;fields[$exists[1]] = $args[0];&lt;br /&gt;                    return true;&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            else if(preg_match("/get_(.*)/", $method, $exists)) {&lt;br /&gt;                if(array_key_exists($exists[1], $this-&gt;fields)) {&lt;br /&gt;                    return $this-&gt;fields[$exists[1]];&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            return false;&lt;br /&gt;        }&lt;br /&gt;        //function to insert to database&lt;br /&gt;        function insert() {&lt;br /&gt;            $this-&gt;db-&gt;insert($this-&gt;table, $this-&gt;fields);&lt;br /&gt;            return $this-&gt;db-&gt;insert_id();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now the controller part:&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;class Welcome extends Controller {&lt;br /&gt;&lt;br /&gt;    function Welcome() {&lt;br /&gt;        parent::Controller();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    function index() {&lt;br /&gt;        //name of fields in book table&lt;br /&gt;        $fieldsArr = array( 'id', 'author','title', 'publisher' );&lt;br /&gt;        $tableName = "book";&lt;br /&gt;&lt;br /&gt;        $this-&gt;load-&gt;model("Test_model", "test");&lt;br /&gt;        $this-&gt;test-&gt;set_up_table($tableName, $fieldsArr);&lt;br /&gt;        $this-&gt;test-&gt;set_author("John Doe");&lt;br /&gt;        $this-&gt;test-&gt;set_title("Advanced PHP Web Development");&lt;br /&gt;        $this-&gt;test-&gt;set_publisher("Wrox");&lt;br /&gt;        $bookId = $this-&gt;test-&gt;insert();&lt;br /&gt;        &lt;br /&gt;        $this-&gt;load-&gt;view('welcome_message');&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And thats it. The code in controller sets values for all the fields and then we call insert function created in our model. The main objective behind the code is to show how dynamic functions tend to ease out the process of coding.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2821308795243888005-7081650766829674109?l=leaveurdream.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/cpm_W2ULhFq-YqXpujr7MkNmm4Q/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/cpm_W2ULhFq-YqXpujr7MkNmm4Q/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/cpm_W2ULhFq-YqXpujr7MkNmm4Q/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/cpm_W2ULhFq-YqXpujr7MkNmm4Q/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/MJNuf/~4/Lc2oh0E5TW4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/7081650766829674109/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=2821308795243888005&amp;postID=7081650766829674109" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/7081650766829674109?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/7081650766829674109?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/MJNuf/~3/Lc2oh0E5TW4/dynamic-functions-in-codeigniter-model.html" title="Dynamic functions in CodeIgniter Model" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://leaveurdream.blogspot.com/2010/12/dynamic-functions-in-codeigniter-model.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0AGRnc-cSp7ImA9Wx9QEE0.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005.post-8363241867332136114</id><published>2010-12-22T00:14:00.000-08:00</published><updated>2010-12-22T00:15:27.959-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-22T00:15:27.959-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JSON" /><category scheme="http://www.blogger.com/atom/ns#" term="jQuery" /><title>Cross domain communication using jQuery</title><content type="html">Due to some restrictions added by browsers, communication across cross domains is not possible by simple use of Ajax technology. It can be done though by adding a server-side script like PHP, and CURLing the other domain to get data and then passing it on to our javascript. But this method requires more code and is&lt;br /&gt;not scalable.&lt;br /&gt;&lt;br /&gt;A better way is to dynamically add script to the page, whose source points to the service url and get the response (data) in the script. This is what JSONP &lt;br /&gt;(Javascript Object Notation with Padding) does.&lt;br /&gt;&lt;br /&gt;JSON is a lightweight data exchange format for exchanging data between browser and server, and jQuery has a native support for JSONP calls beginning with version 1.2. We can load JSON data located at another domain specifying a JSONP callback.&lt;br /&gt;&lt;br /&gt;This can be done as:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="js"&gt;&lt;br /&gt;$.getJSON(domainurl+"&amp;callback=?", function(response) {&lt;br /&gt;    alert("Username: " + response.username);&lt;br /&gt;});&lt;br /&gt;&lt;/pre&gt; &lt;br /&gt;&lt;br /&gt;In above code jQuery replaces '?' after 'callback=' with a generated function name to call. And on complete the function name is removed. &lt;br /&gt;&lt;br /&gt;Despite its ease of use for cross-domain comunication, JSONP has some drawbacks as well. Lets say, if the dynamic script addition does not work then nothing happens, we do not get any errors, it means there is no any error handling support in JSONP.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2821308795243888005-8363241867332136114?l=leaveurdream.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/6I_sQ44iVqqG9yyaX9KL-GKopJ0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/6I_sQ44iVqqG9yyaX9KL-GKopJ0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/6I_sQ44iVqqG9yyaX9KL-GKopJ0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/6I_sQ44iVqqG9yyaX9KL-GKopJ0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/MJNuf/~4/eSNJH_1cxHc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/8363241867332136114/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=2821308795243888005&amp;postID=8363241867332136114" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/8363241867332136114?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/8363241867332136114?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/MJNuf/~3/eSNJH_1cxHc/cross-domain-communication-using-jquery.html" title="Cross domain communication using jQuery" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://leaveurdream.blogspot.com/2010/12/cross-domain-communication-using-jquery.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0YDRn0yfyp7ImA9Wx9RGEk.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005.post-5872478555355449110</id><published>2010-12-20T04:33:00.001-08:00</published><updated>2010-12-20T04:46:17.397-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-20T04:46:17.397-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Javascript" /><category scheme="http://www.blogger.com/atom/ns#" term="XML" /><title>Parse XML using Javascript</title><content type="html">It is quite easier to parse XML using Javascript. Most of the browsers have XML parsers for manipulating XML. But, prior to parsing the XML it must first be loaded to XML DOM object, which can then be accessed with Javascript. Since for some security reasons, browsers do not allow access across domains, both the page and the xml it is trying to load should be in same server.&lt;br /&gt;&lt;br /&gt;Lets's say, we have an users.xml file like:&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;&lt;users&gt;&lt;br /&gt; &lt;user id="12"&gt;&lt;br /&gt;  &lt;firstname&gt;Sudhir&lt;/firstname&gt;&lt;br /&gt;  &lt;lastname&gt;Bastakoti&lt;/lastname&gt;&lt;br /&gt;  &lt;age&gt;27&lt;/age&gt;&lt;br /&gt; &lt;/user&gt;&lt;br /&gt; &lt;user id="13"&gt;&lt;br /&gt;  &lt;firstname&gt;John&lt;/firstname&gt;&lt;br /&gt;  &lt;lastname&gt;Doe&lt;/lastname&gt;&lt;br /&gt;  &lt;age&gt;72&lt;/age&gt;&lt;br /&gt; &lt;/user&gt;&lt;br /&gt;&lt;/users&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Step 1: Load the XML&lt;br /&gt;&lt;pre name="code" class="js"&gt;&lt;br /&gt;function loadXML(xmlFile) {&lt;br /&gt; if(window.XMLHttpRequest) {&lt;br /&gt;  xvar = new XMLHttpRequest();&lt;br /&gt; }&lt;br /&gt; else {&lt;br /&gt;  xvar = new ActiveXObject("Microsoft.XMLHTTP");&lt;br /&gt; }&lt;br /&gt; xvar.open("GET", xmlFile, false);&lt;br /&gt; xvar.send();&lt;br /&gt; return xvar.responseXML;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;OR, the XML can be loaded as string as well, like&lt;br /&gt;&lt;pre name="code" class="js"&gt;&lt;br /&gt;function loadXMLString(xmlString) {&lt;br /&gt; //here xmlString is the content of XML as string&lt;br /&gt; if(window.DOMParser) {&lt;br /&gt;  parseIt = new DOMParser();&lt;br /&gt;  xDoc = parseIt.parseFromString(xmlString,"text/xml");&lt;br /&gt; }&lt;br /&gt; else {&lt;br /&gt;  xDoc = new ActiveXObject("Microsoft.XMLDOM");&lt;br /&gt;  xDoc.async = "false";&lt;br /&gt;  xDoc.loadXML(xmlString); &lt;br /&gt; }&lt;br /&gt; return xDoc;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;There are some properties of DOM u.parentNode gives parent node of u, u.childNodes gives child nodes of u, u.attributes gives attributes nodes of u, u.nodeName gives name of u , u.nodeValue gives value of u&lt;br /&gt;And we have a nodeType Property&lt;br /&gt;Element has NodeType 1, Attribute 2, Text 3, Comment 8 and Document 9&lt;br /&gt;&lt;br /&gt;Step 2:&lt;br /&gt;To get the length of &lt;user&gt; nodes we can do as:&lt;br /&gt;&lt;pre name="code" class="js"&gt;&lt;br /&gt;xDoc = loadXML("books.xml");&lt;br /&gt;u = xDoc.getElementsByTagName("user").length;&lt;br /&gt;//it will output 2&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;To loop through all the nodes we can do as:&lt;br /&gt;&lt;pre name="code" class="js"&gt;&lt;br /&gt;xDoc = loadXML("books.xml");&lt;br /&gt;u = xDoc.documentElement.childNodes;&lt;br /&gt;var details = "";&lt;br /&gt;for(var i = 0; i &lt; u.length; i++) {&lt;br /&gt; details +=u[i].nodeName+": "+x[i].childNodes[0].nodeValue+"&lt;br /&gt;";&lt;br /&gt;}&lt;br /&gt;alert(details);&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2821308795243888005-5872478555355449110?l=leaveurdream.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/4RqIyGC83EcAXbQ9fAFIobhgNMc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4RqIyGC83EcAXbQ9fAFIobhgNMc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/4RqIyGC83EcAXbQ9fAFIobhgNMc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4RqIyGC83EcAXbQ9fAFIobhgNMc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/MJNuf/~4/WGuvR8jg3bg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/5872478555355449110/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=2821308795243888005&amp;postID=5872478555355449110" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/5872478555355449110?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/5872478555355449110?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/MJNuf/~3/WGuvR8jg3bg/parse-xml-using-javascript.html" title="Parse XML using Javascript" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://leaveurdream.blogspot.com/2010/12/parse-xml-using-javascript.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0UCQn0-eCp7ImA9Wx9RFUo.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005.post-601682431886918434</id><published>2010-12-16T23:27:00.000-08:00</published><updated>2010-12-16T23:34:23.350-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-16T23:34:23.350-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Ajax" /><category scheme="http://www.blogger.com/atom/ns#" term="PHP Tips" /><title>Detect Ajax request using PHP</title><content type="html">Sometimes, we need to detect ajax request using php. In such case, we can write following code that checks whether the request is ajax or not. It is helpful in conditions such as when i have to load a page depending on condition using a same function in php.&lt;br /&gt;&lt;pre name="code" class="php"&gt;&lt;br /&gt;if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) &amp;&amp; $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')) {&lt;br /&gt;    echo "Ajax request";&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;    echo "Normal Page Load";&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And thats it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2821308795243888005-601682431886918434?l=leaveurdream.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/w8zEBWsXl42-8g6a7i5q_jmZmh8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/w8zEBWsXl42-8g6a7i5q_jmZmh8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/w8zEBWsXl42-8g6a7i5q_jmZmh8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/w8zEBWsXl42-8g6a7i5q_jmZmh8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/MJNuf/~4/FQlbbT4fCm4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/601682431886918434/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=2821308795243888005&amp;postID=601682431886918434" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/601682431886918434?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/601682431886918434?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/MJNuf/~3/FQlbbT4fCm4/detect-ajax-request-using-php.html" title="Detect Ajax request using PHP" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://leaveurdream.blogspot.com/2010/12/detect-ajax-request-using-php.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEECQXg8eyp7ImA9Wx9RFEQ.&quot;"><id>tag:blogger.com,1999:blog-2821308795243888005.post-3106304424690878239</id><published>2010-12-16T02:43:00.000-08:00</published><updated>2010-12-16T02:51:00.673-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-16T02:51:00.673-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="jQuery" /><title>Check uncheck jquery plugin</title><content type="html">I needed check all - uncheck all checkboxes feature to be added to lots of pages in one of my site, so thought of creating a jquery plugin for it, so that i would not have to write same piece of code here and there. So here's the plugin, if Check All checkbox is checked all the sub checkboxes are checked and vice-versa, and if Check All is checked and then any of the sub checkboxes is unchecked, then Check All will also be unchecked.&lt;br /&gt;&lt;pre name="code" class="js"&gt;&lt;br /&gt;(function($) {&lt;br /&gt; $.fn.extend({&lt;br /&gt;  checkun: function(options) {&lt;br /&gt;   var defaults = {&lt;br /&gt;    chkAllName : "",&lt;br /&gt;    chkBoxName : ""&lt;br /&gt;   }&lt;br /&gt;   var options = $.extend(defaults, options);&lt;br /&gt;   var chkAll = options.chkAllName;&lt;br /&gt;   var chkBoxs = options.chkBoxName;&lt;br /&gt;   var chkBoxesLength = $("input[name='"+chkBoxs+"']").length;&lt;br /&gt;   &lt;br /&gt;   $("input[name='"+chkAll+"']").click(function() {&lt;br /&gt;    //get checked state of chkAll checkbox&lt;br /&gt;    var chkState = $(this).attr("checked");&lt;br /&gt;    if(chkState) {&lt;br /&gt;       $("input[name='"+chkBoxs+"']").attr("checked", true);&lt;br /&gt;    }&lt;br /&gt;    else {&lt;br /&gt;     $("input[name='"+chkBoxs+"']").attr("checked", false);&lt;br /&gt;    }&lt;br /&gt;   });&lt;br /&gt;   $("input[name='"+chkBoxs+"']").click(function() {&lt;br /&gt;    var subChkState = $(this).attr("checked");&lt;br /&gt;    if(subChkState) {&lt;br /&gt;     //get the total checkboxes and total checked checkboxes&lt;br /&gt;     var chkedLen = $("input[name='"+chkBoxs+"']:checked").length;&lt;br /&gt;     if(chkedLen == chkBoxesLength) {&lt;br /&gt;      $("input[name='"+chkAll+"']").attr("checked", true);&lt;br /&gt;     }&lt;br /&gt;    }&lt;br /&gt;    else {&lt;br /&gt;     //uncheck the chkAll checkbox&lt;br /&gt;     $("input[name='"+chkAll+"']").attr("checked", false);&lt;br /&gt;    }&lt;br /&gt;   });&lt;br /&gt;  }&lt;br /&gt; });&lt;br /&gt;})(jQuery);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And to test it, we use the following&lt;br /&gt;&lt;pre name="code" class="js"&gt;&lt;br /&gt;//load jquery.js&lt;br /&gt;&lt;script type="text/javascript" src="jquery.checkun.js"&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;br /&gt;$(document).ready(function() {&lt;br /&gt;   //chkAll is the name of checkbox Check All&lt;br /&gt;   // chkBox[] is the name of sub checkboxes&lt;br /&gt;   $.fn.checkun({chkAllName: "chkAll", chkBoxName: "chkBox[]"});&lt;br /&gt;});&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;//&lt;input type="checkbox" name="chkAll" id="chkAlls" /&gt;&amp;nbsp; Check All&lt;br /&gt;//&lt;input type="checkbox" name="chkBox[]" id="chkBox1" /&gt;&lt;br /&gt;//&lt;input type="checkbox" name="chkBox[]" id="chkBox2" /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Thats it. Hope this helps someone.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2821308795243888005-3106304424690878239?l=leaveurdream.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/hY0a2FcnwXSUmBoQ2hv-YDrm-jk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hY0a2FcnwXSUmBoQ2hv-YDrm-jk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/hY0a2FcnwXSUmBoQ2hv-YDrm-jk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hY0a2FcnwXSUmBoQ2hv-YDrm-jk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/MJNuf/~4/J4T8gjOwheU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://leaveurdream.blogspot.com/feeds/3106304424690878239/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=2821308795243888005&amp;postID=3106304424690878239" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/3106304424690878239?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2821308795243888005/posts/default/3106304424690878239?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/MJNuf/~3/J4T8gjOwheU/check-uncheck-jquery-plugin.html" title="Check uncheck jquery plugin" /><author><name>Sudhir Bastakoti</name><uri>http://www.blogger.com/profile/09644016451027858552</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total><feedburner:origLink>http://leaveurdream.blogspot.com/2010/12/check-uncheck-jquery-plugin.html</feedburner:origLink></entry></feed>

