Archive for Playground
May 15, 2008 at 12:08 pm · Filed under Interest, Playground, Resources
When I work on my local machine on a website, I usually setup the virtual host on a sub-domain setup on the localhost. I feel comfortable using a sub-domain rather than setting up an Alias. I’ve seen many people know about it, but there are many who don’t, and this is for them.
So what do you have to do to setup a sub-domain on the localhost? It is not a rocket science but one must know where to do it, especially on a Windows box.
On Windows OS browse to {Drive on which your Windows OS is installed}:/{WINDOWS/WINNT}/system32/drivers/etc/. Open “hosts” file into a text editor, and you will see something similar to this:
# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
127.0.0.1 localhost
The last line represents the hop any request to http://localhost/ will go through. The IP 127.0.0.1 is used (usually) for you localhost, and going to http://localhost/ will access the files under the root of directory setup for it. Now if you want to setup a sub-domain called “myself”, i.e. http://myself.localhost/, then you add the following line at the end of the file.
127.0.0.1 myself.localhost
On a Linux box, “hosts” file is located under /etc/. You will require “root” access to edit this file or the user access who has priviledge to edit this file. Similar to Windows system, add the following line into the file:
127.0.0.1 myself.localhost
You don’t have to restart your web server for this change to take effect. But you will have to setup the virtual host to point to this sub-domain, which will require you to restart the web server.
Thank You.
May 15, 2008 at 11:39 am · Filed under Interest, Playground, Resources
Ever wanted to redirect users from one domain to other or one sub-domain to other without compromising the the file path or query string variables? I’ve come across the requirement when I published my WordPress blog.
For testing, I initially installed WordPress on a testing sub-domain, where I imported all the blog entries and added blog-roll links. After doing so, PHPClasses.org picked up my entries for Grab Yahoo, LinkMeIn and MySpace profile updater as track-back links. Later when I switched to my main sub-domain, I’d to find a way to keep the track-back links as is, and redirect users to the proper locations. The trick was done by .htaccess file.
After reading the apache’s documentation on mod_rewrite module, I’ve successfully implemented it. If you want people accessing http://sub1.yourdomain.com/2/12/some-post-of-yours/ to go to http://sub2.yourdomain.com/2/12/some-post-of-yours/ then in the root of sub1 (first sub-domain) create a .htaccess file and add the following lines:
RewriteEngine On
RewriteRule (.*) http://sub2.yourdomain.com/$1
I have not read much and not sure if there’s any other option to do this more efficiently; but this trick has served my purpose.
May 14, 2008 at 9:10 pm · Filed under Interest, Playground
My blog is now powered by WordPress. Since I launched my website, since 2000, I’ve always maintained my own design; even I’ve developed a blog so that I can shape it the way I want. But these days I don’t even have time to write something on my blog and to come up with a new design is something that is kind of IMPOSSIBLE.
So, the thing I’ve decided to do is what you see now. I’ve installed WordPress on my server and just finished importing all my blog entries, setup the pages and, of course, choose the theme. Choosing theme was one of the biggest and time consuming part of this whole process. I always like simple but eye catching design. I don’t know if this design is eye catching to you (the reader) but I really liked it. First time I saw this theme on Lokesh Dhakar’s website, developer of Lightbox script used to overlay images.
After installing WordPress, I’ve been trying to explore different things it offers; different plug-ins, themes, widgets etc. I’ve never used WordPress but the experience so far is good. It has some nice features, which I’ve always wanted to implement on my custom made blog. Now that I’ve decided to use WordPress, it will make my life easier, I hope. I know to add a new page or post is going to be smooth but not sure about choosing new theme. I don’t like to hang around with a single design for a long time. I hope that will be smooth as well
Thank you!
August 31, 2007 at 11:32 am · Filed under Interest, Playground, Resources
Today my new class LinkMeIn was released on PHPClasses.org. I have developed this class about couple of months back but did not have enough time to sit and arrange the files to upload on PHPClasses.org. After Grab Yahoo and MySpace Profile Updater classes this is my third class for same type. This class allows any registered LinkedIn.com user to enter their login information and get the contact list. The list is returned as an array or RSS 2.0 format.
I will update LinkMeIn class in future to add more functionalities to it. For the time being if you want to test it, please visit the LinkMeIn Demo location. To report any bug please use PHPClasses.org Support Forum and if you want to contact me directly please go to the Contact section.
–
Thank you
August 24, 2007 at 10:07 pm · Filed under Interest, Playground, Resources
I have added a new functionality for the Grab Yahoo class. Soon after I released the patch, I figured out that I could add this new functionality which did not take me much time to implement. This new feature will allow you to grab your Yahoo! Calendar in an array format.
Using Yahoo’s calendar export feature, I grab the CSV file and parse it to form an array. This was a very simple addition as it uses same method as Address Book parsing. Only thing that was different was the way I had to parse the CSV, which Yahoo creates for Outlook. I don’t have any further plan to upgrade this class but do have other plans to build similar web service based classes.
Please download the latest version of grab yahoo class (v.1.3) here.
–
Thank you.
August 20, 2007 at 10:57 pm · Filed under Interest, Playground, Resources
Last week suddenly my Grab Yahoo class stopped working for Address Book section. After Mr Mandy Singh reported the bug on phpclasses.org discussion board I started digging to resolve the issue.
When requesting the address book CSV from Yahoo a value for the key “crumb” is sent in the query string. Earlier Yahoo never checked for the validity of the variable but they have changed the way it is used. Now they check if the value for “crumb” is valid or not. As my script was using a predefined value and it has expired, Yahoo server could not validate. Yahoo was showing an error stating “Invalid or missing crumb”.
I modified my class so that it first loads the page from where request for the CSV is made. From the source of the page, it locates the latest value for crumb assigned by Yahoo and uses that value to send request for the address book CSV file. It is now working as expected. If you find any bug please report it on phpclasses.org discussion board.
Please download the latest version of Grab Yahoo class (v. 1.2.1) here.
–
Thank you.
September 18, 2006 at 6:12 am · Filed under Playground
Windows Installation steps for Ruby on Rails
You will have to download Ruby installer - click here - and run the installer.
Now next step is to install Rails and to do that go to Command Prompt [Start > Run > cmd]. Run the following command:
gem install rails -remote
This command will look for appropriate version of Rails for the Ruby, download it for installation. This installation process will give some options, select Y for all the givens.
Setup an empty Rails application
To setup a blank/empty Rails application open command prompt and navigate to your project directory:
cd D:/projects/ror/
Now let’s say we want to name our first Ruby on Rails web application “fror” [First Ruby on Rails]. To do so run the following command:
rails fror
This will create a directory called “fror” containing complete directory tree of folders and files for the Rails application.
Test our first Rails application
From the command prompt navigate into the directory that we have just created “fror” and type the following command to start built-in web server, WEBrick:
ruby script/server
Now try to run the URL http : // localhost : 3000/ and this should give you a message like “Welcome aboard”.
May 25, 2006 at 9:44 pm · Filed under Interest, Playground, Resources
Today my class titled Grab Yahoo has been published on www.phpclasses.org.
This class is a collation of my previous two scripts in PHP to grab Yahoo address book and messenger list. You will have to provide your
Yahoo account username and password to it which will return an array of the list of your choosen service (Address Book or Messenger List).
This will be useful in a way that anyone willing to provide the service like upon user registration to the site, you ask the person to invite people on their Yahoo address book etc. Similar to what Hi5, Name Database etc does.
Please visit the download page here to download the class pack.
Visit the discussion board to post any suggestion, comment or bug to report.
Please don’t forget to rate my script.
Visit this page to see the demo.
~~Thanks to all and God Bless!!~~
May 20, 2006 at 12:17 am · Filed under Interest, Playground, Resources
First of all Thanks to Mr Arun for pointing out the problem in running the script (Yahoo! Messenger Friend List) on localhost. When I started working with cURL to grab the Yahoo address book, I faced the problem. Later when I uploaded my script on to server, it did not give any error and since then I have been testing my code there instead of testing it locally. But due to the fact that people will definitely try to run it on their localhost, I came to realisation that it is necessary to provide a solution. So after few hours of investigation I finally resolved it.
Basically the problem is that cURL is unable to verify the SSL certificate on localhost. The error that is generated by cURL is:
SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
If you print the cURL error in my code, you will see this error generated on localhost.
echo curl_error($ch);
To solve this problem, first we will need to provide a file that is known as CA Bundle for cURL to read and verify the SSL certificate. Download the text format file for CA Bundle from here. On the site it says the file is in PEM format, but on my WinXP I saved the file as “CRT” file. This extension shows the correct icon. Although the extension really does not matter because all cURL will use it for is to verify the SSL certificate.
This is not the only problem that I faced while working on localhost. I found the cURL option CURLOPT_COOKIEJAR does not save the cookie file. I found a nice explanation of it on php.net. There were few options that was given by users. One of them was that after a cookie is created the cookie information reside in the header. When CURLOPT_COOKIEJAR cannot write it to a file you can write the header information using CURLOPT_WRITEHEADER to a file and grab the cookie information from there. But one of the other option solved the problem very easily. Relative path to the file that I specified was not understood by cURL. So instead I had to write full path for the filename which worked perfectly. cURL option CURLOPT_COOKIEJAR wrote the file without any problem.
The last problem that I faced was a little tricky and took most of my time solving it. I was getting authenticated by Yahoo without any problem but when I was trying to go to next step, which is actually to grab my messenger list a cURL error was generated “Can’t connect to host”. I could not understand why one part of the code connects to Yahoo and authenticates and the other cannot connect to any site at all. This was probably due to my tired brain which took this much time figuring out the problem. The problem is that I use HTTP proxy server!! But do not require any proxy to connect to secured servers. Solution to this is to use cURL option CURLOPT_PROXY to specify your proxy server address and port number, only if you require proxy server. According to my code, it should be placed in the second part of cURL operation, which is initalised to $ch1.
curl_setopt($ch1, CURLOPT_PROXY, “proxy.address_of.isp:port”);
This small changes resolves all problems and the script works on localhost perfectly. Here is a quick look towards the change required in get_list.php file.
Step 1: Download the CA Bundle file and place it where your server can access. Make sure the file and directory has the right permission setup.
Step 2: Place the following line before performing the first cURL session, i.e. curl_exec($ch); [line number 64]
curl_setopt($ch, CURLOPT_CAINFO, ‘full/path/to/the/ca-bundle.crt’);
Step 3: You need to specify the full path to save your Cookie file. Currently line number 53 needs to be modified.
$cookieFilename = MD5($cookieFilename);
changes to
$cookieFilename = $_SERVER['DOCUMENT_ROOT'] . ‘/any/additional/directory/names/’ . MD5($cookieFilename);
I prefer to use DOCUMENT_ROOT, but the path should be as per your choice and must be accessible by your server.
Step 4: This step is to be followed only if you are using proxy server. Specify the following line before performing your cURL session. If you require proxy for both http and secured server then the lines should be used in the both sessions.
curl_setopt([$ch][$ch1], CURLOPT_PROXY, “proxy.address_of.isp:port”);
After solving this to run on localhost, I am now interested to make the code more customisable. Use of constants, methods etc will be very nice. I also need to clean up the code a lot. Please contact me if anyone of you face problem using it either on localhost or remote server.
~~ThAnKs~~
May 18, 2006 at 2:05 pm · Filed under Interest, Playground, Resources
Using cURL in PHP is not that tough after all. Just the other day I came up with a script that grabs the Yahoo! Address Book. Today I have modified the same script to grab Yahoo! Messenger friend list.
Check out grabbers here.
One must know the URLs that Yahoo! goes through and data that it passes for authentication. After cURL helps you to authenticate on Yahoo, you simply write a Cookie file to contain the session information. This file is used later part of the script where cURL helps you to grab the address book or messenger list.
You will need to trick Yahoo by sending header information like HTTP Referrer. Address book is grabbed in CSV format, which needs to be parsed to show your desired information. There are 82 columns that address book sends you!! For messenger it is just cleaning up a HTML file generated by cURL. You instruct cURL not to give any output of the generated result, then save it on a temporary file, clean up unnecessary information, reformat the remaining information and print it on the screen. At the end you MUST use unlink() to delete all the files that were generated during the process. Cookie file, messenger list file etc. I have deleted them, being a good boy!!
Here is the partial sample code.
https://login.yahoo.com/config/login?”;
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 22);
curl_setopt($ch, CURLOPT_POSTFIELDS, …..!!! STOP HERE |
The script for grabbing Yahoo messenger list has been published on weberdev.com. Please click “Yahoo! Messenger Friend List” to see my code on weberdev.com and download the ZIP attached to the example.
~~EnJoY~~
Next entries »