Thursday 9 December 2010

10 Principles of the PHP Masters

With PHP’s widespread adoption,it’s almost too easy to find a script or snippet to do exactly what you need. Unfortunately, there’s no filter as to what is a “good practice” and what’s, well… not so good when writing a PHP script. We need trustworthy sources, who have proven they have a solid grasp on the best practices of PHP.

We need PHP masters to show us the best principles to follow for high-grade PHP programming.

 

1. Use PHP Only When You Need it – Rasmus Lerdorf


There’s no better resource than PHP’s creator for knowing what PHP is capable of. Rasmus Lerdorf created PHP in 1995, and since then the language has spread like wildfire through the developer community, changing the face of the Internet. However, Rasmus didn’t create PHP with that intent. PHP was created out of a need to solve web development problems.
And as with many open source projects that have gone on to become popular, the motivation was never philosophical or even narcissistic. It was purely a case of needing a tool to solve real-world Web-related problems. In 1994 the options were fairly limited when it came to Web development tools.

However, you can’t use PHP for everything. Lerdorf is the first to admit that PHP is really just a tool in your toolbox, and that even PHP has limitations.
Use the right tool for the job. I have run across companies that have completely bought into PHP, deploying it absolutely everywhere, but it was never meant to be a general-purpose language appropriate for every problem. It is most at home as the front-end scripting language for the Web.

Trying to use PHP for everything isn’t efficient, and it certainly isn’t the best use of your time as a web developer. Don’t be afraid to to use other languages if PHP isn’t working out for your project.
http://eric.bachard.free.fr/mac/aquavcl/screenshots/july2007/we_need_you/20041021_laMouette-WeNeedYou.png

2. Use Many Tables With PHP and MYSQL for Scalability – Matt Mullenweg


Nobody needs to question Matt Mullenweg’s authority with PHP. He has, (alongside a rabid community), developed the most popular blogging system on the planet: WordPress. After creating WordPress, Matt and company launched the stellar WordPress.com, a free blogging site based on the WordPress MU code base blogging software for multiple blogs. At the time of this writing, WordPress.com hosts over 4 million blogs, and their users have written over 140,000 posts today. (You can see more interesting stats about WordPress.com usage here.)

If anybody knows how to scale a website, it’s Matt Mullenweg. In 2006 Matt gave some insight into WordPress’ database structure and explained why WordPress MU uses a separate MySQL table for each blog, as opposed to using one giant “monolithic” table for all of the blogs.
We tested this approach for MU, but found it was too expensive to scale past a certain point. With monolithic structures you hit a wall based on your hardware. In MU users are divided and can be partitioned easily, for example on WordPress.com we have the users partitioned between 4096 databases, which allows you to scale very cheaply and efficiently to hundreds of thousands and even millions of users and extremely high levels of traffic.

Being able migrate the tables allows the code and ultimately the blogs to run much faster and scale easier. Alongside some heavy caching, and smart database usage, Matt has shown that extremely popular sites like Facebook and WordPress.com can run off of PHP and handle the incredible traffic load.
http://www.databasejournal.com/img/BS_bbdbAccess.gif

3. Never, ever trust your users – Dave Child


Dave Child is the brainchild (teehee) behind the recently renamed Added Bytes (previously ilovejackdaniels.com) website that featured Dave’s excellent cheat sheets for many programming languages. Dave’s worked for many development companies in the UK and has established himself as an authority in the programming world.

Dave offers some sage advice when it comes to writing secure code in PHP: Don’t trust your users. They just might hurt you.
So the cardinal rule of all web development, and I can’t stress it enough, is: Never, Ever, Trust Your Users. Assume every single piece of data your site collects from a user contains malicious code. Always. That includes data you think you have checked with client-side validation, for example using JavaScript. If you can manage that, you’ll be off to a good start. If PHP security is important to you, this single point is the most important to learn.

Dave goes on to give specific examples of secure practices in parts one, two and three of his ‘Writing Secure PHP’ series. But his ultimate takeaway is this:
Finally, be completely and utterly paranoid. If you assume your site will never come under attack, or face any problems of any sort, then when something eventually does go wrong, you will be in massive amounts of trouble. If, on the other hand, you assume every single visitor to your site is out to get you and you are permanently at war, you will help yourself to keep your site secure, and be prepared in case things should go wrong.

http://i163.photobucket.com/albums/t316/chris-bauer/i_trust_you_to_kill_me_larg.jpg

4. Invest in PHP Caching – Ben Balbo


Ben Balbo has been writing for Site Point, a very well respected tutorial site for the likes of developers and designers. He’s on the committee for both the Melbourne PHP User Group and Open Source Developers’ Club, so he knows a thing or two about the language. It’s no surprise with Ben’s background as a PHP developer and trainer that he recommends putting a little more thought and preparation into PHP caching.
If you have a busy and predominantly static web site–such as a blog–that’s managed through a content management system, it will likely require little alteration, yet may benefit from huge performance improvements resulting from a small investment of your time. Setting up caching for a more complex site that generates content on a per-user basis, such as a portal or shopping cart system, will prove a little more tricky and time consuming, but the benefits are still clear.

There are many different techniques for caching in PHP, and Ben touches on a few of the bigger ones in the article, like:

  • cached function calls

  • setting expiry headers

  • caching file downloads in IE

  • template caching

  • Cache_Lite


and many others. Because of the nature of dynamic languages like PHP, caching is critical to store those parts of the page that are accessed frequently and don’t change often.
http://www.planetoftunes.com/computer/c_media/caching.gif

5. Speed up PHP Development with an IDE, Templates and Snippets – Chad Kieffer


When Chad Kieffer isn’t busy rocking user interfaces and administering databases, he’s giving expertise advice from his blog 2 tablespoons. Because of Chad’s wide field of expertise, he’s often able to see the big picture that other programmers might not, specifically when it comes to the holistic approach that Chad takes to developing a website. He specializes in all aspects of the development process, so any insights he can provide with putting together an entire project is going to be useful.

Chad believes that using an IDE like Eclipse PDT (Eclipse’s PHP development package) with a mixture of templates and snippets can really speed up the turnaround time on a project.
Busy schedules, long to do lists, and deadlines make it tough for developers to get familiar with some of the advanced features their tools provide. This is a shame, because some features, like Eclipse Templates, can really reduce coding time and errors.

Common sense says that any time you can automate a task, the quicker you’ll get the project done. The same holds true with Dan’s theory. By taking the time to create templates that you’ll use over and over, you’ll save tons of time automating the repetitive parts of coding.

By using an IDE like Eclipse and the PDT package, you’ll find that your development time will incrementally speed up. The IDE will auto-close brackets, add those missing semicolons and even allow you to debug within the editor, without having to upload to the server. (Chad has a nifty tutorial on getting started with Eclipse PDT and the benefits of an IDE in general, if you’re interested.)
http://blog.xole.net/resources/zend-studio-beta-5.0.png

6. Make Better Use of PHP’s Filter Functions – Joey Sochacki


While Joey Sochacki may not be as big of a name as Matt Mullenweg in the PHP community, he’s a seasoned web developer and shares tips that he’s picked up along the way at his blog Devolio.

Joey has found that even though there is a ton of filtering that has to happen when writing PHP code, not many programmers make use of PHP’s filter functions.
Filtering data. We all have to do it. Most, if not all of us, despise doing it. However, unbeknown to most are PHP’s filter_* functions, that allow us to do all sorts of filtering and validation. Using PHP’s filter_* functions, we can validate and sanitize data types, URLs, e-mail addresses, IP addresses, strip bad characters, and more, all with relative ease.

Filtering can be tricky, but this guide can help immensely. With Joey’s help you’ll learn how to install the filters and and filter nearly anything, taking advantage of the filtering power of PHP.
http://www.potterswithoutborders.com/komasket/cartoon.jpg

7. Use a PHP Framework – Josh Sharp


There has always been a debate as to whether to use a PHP framework like Zend, CakePHP, Code Igniter, or any other framework. There are upsides and downsides to using one, and many developers have their own opinions about whether or not to go down this road.

Josh Sharp is a web developer who makes his bread and butter creating websites for clients. This is why you should trust him when he says it’s a good idea to use a PHP framework to save time and eliminate mistakes when programming. Why? Josh believes it’s because PHP is too easy to learn.
But PHP’s ease of use is also its downfall. Because there are less restrictions on the structure of the code you write, it’s much easier to write bad code. But there is a solution: use a framework.

PHP frameworks help standardize how you program, and can save lots of time in the development process. You can read more about the benefit of using a PHP framework at Josh’s blog.
http://www.webdevelopment2.com/wp-content/uploads/what-do-you-look-for-in-a-php-framework-graph.png

8. Don’t use a PHP Framework – Rasmus Lerdorf


Contrary to Josh’s belief that one should use a PHP framework, Rasmus Lerdorf, the Godfather of PHP himself, believes that frameworks aren’t that great. Why? Because they perform much slower than simple PHP.

During Rasmus’ presentation at Drupalcon 2008, Rasmus compared the response times to a PHP page with a simple “Hello World” example, and compared it to a few PHP frameworks (slides 24-32), and showed that PHP frameworks are much slower than straight PHP.

You can listen or watch the entire presentation where Rasmus shows the performance losses with PHP frameworks. In short, Rasmus shows that performance takes a major hit when you use a PHP framework as opposed to using pure PHP.

[Note: If you have to use a PHP framework, Rasmus likes Code Igniter the best, as it is "least like a framework"]

http://www.fmft.net/EU%20Constitution%20EU%20Treaty%20Referendum%20Mr%20Free%20Market%20I%20Say%20No%20Free%20Market%20Fairy%20Tales.JPG

9. Use Batch Processing – Jack D. Herrington


Jack Herrington is no stranger to PHP and the development world. On top of writing over 30 articles for the prestigious IBM developerWorks, Jack has also published programming books like PHP Hacks. Jack is a bona fide expert.

Herrington recommends using batch processing and cron to tackle those tasks that can process in the background. Web users don’t want to wait long for tasks to complete on the web. There are some jobs that take longer that are much more suited to being done in the background.
Certainly, in some small cases, it’s a bit easier to fire off of a helper thread to handle small jobs. But it’s easy to see that with the use of conventional tools — cron, MySQL, standard object-oriented PHP, and Pear::DB — creating batch jobs in PHP applications is easy to do, easy to deploy, and easy to maintain.

Jack believes in simplicity, and instead of using threading on servers, he uses the simple combination of cron, PHP and MySQL to process tasks in the background.
I’ve done both, and I think cron has the advantage of the “Keep It Simple, Stupid” (KISS) principle. It keeps the background processing simple. Instead of having a multithreaded job-processing application that runs forever and, thus, can never leak memory, you have a simple batch script that cron starts. The script determines whether there’s anything to do, does it, then exits. No need to worry about memory leaks. No need to worry about a thread stalling or getting caught in an infinite loop.

http://publib.boulder.ibm.com/infocenter/zoslnctr/v1r7/topic/com.ibm.zconcepts.doc/zOSB003-0.gif

10. Turn on Error Reporting Immediately – David Cummings


David Cummings runs his own software company that specializes in content management systems, and has won several awards. If anyone knows how to develop a PHP application efficiently, it’s Dave.

David wrote in a SitePoint article about the two PHP tips he wished he’d learned in the beginning. One of the tips: Turn on error reporting immediately. It’ll save a great deal of time in the long run.
The single most important thing I tell people who use PHP is to turn error reporting to its maximum level. Why would I want to do this? Generally the error reporting is set at a level that will hide many little things like:

  • declaring a variable ahead of time,

  • referencing a variable that isn’t available in that segment of code, or

  • using a define that isn’t set.

  • These factors might not seem like that big a deal — until you develop structured or object oriented programs with functions and classes. Too often, writing code without error reporting turned up high would cost you hours as you scoured long functions that didn’t work because a variable was misspelled or not accessible.


Error reporting can make finding the reason for an error much easier. A tiny bug in the code can be quickly identified if PHP’s error reporting is turned on high. Save yourself some time and hair pulling by letting PHP find your bugs for you.

http://daringfireball.net/misc/2003/12/php_error_75.png

php – Cannot modify header information – headers already sent by (php header already sent error)

This error comes when you print any thing before php hreader command or sometime single spaces allowed before any file starting place or printing or getting values from $_COOKIE or $_SESSION or set cookie or set session etc…

Example Error Code:
<?php
print “text”;
header(‘Location: http://www.example.com/’);
?>

Solution :

<?php
function JSRedirection($url)
{?>
<script type=”text/javascript”>
<!–
window.location = “<?=$url?>”
//–>
</script>
<?}
print “test”;
JSRedirection(“http://www.example.com/”);

?>

Above is by use of js redirect function. But we can solved it by php functions only.

Example 1:

<?php
header("location: 1.html");
header("location: 2.html"); //replaces 1.html
?>


This redirects to 2.html since the second header replaces the first.

Example 2:

<?php
header("location: 1.html");
echo "send data";
header("location: 2.html"); //1.html already sent
?>


This redirects to 1.html since the header is sent as soon as the echo happens. You also won't see any "headers already sent" errors because the browser follows the redirect before it can display the error.

Example 3:

<?php
ob_start();
header("location: 1.html");
echo "send data";
header("location: 2.html"); //replaces 1.html
ob_end_flush(); //now the headers are sent
?>


Wrapping the previous example in an output buffer actually changes the behavior of the script! This is because headers aren't sent until the output buffer is flushed.

OR

Need to write <?php ob_start(); ?> at first line of html part when you main body is common for all pages.

like:

<?php ob_start(); ?>

<html> ……  <?php include_once “<included part of files >”;  ?>  …… </html>

Monday 22 November 2010

Few Useful Sites To Subscribe

Here I am listing few of the very useful information/resource providing sites that keeps you awake about the things in current trends to buisness,social media, market, entrepreneurship , design , technology.

http://techcrunch.com/
http://sanderssays.typepad.com/sanders_says/
http://www.smashingmagazine.com/
http://sethgodin.typepad.com/seths_blog/
http://dilbert.com/
http://www.leadershipnow.com/leadingblog/
http://www.ted.com/
http://www.spring.org.uk/
http://www.fastcompany.com/
http://www.boomberg.com/
http://www.ft.com

Please add your comment if I missed any important site.

 

Web 2.0 Vs Web 1.0


  • Web 2.0 is about communities, Web 1.0 was about companies

  • Web 2.0 is about blogs, Web 1.0 was about home pages

  • Web 2.0 is about peer to peer, Web 1.0 was about client-server

  • Web 2.0 is about XML, Web 1.0 was about HTML

  • Web 2.0 is about writing, Web 1.0 was about reading

  • Web 2.0 is about tags, Web 1.0 was about taxonomy

  • Web 2.0 is about wireless, Web 1.0 was about wires

  • Web 2.0 is about sharing, Web 1.0 was about owning

  • Web 2.0 is about RSS, Web 1.0 was about portals

  • Web 2.0 is about trade sales, Web 1.0 was about IPOs

  • Web 2.0 is about web applications, Web 1.0 was about web forms

  • Web 2.0 is about APIs, Web 1.0 was about screen scraping

  • Web 2.0 is about broadband, Web 1.0 was about dialup

  • Web 2.0 is about bandwidth costs, Web 1.0 was about hardware costs

  • Web 2.0 is about Google, Web 1.0 was about Netscape


 

Thursday 18 November 2010

PHP Add and Remove Querystring Variables

function add_querystring_var($url, $key, $value) {

$url = preg_replace('/(.*)(\?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&');

$url = substr($url, 0, -1);

if (strpos($url, '?') === false) {

return ($url . '?' . $key . '=' . $value);

} else {

return ($url . '&' . $key . '=' . $value);

}

}

 

function remove_querystring_var($url, $key) {

$url = preg_replace('/(.*)(\?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&');

$url = substr($url, 0, -1);

return ($url);

}

EXE in PHP (Make Executable or Make Desktop Application in PHP)

Hello Friends,

I m a web developer and i always use PHP as web scripting server side language but before some days when i found that now it is possible to make EXE in PHP means now you can make Executable or make Desktop application by PHP. Isn’t it Great?

There are many complier available on web by which you can create EXE in PHP.

This program runs through dos and windows only,I don’t know About Linux.If you want to make Executable in PHP then firstly download PHP EXE Compiler/Embedder from Here.

Try to explain you some more things about this.

 

1.First Download zip from Here.

2. Now unzip it and open Command prompt and then go to its directory.

3. Start > run… ‘cmd’
4. Use the “cd..” command to change directory.

5. Place PHP script to be compiled next to bamcompile.exe (same directory)
6. in the cmd prompt, at that directory, type:
ex: “bamcompile test.php”
variations:
“bamcompile -c test.php” gives compression.
-e:something.dll allows a DLL to be embedded

Readymade examples are given in Zipped files which you have downloaded, just try it out.

Monday 15 November 2010

MySQL Table Types



MySQL supports various of table types or storage engines to allow you to optimize your database. The table types are available in MySQL are:

  • ISAM

  • MyISAM

  • InnoDB

  • BerkeleyDB (BDB)

  • MERGE

  • HEAP


The most important feature to make all the table types above distinction is transaction-safe or not. Only InnoDB and BDB tables are transaction safe and only MyISAM tables support full-text indexing and searching feature. MyISAM is also the default table type when you create table without declaring which storage engine to use. Here are some major features of each table types:

ISAM


ISAM had been deprecated and removed from version 5.x. All of it functionality entire replace by MyISAM. ISAM table has a hard size 4GB and is not portable.

MyISAM


MyISAM table type is default when you create table. MyISAM table work very fast but not transaction-safe. The size of MyISAM table depends on the operating system and the data file are portable from system to system. With MyISAM table type, you can have 64 keys per table and maximum key length of 1024 bytes.

InnoDB


Different from MyISAM table type, InnoDB table are transaction safe and supports row-level locking. Foreign keys are supported in InnoDB tables. The data file of InnoDB table can be stored in more than one file so the size of table depends on the disk space. Like the MyISAM table type, data file of InnoDB is portable from system to system. The disadvantage of InnoDB in comparison with MyISAM is it take more disk space.

BDB


BDB is similar to InnoDB in transaction safe. It supports page level locking but data file are not portable.

MERGE


Merge table type is added to treat multiple MyISAM tables as a single table so it remove the size limitation from MyISAM tables.

HEAP


Heap table is stored in memory so it is the fastest one. Because of storage mechanism, the data will be lost when the power failure and sometime it can cause the server run out of memory. Heap tables do not support columns with AUTO_INCREMENT, BLOB and TEXT characteristics.


 

Tuesday 2 November 2010

Send mail from your localhost

Hello Friends !!

When you developing your site then you are facing a problem that how to send mail from your local host ?

Because when you are testing your project/site in localhost then this problem occurred. At that time you think about upload your site on server.

If you don’t want this type of uploading work and you want to test your mail form your localhost then here is the solution.

First of all open your xamp or wamp installed directory.

Then open php directory and find php.ini.

Then open this php.ini in notepad and find [mail function] in that file.

When you find it, remove semi colon before SMTP,smtp_port and sendmail_from.

Set this parameters like this :

SMTP=mail.test.com  //it indicates mail server

smtp_port=25            // it indicates port address

sendmail_from=test@test.com   // it indicates mail id from which you want to send mail

After this, please stop you xamp/wamp services, do refresh and start it again.

Thats it.. Now you can send mail from your localhost..

If you have any query or any confusion then feel free to comment me.

Thanks !!

[PHP] Email Attachment – PDF In Email Attachment

Hi Friends , yesterday I was working with email attachment and I wanted to send pdf file as email attachment but It was giving me so many problems. I have searched so many code for PDF attachment but no one was working So I start tp debug code and finally  made working pdf attachment code by pdf attachment in email worked successfully.

<?php



$fileatt = "test.pdf"; // Path to the file

$fileatt_type = "application/pdf"; // File Type

$fileatt_name = "test.pdf"; // Filename that will be used for the file as the attachment

$email_from = "noreply@hackingethics.com"; // Who the email is from

$email_subject = "Your attached file"; // The Subject of the email

$email_message = "Thanks for visiting <a href="http://www.hackingethics.com/" target="_blank" title="More about HackingEthics »">HackingEthics</a>.com! <br>";

$email_message .= "Thanks for visiting.<br>"; // Message that the email has in it

$email_to = "xyz@gmail.com"; // Who the email is to

$headers = "From: ".$email_from;

$file = fopen($fileatt,'rb');

$data = fread($file,filesize($fileatt));

fclose($file);

$semi_rand = md5(time());

$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

$headers .= "\nMIME-Version: 1.0\n" .

"Content-Type: multipart/mixed;\n" .

" boundary=\"{$mime_boundary}\"";

$email_message .= "This is a multi-part message in MIME format.\n\n" .

"--{$mime_boundary}\n" .

"Content-Type:text/html; charset=\"iso-8859-1\"\n" .

"Content-Transfer-Encoding: 7bit\n\n" .

$email_message .= "\n\n";

$data = chunk_split(base64_encode($data));

$email_message .= "--{$mime_boundary}\n" .

"Content-Type: {$fileatt_type};\n" .

" name=\"{$fileatt_name}\"\n" .

//"Content-Disposition: attachment;\n" .

//" filename=\"{$fileatt_name}\"\n" .

"Content-Transfer-Encoding: base64\n\n" .

$data .= "\n\n" .

"--{$mime_boundary}--\n";

$sent = @mail($email_to, $email_subject, $email_message, $headers);

if($sent) {

echo "Your email attachment has been Worked.";

} else {

die("Sorry but the email could not be sent. Please go back and try again!");

}

?>

Replace your email address in $email_to and filename in $fileatt and $fileatt_name.

 









Integration of Google Map in Websites (PHP,dot net,Java etc)

Hello friends I m a Web Developer so i want to share my knowledge with you.We all know about GoogleMap, now if you want to integrate Google Map in your website or in your client website then i m giving you some tips about Google map integration in website (PHP,.NET,Java etc).

To integrate Google Map in Website then firstly you have one API key,from this API key you can use Google Map in your website. This API key is Unique for every website (this API key working for all subdirecories in a website,So always use Root directory to get API key ) , so here is the link to generate API key for Google Map. (Click here to Generate API key for Google Map).Now you can check Google Map Documentation for integration in Google Map in Website.you can find all things in this Documentation but But now if you wana some more Stuffs in Google Map like Position Overview,Markers on places,Zoom,Double Click Zoom,To here from Here direction,Markers with info windows,Tabbed Info WIndows,Custom Zoom Slider,Context menus and also Adding your own custom map with examples then i know one more website link which have this all stuffs with simple and sweet examples.You can understand this all examples easily and also you can integrate in your website. (Click here for Google Map integration in Website Tutorial)
If you have any problem in Google Map you can contact me, I will try my best to help you in Google Map

How to integrate paypal pro in to your php site....

The following code is used to integrate payment module in your site

create one file with name paypal.php [or any name you wish]

paypal.php file contains the following code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>The Popout - Paypal Payment</title>
<link rel="icon" href="favicon.ico" type="image/x-icon" />
<link rel="icon" href="images/1.ico" type="image/x-icon">
<link rel="shortcut icon" href="images/1.ico" type="image/x-icon">
</head>
<body oncontextmenu="return false" onLoad="document.paypal_form.submit();">
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" name="paypal_form">
<input type="hidden" name="image" src="images/payment_sub.gif" border="0" alt="Make payments with PayPal - it's fast, free and secure!">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="business" value="clientpaypalid@clientsite.com"> <!--Value is Client paypal id for his site, it is mandatary-->
<input type="hidden" name="item_name" value="Premium Membership">
<input type="hidden" name="buyer_credit_promo_code" value="1">
<input type="hidden" name="buyer_credit_product_category" value="1">
<input type="hidden" name="buyer_credit_shipping_method" value="1">
<input type="hidden" name="buyer_credit_user_address_change" value="1">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="AUD"> <!--Value is currency code-->
<input type="hidden" name="lc" value="US"> <!--Country code-->
<input type="hidden" name="bn" value="PP-SubscriptionsBF">
<input type="hidden" name="a3" value="<?=$amount?>"> <!--Value is the amount how much you collect from user, this value is mandatary, you can get this value from the hidden filed of previous form you come from or get from passing to the url, best to get from hidden field, if you get from url it is not safe because we give chance to the user to change the amount value-->
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="M">
<input type="hidden" name="src" value="1">
<input type="hidden" name="sra" value="1">
<input type="hidden" name="first_name" value="<?=$firstname?>"> <!--Value for this user details is not mandatary, these fields will be filled in the paypal site if we are not passing. If we pass these values these values will be autofilledin in the paypal site-->
<input type="hidden" name="last_name" value="<?=$lastname?>">
<input type="hidden" name="address1" value="<?=$address?>">
<input type="hidden" name="city" value="<?=$city?>">
<input type="hidden" name="state" id="state" value="<?=$state?>">
<input type="hidden" name="zip" value="<?=$zip?>">
<input type="hidden" name="country" id="country_code" value="<?=$country_code?>">
<input type="hidden" name="H_PhoneNumber" value="<?=$H_PhoneNumber?>">
<input type="hidden" name="email" value="<?=$email?>">
<input type="hidden" name="credit_card_type" id="credit_card_type" value="<?=$credit_card_type?>">
<input type="hidden" name="cc_number" value="<?=$card_num?>">
<input type="hidden" name="expdate_month" value="<?=$exp_month?>">
<input type="hidden" name="expdate_year" value="<?=$exp_year?>">
<input type="hidden" name="cvv2_number" value="<?=$card_code?>">
<input type="hidden" name="return" value="http://www.popout.com.au/dev/paypalstatus.php?msg=success"> <!--this is the page redirecting from paypal site when the user gives all correct details-->
<input type="hidden" name="cancel_return" value="http://www.popout.com.au/dev/paypalstatus.php?msg=failure"> <!--this is the page redirecting from paypal site when the user gives false details-->
<input type="submit" name="submit" value="continue" />
</form>
</body>
</html>

Monday 18 October 2010

How to Read Data From CSV File In PHP

You have data in comma-separated values (CSV) format, for example a file exported from Excel or a database, and you want to extract the records and fields into a format you can manipulate in PHP.

If the CSV data is in a file (or available via a URL), open the file with fopen( )and read in the data with fgetcsv( ). This prints out the data in an HTML table:
$fp = fopen('sample2.csv','r') or die("can't open file");
print "<table>\n";
while($csv_line = fgetcsv($fp,1024)) {
print '<tr>';
for ($i = 0, $j = count($csv_line); $i < $j; $i++) {
print '<td>'.$csv_line[$i].'</td>';
}
print "</tr>\n";
}
print '</table>\n';
fclose($fp) or die("can't close file");



The second argument to fgetcsv( ) must be longer than the maximum length of a line in your CSV file. (Don't forget to count the end-of-line whitespace.) If you read in CSV lines longer than 1K, change the 1024 used in this recipe to something that accommodates your line length.

You can pass fgetcsv( ) an optional third argument, a delimiter to use instead of a comma (,). Using a different delimiter however, somewhat defeats the purpose of CSV as an easy way to exchange tabular data.

Don't be tempted to bypass fgetcsv( ) and just read a line in and explode()on the commas. CSV is more complicated than that, in order to deal with embedded commas and double quotes. Using fgetcsv( ) protects you and your code from subtle errors.

 

Friday 15 October 2010

How Life Changed.......

Here I am sitting in my office @ night…Thinking hard about life

How it changed from a maverick collage life to strict professional life…...

How tiny pocket money changed to huge monthly paychecksbut then why it gives lesss happiness….

How a few local denim jeans changed to new branded wardrobebut then why there are less people to use them

How a single plate of samosa changed to a full Pizza or burgerBut then why there is less hunger…..

How a bike always in reserve changed to bike always onbut then why there are less places to go on……

How a small coffee shop changed to cafe coffee daybut then why its feels like shop is far away…..

How a limited prepaid card changed to postpaid packagebut then why there are less calls & more messages……

How a general class journey changed to Flight journeyBut then why there are less vacations for enjoyment….

How a old assembled desktop changed to new branded laptopbut then why there is less time to put it on……….

How a small bunch of friends changed to office mateBut then why we always feel lonely n miss those college frnz.….

Here I am sitting in my office @ night…Thinking hard about life

How it changed….. How it changed……..

Friday 1 October 2010

આપણે ગુજરાતીઓ.....



આપણે ગુજરાતીઓ .....

હોટેલમાં કોઈ ચા મંગાવે અને ચામાં માખી પડે તો શું થાય…. ?

(1) ચોખ્ખાઈનો આગ્રહી બ્રિટિશર ચા પીધા વગર ભરેલો કપ તરછોડીને જતો રહે.

(2) 'કેર-ફ્રી' સ્વભાવવાળો અમેરિકન ચામાંથી માખી કાઢી ચા પી જાય.

(3) 'ચાલુ' સ્વભાવવાળો ઓસ્ટ્રેલિયન ચા ઢોળી કપ લઈને જતો રહે.

(4) 'ચિત્ર-વિચિત્ર' ખાનારો ચીનો માખી ઊપાડીને ખાઈ જાય.

આ સમયે એક 'મહાન વ્યક્તિ' ત્યાં હાજર હોય તો એ શું કરે ખબર છે? એ 'મહાન' વ્યક્તિ બ્રિટિશર પાસેથી તરછોડેલી ચાના પૈસા લે. એણે તરછોડેલી ચા અમેરિકનને વેચી દે, કપ ઓસ્ટ્રેલિયનને વેચી અને અને માખી ચીનાને વેચી દે! બધાના પૈસા ખિસ્સામાં મૂકી ઘર ભેગો થઈ જાય. આ સોલિડ ગણતરીબાજ મહાન વ્યક્તિ એટલે કોણ ખબર છે ? આ અદ્દભુત, જોરદાર મહાનુભાવ એટલે 'ગુજરાતી' !

આખી દુનિયામાં 'વર્લ્ડ બેસ્ટ વેપારી'નો જેને એવોર્ડ મળેલો છે, તે છે – હું, તમે અને આપણે બધા – 'ગુજરાતીઓ', પણ આપણે માત્ર વેપારી જ નથી, વેપારીથી પણ વિશેષ છીએ. આપણો સ્વભાવ, આપણી આદતો, આપણી ખાસિયતો આપણને બીજાથી નોખાં અને જુદાં બનાવે છે. તો ચાલો આપણે ગુજરાતીઓ કેવા છીએ એની ચર્ચા આજે એરણ ઉપર ચઢાવીએ.

આપણા ભારત દેશનો નકશો જુઓ તો એમાં પશ્ચિમ છેડે હસતાં મોઢાના આકારવાળું રાજ્ય દેખાશે. આ હસતું મોઢું એટલે આપણું ગુજરાત અને તેમાં વસતા સાડા પાંચ કરોડ હસતાં મોઢા એટલે આપણે ગુજરાતીઓ, પણ ગુજરાતીઓ માત્ર ગુજરાતમાં જ વસે છે તે માનવું ભૂલભરેલું છે. ગુજરાતીઓ આખી દુનિયામાં બધે જ ફેલાયેલા છે અને બધી જ જગ્યાએ ધંધો કરી 'બે પૈસા' કમાઈ રહ્યા છે.

વિશ્વપ્રવાસે નીકળવાના શોખીન ગુજરાતીઓમાનો કોઈ સહારાનું રણ જોવા જાય અને ત્યાં તેને ચાની કીટલી ચલાવતો ગુજરાતી મળી જાય તેવું બને ખરું! પેંગ્વિન કે સફેદ રીંછ ઉપર રિસર્ચ કરતો વૈજ્ઞાનિક એન્ટાર્કટિકામાં જાય ત્યારે ત્યાં તેને આઈસ્ક્રીમ પાર્લર ચલાવતો ગુજરાતી મળી જાય એવું પણ બને.

'મનીમાઈન્ડેડ' તરીકે જાણીતા ગુજરાતીઓનો પૈસા કમાવાનો ગાંડો શોખ તેમને દુનિયામાં બધે જ લઈ જાય છે (કાયદેસર કે ગેરકાયદેસર !). તેમાંય ફોરેન જવા માટે ગુજરાતીઓનો સૌથી ફેવરિટ દેશ હોય તો અમેરિકા. જેમ વૈજ્ઞાનિકોને મંગળ કે ચંદ્ર પર જવાનું વળગણ હોય છે તેમ ગુજરાતીઓને કોઈ પણ રીતે અમેરિકા વટી જવાનું વળગણ હોય છે. ત્યાં જઈને ભલે 'કંઈ પણ' કરવું પડે પણ તે માટે તેઓ અહીંયા 'કંઈ પણ' કરવા તૈયાર હોય છે. કેટલાક તો માણસમાંથી 'કબૂતર' બનવા તૈયાર થઈ જાય છે... આ 'કબૂતરો'નું અંતિમ લક્ષ્ય ડૉલરનું ચણ ચણવાનું હોય છે. (કેમકે, એક ડૉલર બરાબર પચ્ચાહ રૂપિયા થાય ને ભઈ!) આને જ રિલેટેડ આપણી એક બીજી આદત પણ છે.

આપણને આપણી ગુજરાતી ભાષા કરતાં અંગ્રેજી ભાષાનું સોલિડ વળગણ છે. યુ નો, આપણે બધા સેન્ટેન્સમાં વિધાઉટ એની રિઝન ઈંગ્લિશ વર્ડઝ ઘૂસાડી દઈએ છીએ. ગમે તેવું ખોટું અને વાહિયાત અંગ્રેજી બોલનારાઓને આપણે બહુ હોશિયાર ગણીએ છીએ. ગુજરાતી સારું બોલતા ના આવડતું હોય તો ચાલે પણ બકવાસ અંગ્રેજી બોલતા તો આવડવું જ જોઈએ તેવો આપણને ભ્રમ પેસી ગયો છે. બે-ચાર ગુજરાતીઓ ક્યાંક ભેગા થાય તો તેમને અંગ્રેજી બોલવાનો એટેક આવે છે. કેટલાક તો અંગ્રેજી છાંટવાળું પહોળાં ઉચ્ચારોવાળું ગુજરાતી બોલતા હોય છે અને તેનો ગર્વ અનુભવે છે.

(ઓ…કખે…ગાય્ઝ એન્ડ ગા…લ્ઝ….હું છું…ત...મા…રો…. દો…સ્ત…ઍન્ડ…હો..સ્ટ… વિનુ…વાહિયાત…. ઍન્ડતમે લિસન કરી રહ્યા છો…રેડિયો ચારસો વીસ…. ઈ…ટ…સ…રો…કિં…ગ…)

આવી રીતે ગુજરાતી ભાષાના 'સિસ્ટર મેરેજ' કરવા બદલ રેડિયો જોકીઓ અને ટીવી પ્રોગ્રામના એન્કરોને તો ખાસ શૌર્યચંદ્રક આપવો જોઈએ. સરસ-મજાની વિપુલ પ્રમાણમાં શબ્દભંડોળ ધરાવતી આપણી માતૃભાષા ગુજરાતીની સૌથી વધુ અવગણના કરતાં હોય તો તે આપણે પોતે જ છીએ. (અંગ્રેજી શીખવામાં કંઈ જ વાંધો નથી, પણ ગુજરાતી ભાષાને બગાડો એ ખોટું ને, ભઈ ?!)

પરદેશી, પરદેશી ભાષા અને તેની સાથે પરદેશના ખોરાકનું પણ ગુજરાતીઓને અજબ-ગજબનું વળગણ છે. આપણે ત્યાં જે ચાઈનીઝ ખવાય છે તેવું જો કોઈ પણ ચીનો ચાખી લે તો આપઘાત જ કરી લે ! સવાસો કરોડ ચીનાઓમાંથી કોઈએ ક્યારેય ના ખાધી હોય તેવી એક ચાઈનીઝ વાનગી અહીંયા મળે છે. એ છે 'ચાઈનીઝ ભેળ'. આપણે ઈટાલીના પિઝાના પણ આવા જ હાલ કરી નાખ્યા છે. મજાની વાત એ છે કે આપણે ત્યાં ઈટાલિયન પિઝાની સાથે જૈન પિઝા અને ફરાળી પિઝા મળે છે! અને તમને કહી દઉં બોસ, હવે મેક્સિકન અને થાઈ ફૂડનો વારો છે! થોડા જ વખતમાં આપણે ત્યાં મેક્સિકન મેંદુવડા અને થાઈ ઠંડાઈ મળતી થઈ જશે. (ટૂંકમાં આપણે વિશ્વની કોઈ પણ વાનગીનું ગુજરાતીકરણ કરવા માટે સક્ષમ છીએ, હોં ભઈ !)

સૌથી વધારે તેલથી લથબથ વાનગીઓ આરોગવાના શોખીન ગુજરાતીઓ ખાવાની સાથે 'પીવા'ના પણ શોખીન છે. આ 'પીવા'નું એટલે શું તે કોઈને સમજાવવાની જરૂર નથી. દારૂબંધી હોવા છતાં પણ અહીંયા ખૂબ 'પીવાય' છે. દૂધવાળા અને શાકવાળાની જેમ દરેક પીનારાનો પોતાનો અંગત સપ્લાયર હોય છે; જે હોમડિલિવરી કરી જાય છે. પીવું એ ગુજરાતીઓ માટે મોટું થ્રીલ છે, જેની સાથે આપણે વીરતાનો ભાવ જોડી દીધો છે. ધોનીને આઠ લિટર દૂધ પીધા પછી જેટલો ગર્વ ન થાય તેટલો આપણને બે પેગ પીધા પછી થતો હોય છે. ગુજરાતીઓ અને તેમના પીવાના શોખ પર લખવા બેસીએ તો એક અલગ લેખ લખવો પડે એટલે આ મુદ્દાને અહીંયા જ બોટમ્સ અપ કરી દઈએ.

ગુજરાતીઓનો જીવનમંત્ર છે ખઈ-પીને સૂઈ જવું. ઘણા તો બપોરે ખાધા પછી ચાર કલાક માટે કામ-ધંધા બંધ કરીને આડા પડખે થઈ જતા હોય છે. ગુજરાતીઓની રાતની સૂવાની એક ખાસિયત તો અદ્દભુત છે. આપણે ધાબે-અગાશીમાં સૂવાના શોખીન છીએ. ઉનાળો શરૂ થતાં વેંત રાત્રે સાડા આઠ-નવ વાગ્યે ગાદલાંના પિલ્લાઓ લઈ ધાબે ધસી જતા ગુજરાતીઓને નિહાળવા એક લહાવો છે. એવું ના માનશો કે આપણે ઉનાળામાં નવ વાગ્યામાં સૂઈ જઈએ છીએ, આ તો આપણે બે કલાક માટે પથારી ઠંડી કરવા મૂકીએ છીએ. ધાબે ઠંડી પથારીઓમાં સૂવાનું કલ્ચર માત્ર આપણા ગુજરાતમાં જ છે એવું અમારું દઢ પણે માનવું છે. (મકાનમાં ઘરફોડ ચોરી થઈ જાય એનો વાંધો નહીં,પણ લાખ રૂપિયાની ઊંઘ ના બગડવી જોઈએ, હોં ભઈ!) આટલું ખઈ-પીને સૂઈ જઈએ એટલે શરીર વધી જ જાય ને! ફાંદાળા પુરુષો અને બરણી આકારની બહેનો ગુજરાતની ધરતીને ધમરોળતી જોવા મળે છે તેનું કારણ આપણા આ શોખ જ છે. એટલે જ આપણે લેંઘા-ઝભ્ભા અને સાડીઓ જેવા 'ફ્લેક્સિબલ' ડ્રેસ અપનાવ્યા છે જેથી શરીર વધે તો પણ કપડાં ટાઈટ પડવાની ચિંતા નહીં.

વધેલા શરીરે ટીવી સામે બેસી રમતગમત જોવાનો પણ આપણે ખૂબ શોખ છે. (આ વાક્યમાં રમતગમત એટલે ક્રિકેટ...ક્રિકેટ…અને માત્ર ક્રિકેટ…) 18 વર્ષની ઉંમર પછી ગુજરાતીઓ શારીરિક શ્રમ પડે તેવી કોઈ રમતો રમતા જ નથી. તેમ છતાંય દરેક બાપ એના દીકરાને અચૂક કહેતો જોવા મળે કે'અમે, અમારા જમાનામાં બહુ રમતા'તા હોં ભઈ!'

વધેલા શરીરવાળા ગુજરાતીઓ માટે કસરત એટલે જમ્યા પછી પાનના ગલ્લા સુધી ચાલતાં જવું તે. મોઢામાં પાન કે મસાલો દબાવી કલાકો સુધી વિષયવિહીન ચર્ચાઓ કરવામાં ગુજરાતીઓની માસ્ટરી છે. પાનના ગલ્લા અને ચાની કીટલીઓ એ ગુજરાતીઓ માટે વૈચારિક આદાન-પ્રદાન માટેના આદર્શ સ્થાનકો છે. સાચો સમાજવાદ આ બે જગ્યાઓએ જ જોવા મળે છે. અહીંયા ગાડી, સ્કૂટરવાળા સાથે જ મજૂર પણ ઊભો રહી ચા પીતો હોય છે. (આ વાત પર બે કટિંગ ચા થઈ જાય, હોં ભઈ!)

દરેક ગુજરાતી મા-બાપને તેમના સંતાનોને ડોક્ટર, એન્જિનિયર કે સી.એ. બનાવવામાં જ રસ હોય છે. સંતાનોની કરિયર મા-બાપ જ નક્કી કરે છે. કોઈ ગુજરાતી મા-બાપને એવું કહેતા સાંભળ્યા નથી કે 'મારે મારા દીકરાને કલાકાર બનાવવો છે, મારે મારી દીકરીને ચિત્રકાર બનાવવી છે, મારો દીકરો ફોજમાં જશે, મારી દીકરીને એથ્લિટ બનાવવી છે, મારા દીકરાને ફેલ્પ્સ જેવો તરવૈયો બનાવવો છે.' (નાટક-ચેટક, કવિતા, સાહિત્ય-લેખનના રવાડે ચઢેલા છોકરાંવને તો આઉટલાઈનના કહેવાય છે, હોં ભઈ !)

રૂપિયા કમાવા સિવાય બીજો કોઈ પણ શોખ ન ધરાવતા ગુજરાતીઓનો એક શોખ ખૂબ જાણીતો છે રજાઓમાં ફરવા જવાનો અને તે પણ સાથે ખૂબ બધા નાસ્તા લઈને. જ્યારે અને જ્યાં પણ ફરવા જઈએ ત્યારે ડબ્બાઓના ડબ્બા ભરીને સેવમમરા, ઢેબરાં,ગાંઠિયાં, પૂરીઓ, અથાણાં સાથે લઈને નીકળીએ છીએ. ઘર બદલ્યું હોય એટલો બધો સામાન લઈ ટ્રેનમાં ખડકાઈએ છીએ અને ટ્રેન ઉપડે કે પંદર જ મિનિટમાં રાડારાડી કરતાં નાસ્તાઓ ઝાપટવા મંડીએ છીએ અને ઢોળવા મંડીએ છીએ. ગુજરાતીઓના ફરવાના શોખના કારણે પરદેશની ટૂરમાં ગુજરાતી થાળી મળતી થઈ ગઈ છે. જો ગુજરાતીઓ ફરવાનું બંધ કરી દે તો બધી જ ટ્રાવેલ્સ એજન્સીઓ અને પેકેજ ટૂર, કપલ ટૂરવાળાઓનું ઉઠમણું થઈ જાય. (આપણે ફરવાની સાથે ફરવાની સલાહ આપવાના પણ શોખીન છીએ. નવસારી સુધી પણ નહીં ગયેલો માણસ નૈનિતાલ કેવી રીતે જવું તેની સલાહ આપી શકે, હોં ભઈ!)

ગુજરાતીઓના લેટેસ્ટ બે શોખ. એક - ટુ વ્હીલર અને બીજો - મોબાઈલ. જગતમાં સૌથી વધારે ટુ વ્હીલર ગુજરાતમાં ફરે છે. આપણું ચાલે એક રૂમમાંથી બીજા રૂમમાં જવા માટે પણ ટુ-વ્હીલર વાપરીએ. પહેલાના જમાનામાં એવું કહેવાતું તું કે 'દેવું કરીને પણ ઘી પીવું.' હવે એવું કહેવાય છે કે 'દેવું કરીને પણ બાઈક લેવું.' ગુજરાતીઓના 'દિલની સૌથી નજીક' જો કોઈ હોય તો તે છે મોબાઈલ (કેમકે આપણે મોબાઈલને હંમેશાં શર્ટના ઉપલાં ખિસ્સામાં જ રાખીએ છીએ.) જાત-જાતના મોબાઈલ, ભાતભાતની રિંગટોનનો આપણને જબરજસ્ત ક્રેઝ છે. મોબાઈલની સૌથી વધુ સ્કિમ આપણા ગુજરાતમાં જ છે અને તેનો સૌથી વધુ લાભ પણ ગુજરાતીઓ ઉઠાવે છે. જો સ્કિમમાં 'ફ્રી' લખ્યું તો તો 'ખ…લ્લા…સ'. રાત્રે દસથી સવારે છ, 'મોબાઈલથી મોબાઈલ ફ્રી' એવી સ્કિમ જાહેર થાય એટલે ગુજરાતીઓ મચી જ પડે. બાજુ-બાજુમાં બેઠા હોય તો પણ મોબાઈલથી મોબાઈલ વાતો કરે ! (હે…લો…, અને જ્યારે બિલ આવે ત્યારે કંપનીવાળા જોડે સૌથી વધુ બબાલ પણ આપણે જ કરીએ છીએ, હોં ભઈ !)

ગુજરાતીઓની સ્વભાવગત ખાસિયત પણ અનોખી છે. આપણે એવર ઓપ્ટિમિસ્ટ એટલે કે સદાય આશાવાદી માણસો છીએ. શેરબજાર ક…ડ…ડ…ડ…ભૂ...સ…કરતું તૂટે તો પણ આપણે આશા રાખીએ છીએ કે 'કશો વાંધો નહીં, કાલે બજાર ઉપર આવી જ જશે.' આ સાથે આપણે ગુજરાતીઓ એટલા જ ખમીરવંતા પણ છીએ. ભૂકંપ આવે, પૂર આવે કે બોમ્બ બ્લાસ્ટ થાય, આપણે ત્યાં બીજા દિવસથી તો બધું રાબેતા મુજબ….

ગુજરાતીઓની એક સૌથી મોટી ખાસિયત, ખૂબી, વિશેષતા, વિલક્ષણતા એ છે કે આપણે ગુજરાતીઓ ક્યારેય પણ કોઈનાથી ઈમ્પ્રેસ થતા નથી. સાદા શબ્દોમાં કહીએ તો આપણે ક્યારેય કોઈથી ઘીસ ખાતા નથી. ગમે તેવો મોટો ચમરબંધી હોય પણ આપણે તેનાથી અંજાઈ જતા થી. 'એ લાટસા'બ હોય તો એના ઘેર, મારે શું ?' આવી તાસીર જ આપણને 'જીદ કરી દુનિયા બદલવાની' શક્તિ આપે છે અને તેના લીધે જ ગુજરાતની ધરતી પર ગાંધીજી, સરદાર અને ધીરુભાઈ જેવી હસ્તીઓ પાકી છે. (શું કહો છો, બરાબરને ભઈ?)

હાચુ કઉં તો મને તો ઍક ગુજરાતી હોવાનો બહું ગર્વ છે, તમને છે?

જો હા તો, ઍક સાચા ગુજરાતી તરીકે તમે પણ આપણી આ 'ગુજરાતી ગૌરવ ગાથા' ને આગળ ધપાવો.

'જ્ય જ્ય ગરવી ગુજરાત'. 'જ્યાં વસે ગુજરાતી ત્યાં વસે સદાકાળ ગુજરાત'



Attitude - Dare to challenge yourself

A little boy went into a drug store, reached for a soda carton and ask him for a Phone Call.Shop-owner replied sweetly this is no a STD, but you can do one call.

The store-owner observed and listened to the conversation:
The boy asked, "Lady, Can you give me the job of cutting your lawn?
The woman replied, "I already have someone to cut my lawn."
"Lady, I will cut your lawn for half the price of the person who cuts your lawn now." replied boy.
The woman responded that she was very satisfied with the person who was presently cutting her lawn.
The little boy found more perseverance and offered, "Lady, I'll even sweep your curb and your sidewalk, so on Sunday you will have the prettiest lawn in all of North-Palm beach, Florida."
Again the woman answered in the negative.
With a smile on his face, the little boy replaced the receiver.
The store-owner, who was listening to all this, walked over to the boy and said," Son... I like your attitude; I like that positive spirit and would like to offer you a job."
The little boy replied, "No thanks, I was just checking my performance with the job I already have. I am the one who is working for that lady, I was talking to!"

Access mysql database hosted on remote server using phpMyAdmin

When we access http://localhost/phpmyadmin it connects to the local mysql server by default.

To make it connect to other servers you can follow the following steps:

Go to phpMyAdmin directory in your server installation (c:\wamp\phpmyadmin, in my case)

Open config.inc.php file and find

$cfg[‘Servers’] = array();
$i = 1

Below this the configuration of localhost would be provided. All the details of the localhost is given by
$cfg[‘Servers’][$i][‘variable_name’] = ‘value_of_the_variable’;

Many of the variables are defined like that.

Find the value declaration for localhost (mostly the last one would be $cfg['Servers'][$i]['AllowDeny']['rules'] = array();)

Then below this line we need to add the details for the another server we want to connect. We don’t need to repeat all the variables declared for localhost. Only those which are required should be declared for the server we are going to add.

We’ll have to increase the count $i and then give values.
<?php
$i++;
$cfg['Servers'][$i]['host']          = '';            // MySQL hostname or IP address
$cfg['Servers'][$i]['port']          = '';          // MySQL port - leave blank for default port
$cfg['Servers'][$i]['socket']        = '';          // Path to the socket - leave blank for default socket
$cfg['Servers'][$i]['connect_type']  = 'tcp';       // How to connect to MySQL server ('tcp' or 'socket')
$cfg['Servers'][$i]['extension']     = 'mysql';     // The php MySQL extension to use ('mysql' or 'mysqli')
$cfg['Servers'][$i]['compress']      = FALSE;       // Use compressed protocol for the MySQL connection (requires PHP >= 4.3.0)
$cfg['Servers'][$i]['auth_type']     = 'config';    // Authentication method (valid choices: config, http, signon or cookie)
$cfg['Servers'][$i]['user']          = 'root';         // MySQL user
$cfg['Servers'][$i]['password']      = '';            // MySQL password (only needed with 'config' auth_type)
?>

Provide appropriate information for the server above.

Now change the value of $cfg['ServerDefault'] to 0. So that when you will open phpmyadmin it will ask you to select the server.

If you will set $cfg['ServerDefault'] = 1; then by default localhost will open.

If you set $cfg['ServerDefault'] = 2; then by default remote database will open.

Saturday 18 September 2010

Increasing speed of PHP:HipHop for PHP by facebook

Facebook has released an open source project called HipHop for PHP to speed up PHP.

It is an effort to maximize the speed of PHP and to raise the standards of PHP so that it can be used at Enterprise level.

HipHop basically converts PHP code into “highly optimized C++”. Due to this CPU usage is reduced by 50% which ultimately increases the speed of any web application. This project incorporates best features of C++ and PHP. Project has been released on GitHub as an open source project.

Using HipHop in conjunction with MemCached performance of PHP can be increased.

According to the announcement,

“Overall HipHop allows us to keep the best aspects of PHP while taking advantage of the performance benefits of C++. In total, we have written over 300,000 lines of code and more than 5,000 unit tests. All of this will be released this evening on GitHub under the open source PHP license.”

Since PHP is the language used by facebook which is the largest website on internet.So this effort by facebook will surely give some prowess to PHP in terms of performance.In compare to Java and Dot net. Effect of this may be seen in the open source movement which is good for internet.

100 Signs that I May Be Writing Spaghetti PHP Code

100. I have no idea where this constant is defined.

99. I have echo statements littered throughout my code.

98. There is an error but it isn’t handled, and I can’t find it to figure out what’s wrong.

97. Spelling ‘referer’ wrong everywhere so it matches the PHP $HTTP_REFERER syntax and then adding a comment everywhere it’s used so everyone knows you did it on purpose.

96. Passing variables directly to 635 functions and using ‘global’ on 453 functions.

95. I have to modify the same function 10 times because I have not moved it into an include script…yet.

94. Finding out that the 2 libraries you need to include also happen to include each other

93. trying to edit html content on the index page and not being able to find the template until you go through 10 scripts (gotta love horde).

92. No comments.

91. You lose track of what include to use for what functions.

90. You edit an include and realize you’ve already written that function or something very similar…somewhere.

89. Opening and closing tags for an element like <p>, <table>, etc are in different files.

88. Can’t find the include file anywhere in the folder I am examining.

87. Includes? What are includes? (This is a corollary to 91).

86. Everything looks the same, as in:
Top of page:
include “include.php”;
include “include1.php”:
include “include2.php”:

85. I find that rewriting is quicker and easier than modifying the original design.

84. You have a library of small functions that you wrote yourself, and will cut’n'paste them into almost every project you work on… Whether they’re needed or not…

82. I’m at that precipice where I suddenly realize that the whole application would be a lot better if I made a certain change – a fundamental change – one that would allow me to streamline my code, perhaps combine functions, and save me time and hassle later on. But it requires me to dump a day’s (or more) work and because of a lack of time – I press on and ignore it.

81. Every time you want to change a variable you have to use grep to find it ;)

80. you have so many “for” loops you’ve declared a variable for each letter in the alphabet.

79. Dreamweaver starts to lag when you open the file.

78. You realize there is no possible way to unwind your cross included files and in your great wisdom you used include and require. You now have to replace all of them with include_once and require_once just to stop the contamination.

77. there are enough “if” statements to make you scroll to the right.

76. Your GET query string is so long it can crash a browser.

75. Your class object includes are stored on a single server and aliased on all your webservers…but you don’t know which server those files are REALLY on anymore.

74. You curse at your co-worker’s terrible logic just before you realise you wrote that code last week.

73. You see comments in the code that read something like:
Your Name: Don’t ask me how or why this works, I know it looks overly complex and it appears there IS a simpler solution, but this works, it fixed a bug from the ‘simpler code’…just leave it be…don’t touch it, I’ve hired a voodoo witch doctor to place a curse on anybody who alters this code…trust me, just leave it alone!

72. Following on from 81 – you know you’re digging through a bowl of the stuff when, as a regular tool, you’re using the windoz’s search feature to find functions, variables and other bits of code.

71. Following of from 80 and 77 – having to “peel” your way through while/for loops and a chunks of IF and ELSE statements because the original author (probably in all his haste) couldn’t be bothered to use brackets. The code works but not always for the right reasons.

70. out of the 50 arrays used 49 are 3 dimensional.

69. You crash your SQL server more then 5 times while testing your queries

68. After uploading your scripts to the server you find that you’ve exceded your allotted bandwidth for the month

67. I use every imaginable variation of the word “foobar” in variable names

66. My enter key doesn’t work, so I just put everything on one line, it works anyways.

65. [editor note: This one is not so much a sign, as an example. See Message #35].

64. You’re not using Python instead. ;)

63. Some functions work even though you know they shouldn’t as you haven’t finished them yet. Being unable to make them fail as expected, you are left with only one conclusion: your code has spontaneously become self-aware – and worse, it *knows* you want to shut it down…

62. You sit down, open your PHP script, and wonder where to begin with debugging… (ooh boy, I know the feeling of that!)

61. Your final page doesn’t validate. You look at the HTML source and see the problem clearly, but you decide not to fix it because you have no idea where this output comes from.

60. When you have to grep for a var from / because you have no idea where in your directory structure the file is, all you know is it is above the root of the site. (I’ve had to do this a few times)

59 - When a simple HELLO WORLD takes up 40 lines of code…

58. Nothing like throwing in a hierarchy of javascripts that are all dependent on each other. Something along the lines of “this script must be defined after variables hd,hm and hy are defined”.

57. You find comments like this in your code:
This code, while convoluted and apparantly redundant fixes a bug in a M$ dll/function/object/etc.

56. When every time the boss and artist come walking through the door, you know you are going to have to change 50 lines of code.

55. You wrap it up and realize that there are 20 funtions in the include files which are never called, although at some point, they were all required.

54. The project scope continues to creep, but the timeline scope continues to deminish (don’t care who you are, if you are keeping up with that, you are hacking dough)

53. You are using database structure changes in the middle of the project

52. In an attempt to same time, you are making system calls for OS functions.

51. Changing database is (e.g MS SQL to MySQL) requires the rewrite of SQL statments.

50. There is HTML in your functions. (this is a little debatable, but it is a watch sign for me). [editor wants to change this to: 50. Your functions output HTML directly (either through switching out of PHP or via echo)].

49. On the weekend you find yourself testing the effects of gzip on include files.

48. The white board in your office is clean.

47. You’ve run out of meaningful variable names, and you are now reduced to using the names of family pets.

46. The ratio between the number of variable names, and the number of field names in the database, is 5 to 1

45. You realize that the only difference between three functions is the number of variables being passed.

44. You realize that you are changing global variables with functions inside include files

43. Your SQL statments have SELECT * in them

42. You know that the algorithm you just created to check the data coming back from the database is a O((N2 -N)/2) .. but you just don’t care anymore.

41. While writing a new function, you are background thinking justifications for the last one you just wrote.

40: You surf over to WW to see how many queries per page others dare to use & scoff at the low number.

39: you plan your vacation using if-else complete with curly brackets.

38. You’ve worn paint off the “$” and “4″ key on your keyboard.

37. You are using classes, but create a “miscellaneous” class where you put all those odds and ends. Finally you realize the “misc” class has become your main class and needs to be included in every script.

36. You create a separate class for every single function.

35. You have an include file called “stuff.inc”

34. Your for loop pops a query and sends the results to a funtion, which runs a for loop across the array you sent with the results from the query, sending the 3, 5 and 10 cells to seperate funtions, and formats the htmml for the 1, 2, 4, 5, 6, 7, 9 values of the array, sending those to a function, which has a for loop, …

33. You have come up with 5 blistering hot ideas for the program you are working on, which have taken you the last 3 weeks to bring to reality, only to find, now that they are all working, and they work even better than you could have imagined 3 weeks ago, they also block the original functionality of the program spec, and are in conflict with the main idea of the client.

32. Your hands are bruised and cut from the shards of exploding classes after hours of trying to shove the client’s feature requests, into your well thought out architecture.

31. You have no idea what a CRC Card is …

31.a) You don’t understand classes.

31.b) You can’t count down from 100.

30. You know someone else is writing spaghetti code when…. you find
if (1==0) {

}

29. When you have more cases then a court house

28: reading this list you think.. “Hmmm what’s so bad about that? Or that? Or that?

27. Infinitely cascading includes like:

index.php:
<?php include(“menu.php”);?>

menu.php:
<?php include(“navigation.php”);?>

navigation.php:
<?php include(“newmenu.php”);?>

newmenu.php:
<?php include(“newmenu_final.php”);?>

newmenu_final.php:
<?php include(“menu_newer_version.php”);?>
… etc

26. if your included file “stuff.inc” has become deprecated in favour of “newer-stuff.inc”

25. Parse error: parse error in /home/index.php on line 140
20 minutes later
Parse error: parse error in /home/index.php on line 141
20 minutes later
Parse error: parse error in /home/index.php on line 142

24. When the first line of your code is:
ini_set(max_execution_time,”99999″);

23. And the last line of your codes is:
ini_set(max_execution_time,”30″);

22. When you open the same db 11 times in the same file.

21. When you have to do your includes in a page being called as in mypage.php?page=somedullpage.

20. You include a file that includes the original file…
<!– file1.php –>
<? include(“file2.php”); //other stuff?>

<!– file2.php –>
<? echo “stuff”; include(“file1.php”);?>

19. You have so many custom fucntions that you try to redifine the nl2br function

18. You have so many custom functions that the WhatDoTheseFunctionsDo.txt file is 20MB

17. Your kids understand the code…after college.

16. You have to grep for all occurences of include() or require() and replace them with include_once() and require_once() just to get your app to run.

15. You’re still using extract, cause well, those security folks are all just anal anyways.

14. You need to write a Perl script to check your PHP code.

13. When your orignal project was to recreate a windows desktop application in php/html/javascript to run on windows desktops.

12.You start trying to recreat a windows app with php…and end up making another form to e-mail app.

11. You realise you have three functions with the exactly the same name, but which do completely different things, scattered across several includes.

10. When your control script forgets that it is handling the return from one of many scripts it calls and re initializes all the vars… and you don’t figure it out for a month.

9. You have read through this whole thread so far and said to yourself “I don’t do any of those” and patted yourself on the back.

8. You’ve read this whole thread and patted yourself on the back for only doing half of them.

7. You post your code to WW looking for some answers and the responses run longer then the Google update threads.

6. goto 5.

5. GOSUB 100:REM In case we missed anything on the first pass…

4.
if ($status == “awake”){
$actitivity = “Writing spaghetti code”;
}elseif($healthstatus == “OK”){
$activity = “Sleep”;
}else{
print “CALL 911 IMMEDIATELY!”;
}

3. You work alone, but have to use CVS to keep track of your project.

2. You took over a project that was so convoluted you had to just scrap it and start over. Now, after three weeks, you find you have the exact same directory structure as the original and most filenames are the same.

1. You’ve been watching this thread the entire time and haven’t thought of a single thing you could add.