10 awesome things to do with cURL

cURL, and its PHP extension libcURL, are tools which can be used to simulate a web browser. In fact, it can for example, submit forms. In this article, I’m going to show you 10 incredible things that you can do using PHP and cURL.

 

1 – Update your Facebook status

Wanna update your facebook status, but don’t want to go to facebook.com, login, and finally being able to update your status? Simply save the following code on your server, define the variables, and voilà!
/*******************************
* Facebook Status Updater
* Christian Flickinger
* http://nexdot.net/blog
* April 20, 2007
*******************************/

$status = 'YOUR_STATUS';
$first_name = 'YOUR_FIRST_NAME';
$login_email = 'YOUR_LOGIN_EMAIL';
$login_pass = 'YOUR_PASSWORD';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://login.facebook.com/login.php?m&next=http%3A%2F%2Fm.facebook.com%2Fhome.php');
curl_setopt($ch, CURLOPT_POSTFIELDS,'email='.urlencode($login_email).'&pass='.urlencode($login_pass).'&login=Login');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "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_exec($ch);

curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/home.php');
$page = curl_exec($ch);

curl_setopt($ch, CURLOPT_POST, 1);
preg_match('/name="post_form_id" value="(.*)" \/>'.ucfirst($first_name).'/', $page, $form_id);
curl_setopt($ch, CURLOPT_POSTFIELDS,'post_form_id='.$form_id[1].'&status='.urlencode($status).'&update=Update');
curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/home.php');
curl_exec($ch);
?>

The jQuery UI CSS Framework

jQuery UI includes a robust CSS Framework designed for building custom jQuery widgets. The framework includes classes that cover a wide array of common user interface needs, and can be manipulated using jQuery UI ThemeRoller. By building your UI components using the jQuery UI CSS Framework, you will be adopting shared markup conventions and allowing for ease of code integration across the plugin community at large.

Framework Classes

The following CSS classes are split between ui.core.css and ui.theme.css, depending on whether styles are fixed and structural, or themeable (colors, fonts, backgrounds, etc) respectively. These classes are designed to be applied to User Interface elements to achieve visual consistency across an application and allow components to be themeable by jQuery UI ThemeRoller.

What is jQuery UI?

jQuery UI is a widget and interaction library built on top of the jQuery JavaScript Library, that you can use to build highly interactive web applications. This guide is designed to get you up to speed on how jQuery UI works. Follow along below to get started.

Read more on 

Micromax Andro A60 previewed in India

  • Micromax Andro A60 previewed in India

    Micromax Andro A60 previewed in India

    Samir Makwana, Nov 27, 2010 1622 hrs IST

    Running Android 2.1 Andro offers 3.2 megapixel camera, Wi-Fi, GPS and 2.8-inch full touchscreen

Yesterday, we reported about Micromax to unveil its first Android phone - Andro. Now concrete details about Micromax Andro smartphone running Google Android 2.1 Eclair update come from Micromax Delhi Bloggers Meet. Micromax Andro A60 is a full touch-screen smartphone that will feature 2.8-inch touch screen. Sporting a 600MHz CPU this Android smartphone will be available in India starting next month for a price of less than Rs. 8000. We'll try to get the exact figure but it s certainly will be less that that figure. 

Coming from India s third largest mobile phone vendor, Micromax Andro takes a leap into Android phones under Rs. 10,000 bracket. Andro has 2.8-inch touchscreen supporting 320x240 pixel resolution which might not please the mobile fanatics but average joe might be happy with it. With dual-band GSM support this smartphone will be 3G ready and promises up to 7.2Mbps speeds via HSUPA and up to 5.76 speeds via HSDPA. Micromax has added even Wi-Fi for wireless connectivity but there was no mention of Bluetooth.  

Micromax s Android debut Andro comes with GPS which is quite interesting for an Android handset priced for less than 8K.With measly 150MB internal memory one can add up to 32GB memory card. The phone offers 3.2 megapixel camera with Auto-focus. You can also record video but don t expect amazing quality. Andro A60 will also sport Accelerometer and gravity sensor for users to enjoy the light weight Android-platform based games

Most worrisome part of Andro A60 is the 1280 mAh Lithium-Ion battery that promises just 4 hours of talk time. Now I am not sure if this is going to be a Dual-SIM phone. But it may get some attraction from users to check out the new operating system - Android. Only after getting our hands on to Andro A60 we can say whether it would be a worth competitor to Samsung Galaxy 5 GT-i5503. Slowly, Android is tapping the entry-level mobile phone segment. At the bloggers meet, Micromax also talked about launching 3.5-inch touchscreen bearing Android handset and also a 7-inch tablet. The price of both these devices would be comparatively affordable.

Some RIM Sales Staff Now Call Apple Home

By STUART WEINBERG
TORONTO—Apple Inc. isn't only poaching corporate customers from BlackBerry maker Research In Motion Ltd., it's poaching members of RIM's enterprise sales team.
In the past 18 months, at least five members of RIM's enterprise-sales team have left the company to join Apple. This includes Geoff Perfect, who served as head of strategic sales at RIM for nearly five years before leaving in April 2009 and joining Apple a month later as head of enterprise iPhone sales, according to LinkedIn, the online networking service for professionals.
In January, Joe Bartlett, Steve Marshall and Peter Decker all left RIM after working there for about four years, according to LinkedIn. Messrs. Bartlett and Marshall joined Apple a month later, while Mr. Decker joined them in February. Mr. Decker was a global account manager at RIM, Mr. Bartlett was a senior global sales manager and Mr. Marshall was a global strategic account manager, according to Linkedin.
At Apple, Mr. Bartlett sells iPhones and iPads to companies in the New England region, while Messrs. Marshall and Decker are listed as iPhone sales reps for the Greater New York City area, according to LinkedIn.
In June, Paul Alvarez left RIM after working five years as a global strategic account manager, according to his LinkedIn profile. He joined Apple the same month and is listed on LinkedIn as working in enterprise iPad and iPhone sales in Canada.
An Apple spokesman confirmed all five individuals are working in enterprise sales at Apple, but declined to comment beyond that. Officials from RIM weren't available to comment.
The movement of personnel from RIM to Apple underscores Apple's aggressive push into the corporate-smartphone market, which RIM has dominated. On its fourth-quarter earnings call in October, Apple Chief Financial Officer Peter Oppenheimer said more than 80% of Fortune 500 companies are deploying or piloting the iPhone.
On that same call, Apple Chief Executive Steve Jobs triggered a war of words with RIM co-Chief Executive Jim Balsillie by taking several swipes at RIM during the call. For instance, Mr. Jobs noted the iPhone outsold the BlackBerry in RIM's corresponding quarter and he questioned the viability of 7-inch tablet computers, which include RIM's upcoming PlayBook. Apple's iPad tablet is 9.7 inches.
Mr. Balsillie responded the next day, saying among other things, that Apple lives in a "distortion field" and that 7-inch tablets will be a big portion of the tablet market.
"Any time you have one company with a lot of momentum in a hot space you're going to have a battle for talent because the guys that are growing really quickly are going to want to get the best and the brightest in the space to help them grow," said Chris Albinson, managing director of Panorama Capital, a Silicon Valley-based venture capital firm.
Mr. Albinson said the battle for talent isn't unique to RIM and Apple, noting that, earlier this month, Google Inc., the Mountain View, Calif. search-engine giant, gave a 10% pay hike to its 23,000 employees as it battles rivals like Facebook Inc. to secure talent.
As for RIM, despite losing a senior executive to Apple, as well as several members of its enterprise-sales team, the Waterloo, Ontario, company continues to hire aggressively. For instance, RIM is advertising for 900 jobs in the Americas, and nearly 300 jobs in other regions, according to information on the careers section of its website.

Apple MacBook gains are others' losses

If the new MacBooks are the "future of notebooks," as Apple CEO Steve Jobs proclaimed, that future is off to a good start. For Apple, that is.
New MacBook Air
New MacBook Air
(Credit: Apple)
ChangeWave Research said this week that Apple is seeing a surge of interest in its MacBooks, driven by the two MacBook Air lines announced in October. A whopping 36 percent of buyers planning to buy laptops say they'll purchase a MacBook, a jump of 11 points since a previous survey a month ago, ChangeWave said.
"Simply put, it's the highest level of planned laptop buying ever for Apple in a ChangeWave survey," the market researcher said.
The plus for Apple is a minus for others. The percentage of consumers who say they'll purchase a Dell laptop has dropped 4 points to 19 percent, since last month, while Hewlett-Packard is also down 4 points to 22 percent, according to ChangeWave.


Read more: http://news.cnet.com/8301-13924_3-20023909-64.html#ixzz16bEEL5j2




Apple's new ultralight MacBook Air models are in demand.
Apple's new ultralight MacBook Air models are in demand.
(Credit: ChangeWave Research)
Netbooks are also suffering. Those tiny 10-inch laptops plummeted 10 points in the last 18 months to 14 percent of those planning to buy a laptop, said ChangeWave.
And Apple seems to be benefiting across the board, extending the brand's appeal to personal gadgets and home entertainment. "In terms of individual electronics items, the Apple iPad Tablet is the clear monster hit this holiday season, with 9 percent saying they'll buy one in the next 90 days," according to ChangeWave. The only category topping the iPad is digital cameras, at 12 percent.
In related news, Apple's worldwide shipments of MacBooks in the fourth quarter are expected to reach a monthly average of 1 million units, with MacBook Air models accounting for 20 percent to 25 percent of the volume, according to Digitimes, citing sources at laptop component suppliers.

google instant

Google Instant is a new search enhancement that shows results as you type. We are pushing the limits of our technology and infrastructure to help you get better search results, faster. Our key technical insight was that people type slowly, but read quickly, typically taking 300 milliseconds between keystrokes, but only 30 milliseconds (a tenth of the time!) to glance at another part of the page. This means that you can scan a results page while you type.
The most obvious change is that you get to the right content much faster than before because you don’t have to finish typing your full search term, or even press “search.” Another shift is that seeing results as you type helps you formulate a better search term by providing instant feedback. You can now adapt your search on the fly until the results match exactly what you want. In time, we may wonder how search ever worked in any other way.

Benefits

Faster Searches: By predicting your search and showing results before you finish typing, Google Instant can save 2-5 seconds per search.
Smarter Predictions: Even when you don’t know exactly what you’re looking for, predictions help guide your search. The top prediction is shown in grey text directly in the search box, so you can stop typing as soon as you see what you need.
Instant Results: Start typing and results appear right before your eyes. Until now, you had to type a full search term, hit return, and hope for the right results. Now results appear instantly as you type, helping you see where you’re headed, every step of the way.

There's more on TV than television.

 

Search your television

Type in what you want to watch, and we'll find it for you. Google TV lets you seamlessly search all of the content on your TV, the web, and apps – then access it with a single click. You can also easily switch between TV and the web without having to change inputs on your television.

jQuery Mobile: Touch-Optimized Web Framework for Smartphones & Tablets

A unified user interface system across all popular mobile device platforms, built on the rock-solid jQuery and jQuery UI foundation. Its lightweight code is built with progressive enhancement, and has a flexible, easily themeable design

Google Maps JavaScript API V2 Services

The Google Maps API is regularly extended, adding new functionality and features that are often released on maps.google.com first. This section covers these services. Note: because the definition of a "service" is somewhat elusive, this section is somewhat of a catch-all. Basically, this section is where we put all of those neat things that we couldn't put anywhere else.
Decision PointsDecision Points














































jQuery.noConflict()

jQuery.noConflict( [ removeAll ] )

removeAllA Boolean indicating whether to remove all jQuery variables from the global scope (including jQuery itself).
Many JavaScript libraries use $ as a function or variable name, just as jQuery does. In jQuery's case, $ is just an alias for jQuery, so all functionality is available without using $. If we need to use another JavaScript library alongside jQuery, we can return control of $ back to the other library with a call to $.noConflict():


This technique is especially effective in conjunction with the .ready() method's ability to alias the jQuery object, as within callback passed to .ready() we can use $ if we wish without fear of conflicts later:


If necessary, we can free up the jQuery name as well by passing true as an argument to the method. This is rarely necessary, and if we must do this (for example, if we need to use multiple versions of the jQuery library on the same page), we need to consider that most plug-ins rely on the presence of the jQuery variable and may not operate correctly in this situation.

Examples:

Example: Maps the original object that was referenced by $ back to $.

jQuery.noConflict();
// Do something with jQuery
jQuery("div p").hide();
// Do something with another library's $()
$("content").style.display = 'none';

Example: Reverts the $ alias and then creates and executes a function to provide the $ as a jQuery alias inside the functions scope. Inside the function the original $ object is not available. This works well for most plugins that don't rely on any other library.

jQuery.noConflict();
(function($) { 
  $(function() {
    // more code using $ as alias to jQuery
  });
})(jQuery);
// other code using $ as an alias to the other library

Example: You can chain the jQuery.noConflict() with the shorthand ready for a compact code.

jQuery.noConflict()(function(){
    // code using jQuery
}); 
// other code using $ as an alias to the other library

Example: Creates a different alias instead of jQuery to use in the rest of the script.

var j = jQuery.noConflict();
// Do something with jQuery
j("div p").hide();
// Do something with another library's $()
$("content").style.display = 'none';

Example: Completely move jQuery to a new namespace in another object.

var dom = {};
dom.query = jQuery.noConflict(true);

Result:

// Do something with the new jQuery
dom.query("div p").hide();
// Do something with another library's $()
$("content").style.display = 'none';
// Do something with another version of jQuery
jQuery("div > p").hide();

Top 10 MySQL Mistakes Made By PHP Developers

The Gift

1. Using MyISAM rather than InnoDB

MySQL has a number of database engines, but you're most likely to encounter MyISAM and InnoDB.
MyISAM is used by default. However, unless you're creating a very simple or experimental database, it's almost certainly the wrong choice! MyISAM doesn't support foreign key constraints or transactions, which are essential for data integrity. In addition, the whole table is locked whenever a record is inserted or updated; this causes a detrimental effect on performance as usage grows.
The solution is simple: use InnoDB.


2. Using PHP's mysql functions

PHP has provided MySQL library functions since day one (or near as makes no difference). Many applications rely on mysql_connect, mysql_query, mysql_fetch_assoc, etc. but the PHP manual states:
If you are using MySQL versions 4.1.3 or later it is strongly recommended that you use the mysqli extension instead.
mysqli, or the MySQL improved extension, has several advantages:
  • an (optional) object-oriented interface
  • prepared statements (which help prevent SQL-injection attacks and increase performance)
  • multiple statements and transaction support
Alternatively, you should consider PDO if you want to support multiple databases.



3. Not sanitizing user input

This should probably be #1: never trust user input. Validate every string using server-side PHP -- don't rely on JavaScript. The simplest SQL injection attacks depend on code such as:
$username = $_POST["name"];

$password =
$_POST["password"];

$sql = "SELECT userid 
        FROM usertable 
        WHERE username='$username' 
        AND password='$password';";

// run query...
This can be cracked by entering "admin'; --" in the username field. The SQL string will equate to:

SELECT userid 
  FROM usertable 
  WHERE username='admin';
The devious cracker can log in as "admin"; they need not know the password because it's commented out of the SQL.

4. Not using UTF-8

Those of us in the US, UK, and Australia rarely consider languages other than English. We happily complete our masterpiece only to find it cannot be used elsewhere.
UTF-8 solves many internationalization issues. Although it won't be properly supported in PHP until version 6.0, there's little to prevent you setting MySQL character sets to UTF-8.


5. Favoring PHP over SQL

When you're new to MySQL, it's tempting to solve problems in the language you know. That can lead to unnecessary and slower code. For example, rather than using MySQL's native AVG() function, you use a PHP loop to calculate an average by summing all values in a record-set.
Watch out also for SQL queries within PHP loops. Normally, it's more effective to run a query then loop through the results.
In general, utilize the strengths of your database when analyzing data. A little SQL knowledge goes a long way.

6. Not optimizing your queries

99% of PHP performance problems will be caused by the database, and a single bad SQL query can play havoc with your web application. MySQL's EXPLAIN statement, the Query Profiler, and many other tools can help you find that rogue SELECT.

7. Using the wrong data types

MySQL offers a range of numeric, string, and time data types. If you're storing a date, use a DATE or DATETIME field. Using an INTEGER or STRING can make SQL queries more complicated, if not impossible.
It's often tempting to invent your own data formats; for example, storing serialized PHP objects in string. Database management may be easier, but MySQL will become a dumb data store and it may lead to problems later.

8. Using * in SELECT queries

Never use * to return all columns in a table--it's lazy. You should only extract the data you need. Even if you require every field, your tables will inevitably change.

9. Under- or over-indexing

As a general rule of thumb, indexes should be applied to any column named in the WHERE clause of a SELECT query.
For example, assume we have a usertable with a numeric ID (the primary key) and an email address. During log on, MySQL must locate the correct ID by searching for an email. With an index, MySQL can use a fast search algorithm to locate the email almost instantly. Without an index, MySQL must check every record in sequence until the address is found.
It's tempting to add indexes to every column, however, they are regenerated during every table INSERT or UPDATE. That can hit performance; only add indexes when necessary.

10. Forgetting to back up

It may be rare, but databases fail. Hard disks can stop. Servers can explode. Web hosts can go bankrupt. Losing your MySQL data is catastrophic, so ensure you have automated backups or replication in place.

PHP & Ajax & Jquery Blog: Creating a Dynamic Poll with jQuery and PHP

PHP & Ajax & Jquery Blog: Creating a Dynamic Poll with jQuery and PHP: "When you combine some neat functionality courtesy of PHP with the cleverness of jQuery you can produce some pretty cool results. In this tut..."