Sunday, December 26, 2010

What is osCommerce?

I personally recommend this e-commerce solution for your online shop. This is totally FREE under the GNU General Public License and has a good reputation around the world.

About osCommerce:

osCommerce is an online shop e-commerce solution that offers a wide range of out-of-the-box features that allows online stores to be setup fairly quickly with ease, and is available for free as an Open Source based solution released under the GNU General Public License.

osCommerce was started in March 2000 and has since matured to a solution that is currently powering 12,150 registered live shops around the world.

Today, osCommerce has been taken to the next level, moving towards an e-commerce framework solution that not only remains easy to setup and maintain, but also making it easier for store administrators to present their stores to their customers with their own unique requirements.

The success of osCommerce is secured by a great and active community where members help one another out and participate in development issues reflecting upon the current state of the project.

osCommerce Philosophy:

Open Source software provides an opportunity for people to work on software with others that share the same interest, exchanging ideas, knowledge, and work with one another, to expand and improve the solution.

The motivation for working on Open Source software originates at different sources, which include working on the software for fun as a hobby, to make the software meet own requirements, and to bring commercial interest into the software.

It is this combination of motivations that has brought together a team of developers to successfully make what osCommerce is today - and what it will be in the future - and an active and growing community, with each person having their own unique requirements but ultimately sharing the same goal: to use the software and to make it a better solution.

Open Source software always remains open providing the opportunity for anyone that is interested to work on it, at any time.

Because Open Source software is open, it provides a choice. The choice to use the software, the choice to learn the software, and the choice to join, share, and participate in a community - a community full of enthusiastic supporters that want to see the software grow and succeed.

It is this very reason why Open Source software is successful, and most importantly, why it works.

Saturday, December 25, 2010

How to post facebook status via backend in PHP

As promised, here's the script on how to submit facebook status using PHP. just follow the simple steps below and you can have a facebook status update on your own website.

1. Again, from my previous post, you should know the structure of the wapsite you wish to access via back-end and for this post, we will access facebook wapsite http://m.facebook.com. check out also my previous post - How to submit facebook status via back-end using PERL

2. Since we are using PHP, we will use CURL to access the site via back-end. make sure you have installed CURL in your server.

3. To start with, input your facebook username/email, password, and status.

$fuser = '<your facebook username/email>';
$fpass = '<your facebook password>';
$status = '<your facebook status>';


4. Initialize CURL as coded below. set the CURLOPT_URL to the login page of the wapsite http://m.facebook.com/login.php to login to the site. set the CURLOPT_POSTFIELDS email and password. then the CURLOPT_COOKIEJAR and CURLOPT_COOKIEFILE.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/login.php');
curl_setopt($ch, CURLOPT_POSTFIELDS,'email='.urlencode($fuser).'&pass='.urlencode($fpass).'&login=Login');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/my_cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
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");
curl_setopt($ch, CURLOPT_REFERER, "http://m.facebook.com");
$page = curl_exec($ch); 


5. CURL_EXEC will output the redirected page which you will need to get PARAMETERS in sending STATUS. you can try printing the variable $page so you will know if the return page is successful or not. I pasted a code snippet of the return page below.

<form method="post" id="composer_form" action="/a/home.php?fbb=rbacd82de&amp;refid=7"><input type="hidden" name="fb_dtsg" value="DdtLy" autocomplete="off" /><input type="hidden" name="post_form_id" value="f224790ed71d0fe6565de44f1b4bbe98" /><input type="hidden" name="charset_test" value="€,´,€,´,水,Д,Є" /><div>What&#039;s on your mind?<br /><textarea class="composerInput" name="status" rows="2" onfocus="" onblur=""></textarea></div><input type="submit" value="Share" class="btn btnC" name="update" /></form>


6. You will need parameters such as FORM ACTION, FB_DTSG, and POST_FORM_ID just like in my previous post. to get these parameters, you should use PREG_MATCH.

//this gets the post_form_id value
preg_match("/input type=\"hidden\" name=\"post_form_id\" value=\"(.*?)\"/", $page, $form_id);
//we'll also need the exact name of the form processor page
preg_match("/form method=\"post\" id=\"composer_form\" action=\"(.*?)\"/", $page, $form_action);
//we'll also need the value of the fb_dtsg
preg_match("/name=\"fb_dtsg\" value=\"(.*?)\"/", $page, $form_fbdtsg);


7. All parameters will be stored as ARRAY in variables $form_id, $form_action, and $form_fbdtsg. you will use this on the code below to send facebook status.

curl_setopt($ch, CURLOPT_URL, "http://m.facebook.com".$form_action[1]);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'post_form_id='.$form_id[1].'&status='.urlencode($status).'&fb_dtsg='.$form_fbdtsg[1].'&update=Share');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/my_cookies.txt");
$page = curl_exec($ch);


8. Upon executing the CURL, you should expect that your STATUS will be posted in your facebook wall. to get the output and information on your CURL execution, you can print CURL_GETINFO. You can also check for errors by printing CURL_ERRNO and CURL_ERROR.

print_r(curl_getinfo($ch));
echo curl_errno($ch) . '-' . curl_error($ch);


9. To summarize everything, you should have a code like this below. happy coding everyone!!

<?

$fuser = '<your facebook username/email>';
$fpass = '<your facebook password>';
$status = '<your facebook status>';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/login.php');
curl_setopt($ch, CURLOPT_POSTFIELDS,'email='.urlencode($fuser).'&pass='.urlencode($fpass).'&login=Login');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/my_cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
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");
curl_setopt($ch, CURLOPT_REFERER, "http://m.facebook.com");
$page = curl_exec($ch);

preg_match("/input type=\"hidden\" name=\"post_form_id\" value=\"(.*?)\"/", $page, $form_id);
preg_match("/form method=\"post\" id=\"composer_form\" action=\"(.*?)\"/", $page, $form_action);
preg_match("/name=\"fb_dtsg\" value=\"(.*?)\"/", $page, $form_fbdtsg);

curl_setopt($ch, CURLOPT_URL, "http://m.facebook.com".$form_action[1]);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'post_form_id='.$form_id[1].'&status='.urlencode($status).'&fb_dtsg='.$form_fbdtsg[1].'&update=Share');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/my_cookies.txt");
$page = curl_exec($ch);

print_r(curl_getinfo($ch));
echo curl_errno($ch) . '-' . curl_error($ch);

?>

Thursday, December 23, 2010

How to post facebook status via backend in PERL

We know that facebook site is a secured and very strict with regards to their website and other site components. There is so much happening on the site that users doesn't realize it changes constantly and that is also for security reason, why? that is because hackers do some research, checking the site constantly as well and if your site is not changing, they can come up with a plan and boom!! before you know it, you're doom already.

Enough with the applaud to the company coz they were great already.

I'm not here to lecture about hacking, but how to submit facebook status right? so, just follow the steps below and you can have a BOT that will send facebook status without human intervention.

1. First thing you have to do is to know the structure of the wap site, this time the facebook wap site http://m.facebook.com

2. Since we are using PERL, we have to install some libraries for sending HTTP request and cookies. install the libraries below:
  • LWP::UserAgent
  • HTTP::Cookies

3. After installing the 2 libraries into your server, we are now ready to do the coding. The code below is just a standard coding that we do in PERL.

#!/usr/bin/perl

require LWP::UserAgent;

use strict;
use warnings;

use HTTP::Cookies;


4. After we require the libraries, we need to initialize the variables we need.

my $lwpua = LWP::UserAgent->new;

5. Set your facebook username/email, password, and your status. please see below.

my $strUser = "<your facebook username/email>";
my $strPass = "<your facebook password>";
my $strStatus = "<your facebook status>";


6. Set up user agent that we will use to send HTTP request.

my $user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6";
my @header = ( 'Referer' => 'http://m.facebook.com/','User-Agent' => $user_agent);


7. Set up cookie file and jar.

my $cookie_file = "cookies.dat";
my $cookie_jar = HTTP::Cookies->new(
                file => $cookie_file,
                autosave => 1,
                ignore_discard => 1);

$lwpua->cookie_jar($cookie_jar);


8. Setup the code for log-in to facebook. Please take note that you should know the link of the login page of the site which is http://m.facebook.com/login.php. The important thing here is to look for the FORM element in which the site is submitting the credentials. You also have to get all the important INPUT parameters for submission to the FORM. I pasted here the FORM element of the login page source as of today as reference. Below also are the ONLY details you need to login.

=begin
<form method="post" action="https://login.facebook.com/login.php?m=m&amp;refsrc=http%3A%2F%2Fm.facebook.com%2login.php&amp;fbb=rac4881b1&amp;refid=9">
<input class="input" name="email" value="" type="text"/>
<input class="input" name="pass" type="password"/>
<input type="submit" value="Log In" class="btn btnC" name="login"/>
</form>
=cut

# logging in to facebook
my $response = $lwpua->post('http://m.facebook.com/login.php',
                      ['email' => $strUser,
                       'pass' => $strPass,
                       'login' => 'Login'], @header);


9. After logging in, we have to extract the COOKIES and use it on our next SESSION or PAGE.

$cookie_jar->extract_cookies( $response );
$cookie_jar->save;


10. After saving the COOKIES, accessing the facebook home page should direct you to the home page where in you can send your STATUS. You can check that if you print the $response->content. I also pasted the code snippet of the content below as reference.

$response = $lwpua->get('http://m.facebook.com/home.php', @header);
my $form_data = $response->content;

=begin
<form method="post" id="composer_form" action="/a/home.php?fbb=r488fb708&amp;refid=7"><input type="hidden" name="fb_dtsg" value="DdtLy" autocomplete="off" /><input type="hidden" name="post_form_id" value="726fdf3c15403500a70f64960565e305" /><input type="hidden" name="charset_test" value="€,´,€,´,水,Д,Є" /><div>What&#039;s on your mind?<br /><textarea class="composerInput" name="status" rows="2" onfocus="" onblur=""></textarea></div><input type="submit" value="Share" class="btn btnC" name="update" /></form>
=cut


11. Same thing here with the login page but this time, we need to know how the page sends a status message. find the FORM that submits STATUS. please take note that the site is frequently changing so you should know how to do the REGEX to catch all the PARAMETERS you need and for the benefit of this post, the above content is the updated content as of today and my REGEX below should be able to catch parameters such as: FORM ACTION, FB_DTSG, and POST_FORM_ID.

$form_data =~ s/\n//g;
$form_data =~ /form method="post" id="composer_form" action="(.*?)"(.*?)name="fb_dtsg" value="(.*?)"(.*?)name="post_form_id" value="(.*?)"/ig;

my $form_action = $1;
my $form_fbdtsg = $3;
my $form_id = $5;


12. Send now the STATUS message with the PARAMETERS needed below.

@header = ('Referer' => 'http://m.facebook.com/',
           'User-Agent' => $user_agent);

$response = $lwpua->post('http://m.facebook.com'.$form_action,
                           ['fb_dtsg' => $form_fbdtsg,
                            'post_form_id' => $form_id,
                            'status' => $strStatus,
                            'update' => 'Share'], @header);

$form_data = $response->content;
unlink($cookie_file);

1;


13. And, that's it!! below is the whole script. hope you were able to get it. next will be in PHP. yeah men!!

#!/usr/bin/perl

require LWP::UserAgent;

use strict;
use warnings;

use HTTP::Cookies;

my $lwpua = LWP::UserAgent->new;

my $strUser = "<your facebook username>";
my $strPass = "<your facebook password>";
my $strStatus = "<your facebook status>";

my $user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6";
my @header = ( 'Referer' => 'http://m.facebook.com/','User-Agent' => $user_agent);

my $cookie_file = "cookies.dat";
my $cookie_jar = HTTP::Cookies->new(
                file => $cookie_file,
                autosave => 1,
                ignore_discard => 1);

$lwpua->cookie_jar($cookie_jar);

my $response = $lwpua->post('http://m.facebook.com/login.php',
                      ['email' => $strUser,
                       'pass' => $strPass,
                       'login' => 'Login'], @header);
$cookie_jar->extract_cookies( $response );
$cookie_jar->save;
$response = $lwpua->get('http://m.facebook.com/home.php', @header);

my $form_data = $response->content;

$form_data =~ s/\n//g;
$form_data =~ /form method="post" id="composer_form" action="(.*?)"(.*?)name="fb_dtsg" value="(.*?)"(.*?)name="post_form_id" value="(.*?)"/ig;

my $form_action = $1;
my $form_fbdtsg = $3;
my $form_id = $5;

@header = ('Referer' => 'http://m.facebook.com/',
           'User-Agent' => $user_agent);

$response = $lwpua->post('http://m.facebook.com'.$form_action,
                           ['fb_dtsg' => $form_fbdtsg,
                            'post_form_id' => $form_id,
                            'status' => $strStatus,
                            'update' => 'Share'], @header);

$form_data = $response->content;
unlink($cookie_file);

1;

Wednesday, December 22, 2010

CodeIgniter framework for your development

CodeIgniter is an Application Development Framework - a toolkit - for people who build web sites using PHP. Its goal is to enable you to develop projects much faster than you could if you were writing code from scratch, by providing a rich set of libraries for commonly needed tasks, as well as a simple interface and logical structure to access these libraries. CodeIgniter lets you creatively focus on your project by minimizing the amount of code needed for a given task.

There's also a good book that teaches beginners on hos to install and use codeigniter on their development - Codeigniter for Rapid PHP Application Development by David Upton. This book is for developers who are new to Codeigniter.  Basic skills in PHP are required.

You can download codeigniter on their website - http://codeigniter.com/download.php

There's a video tutorial and user guide on Codeigniter website for beginners:

How to block SQL injection?

You can block this by using ENCRYPTION.

For PHP users, i recommend to use MD5 encryption, advantage is that md5 is a one way encryption which is hard for hackers to decode and already available via PHP syntax MD5(var)=MD5(var).

Usually, SQL injection are injected on the login page by typing SQL statement on either username or password.. to do this, they just have to type in SQL like this.. "test' or 1=1 or ''='".

Without using MD5 or any other encryption in your sql statement to validate the credentials, access to the site will be allowed.. this is because hackers knows how to manipulate SQL and by just using "OR" on SQL statement, access will be allowed. hackers expected that you will do a normal SQL statement to validate credentials, and by entering SQL statement "test' or 1=1 or ''='" will usually result into this SQL "select 1 from table_name where username='test' or 1=1 or ''=''".

To prevent this from happening, you can use md5 or any other encryption. encrypt all the input parameters when passing to SQL statement for validation, and of course, encrypt the field name equated to the username and password to validate either valid or not. by doing that, your site will be safe for injection that is because there's no way that hackers can form as SQL statement out of encrypted parameters, especially if your encryption is MD5.

To explain further, your SQL statement at the back will be something like this.. "select 1 from table_name where md5(username)=md5('test\' or 1=1 or \'\'=\'').." in which by this time, will not be allowed and problem solved.

Hope this help.

The best social bookmarking widget now a days..

Social bookmarking widgets have really helped reduce clutter on web pages.

Not long ago, it was not uncommon to find bloggers putting a dozen different icons under their blog posts hoping that people would click these buttons to spread their content on the web. But as the number of social sites grew on the Internet, these numerous buttons were replaced with all-in-one widgets that not only offered more features but were easy to maintain as well.

share icon The idea is that instead of confusing your site visitors with icons of 16 different social bookmarking sites, you show them a single Share icon and they can choose the social service they want to use to save, share or bookmark your content.

Which Social Bookmarking & Sharing widget is right for your site?

The three most popular social bookmarking and sharing widgets on Internet are from Share This, Add This and Add to Any. Another service that’s relatively new but worth a mention is Tell a Friend.

Before we actually compare the features of these services, take a look at the graphic above to get some idea about the appearance of these widgets. Or you may visit this dummy page and try out any of these social sharing services.
AddThis.com

AddThis gives you complete control over the appearance and layout of the widget. You can arrange the icons in a single vertical column or put them in a horizontal strip or, if you are comfortable with CSS, you can even go for more complex hover animations.

In addition to sharing your web pages on social networks, your site visitors can also use the AddThis widget to print content or for adding the page to their browser bookmarks.

AddThis provides several analytics reports so you know what content is getting shared and what social services are most popular among your visitors. And there’s an option to add your brand name to the widget as well.

Almost every US government website (include the Whitehouse blog) uses AddThis for social sharing.
ShareThis.com

One of the unique points about the ShareThis widget is that remembers what you share. That means if you vote for a story on Digg or share a link on Twitter or stumble some page, the service will auto-save a log of all this activity into your ShareThis account. The sharing widget is available as a bookmarklet as well and this is handy for browsers like Google Chrome that don’t support add-ons.

On the publisher side, ShareThis is the only service that will allow you site visitors to share content through SMS text messages in addition to email and AIM. Though the default look of the ShareThis widget cannot be changed, you can choose which social services should be available inside the widget and their display order.

Like AddThis, ShareThis too provides detailed analytics so you can find out what people are sharing and how.
AddToAny.com

There are at least 50 different social networks and bookmarking websites on the Internet so how do you decide services that should be included in the sharing widget on your website? For instance, delicious is the most popular bookmarking service but some of your visitors could also be using Diigo or Mister-Wong so what do you do in this case? Show them both or toss a coin and pick one?

Well, the AddToAny button provides an excellent solution to this very problem. The service automatically detects social services that your visitors use and places them first in the widget. The detection mechanism is pretty good and I guess it does this by reading the browser history of visitors.

Another advantage of AddToAny is that it automatically uses your Google Analytics account for reporting. That means if you have the Google Analytics code on a page that also uses the Add To Any widget, the sharing statistics of that page will be collected just like your other Analytics data.

The layout of the Add To Any widget isn’t customizable though advanced users can hide individual tabs or even change the color scheme using CSS hacks.
Tell-A-Friend.com

With Tell-a-Friend, your site visitors can share your content with their IM buddies on Google Talk, Yahoo! Messenger, AOL and MSN/Windows Live Messenger. You can rearrange the tab order in the widget and also choose which social services should be part of the individual tabs. The service also offers a paid option incase you like to brand the widget and email message with a custom logo.

For some reason, the TAF widget on the dummy page isn’t working in IE 8 or Firefox 3.5 but I used the one on NDTV.com and their email sharing feature is pretty impressive.

Conclusion:

All the services discussed above have something unique to offer. Here’s what I would suggest:

If you are looking to customize the widget heavily or plan to use your own social bookmarking icons so that the widget on your site looks a bit different from the rest, AddThis is a perfect choice.

If you want to offer readers an option to share content via text messages or need a widget that is extremely easy to setup and also looks elegant, go with ShareThis.

The Add To Any widget is again a good choice because site visitors get to see the service they frequently use right on top but the email sharing feature in this widget will open in another window.

Tell-A-Friend is the only service that offers sharing via popular instant messaging clients, the widget also includes a rich HTML email client so visitors can add notes to their shares but the free version of TAF doesn’t offer analytics and the widget UI can be a bit confusing for new users.

http://www.labnol.org/internet/sharing-widgets-for-websites/9249/

Setting up a MEEBO bar for your website.

First, you have to create an account from MEEBO website - http://www.meebo.com/websites/. Supply all the details needed, then agree to the terms and conditions of the site. Input the site name and URL of your website.

If you host your own site, you'll have to edit the template for your Web site in order to add the Meebo Bar. Most blog platforms have a setting for edit HTML or edit template where you can modify the code directly.

1. In your template, immediately following the opening <body> tag, insert the following code:

<script type="text/javascript">
if (typeof Meebo == 'undefined') {
Meebo=function(){(Meebo._=Meebo._||[]).push(arguments)};
(function(q){
var args = arguments;
if (!document.body) { return setTimeout(function(){ args.callee.apply(this, args) }, 100); }
var d=document, b=d.body, m=b.insertBefore(d.createElement('div'), b.firstChild), s=d.createElement('script');
m.id='meebo'; m.style.display='none'; m.innerHTML='<iframe id="meebo-iframe"></iframe>';
s.src='http'+(q.https?'s':'')+'://'+(q.stage?'stage-':'')+'cim.meebo.com/cim/cim.php?network='+q.network;
b.insertBefore(s, b.firstChild);

})({network:'codewaresoftwaredevelopment_lo05vi'});
Meebo('makeEverythingSharable');
}
</script>


2. In your template, immediately prior to the closing </body>, insert the following code:

<script type="text/javascript">
Meebo("domReady");
</script>


3. Save your changes and publish your site.

Creating a twitter widget for your website

Copy the snippet inside <body></body> tag of your page, then change the username parameter on setUser call function.

You can also customize the look by changing the parameters under shell, tweets, and features. Ex. paulgonzaga

<script src="http://widgets.twimg.com/j/2/widget.js"></script> <script> new TWTR.Widget({ version: 2, type: 'profile', rpp: 3, interval: 6000, width: 'auto', height: 600, theme: { shell: { background: '#adadad', color: '#ffffff' }, tweets: { background: '#ffffff', color: '#2b2b2b', links: '#0735eb' } }, features: { scrollbar: false, loop: false, live: false, hashtags: true, timestamp: true, avatars: false, behavior: 'default' } }).render().setUser('paulgonzaga').start(); </script>

How to drop all tables in MYSQL via console

On your console, just type the script below supplying the root access credentials [HOST], [USERNAME], [PASSWORD], and [DATABASE] to access the server.

mysqldump -h [HOST] -u [USERNAME] -p[PASSWORD] --add-drop-table --no-data [DATABASE] | grep ^DROP | mysql -h [HOST] -u [USERNAME] -p[PASSWORD] [DATABASE]

Leadership 101


  • Leadership demands sacrifices for the near-term to receive lasting benefits. the longer we wait to make sacrifices, the harder they become. Successful people make important decisions early in their life, then manage those decisions the rest of their lives.
  • Growth does not happen by chance. If you want to be sure to grow, you need a plan something strategic, specific, and scheduled. it's a discipline that would need incredible determination from us.
  • Success comes by going the extra mile, working the extra hours, and investing the extra time. The same is true for us. If we want to get to excel in any segment of life, a little extra effort can help. Our efforts can go a long way if we only work a little smarter, listen a little better, push a little harder, and persevere a little longer.
  • Making a difference in your work is not about productivity; it's about people. When you focus on others and connect with them, you can work together to accomplish great things.
  • Envision a goal you'd like to reach. Make it big enough to scare you a little. Now write down a plan for moving toward it. Create mini-goals within the big goal, to set yourself up for continual progress. And include some risks, too. Set yourself up for success.
  • Leaders build margins, not image. A leader may be forced to take unpopular stands for the good of the company. Popularity isn't bad, but decisions made solely on the basis of popular opinion can be devastating. So take courage and make the right though sometimes painful choices.