Archive for the ‘Stay Hungry Stay Foolish..’ Category

Learn How to Learn

Learn How to Learn

Template systems introduce another level of processing in the application, so we might suspect that Smarty applications will run slower than plain PHP equivalents. Basically, we have a new pseudo-scripting language (the template engine’s tags) inside our scripting language (PHP).

Smarty is extremely fast by doing what is called template compiling. That means that it reads the templates, creates PHP scripts from them and includes the PHP files, resulting in a single PHP script that is compiled by the PHP engine, which is pretty fast. The beauty of the process is that the templates are parsed only once by Smarty, and only templates that are modified are compiled again. This is done automatically by Smarty and results in a fast compilation done by the PHP engine with very little overhead from Smarty.

If you are concerned about the performance of your site, Smarty has built-in caching support that can speed things up, especially on websites that have content that is not modified very often. You can cache all the content of a web page or only some of it and you can specify for how long Smarty should keep the content cached.

Since Smarty does template compiling resulting in a PHP script, there is no reason why we should not use a PHP compiler cache solution like PHP Accelerator or Zend Cache.

PHP Accelerator and Zend Cache have no problem with Smarty’s output and cache the PHP scripts produced by Smarty very well, so if our main concern is performance we should use one of these caching solutions combined with Smarty’s built-in caching support.

As Far As Security is Concerned….

We concluded that Smarty is fast, but we need to know about its security, which according to me is most important for any website.

By default, when using Smarty you are theoretically as secure as you are when using only PHP. This means that by using Smarty you can’t be less secure than using PHP only; but Smarty has some features to improve security in case this is needed.

When a site is built by a programmer working with a designer without using Smarty, the designer has access to the application and can modify all the PHP scripts. This is not good for security because a designer with bad intentions can breach the security of the system very easily when he or she has all the power of PHP in his or her hands.

Smarty comes with some built-in security features for situations where unreliable parties edit templates. When security is set on templates, a designer who modifies templates via an unsecured connection like FTP is unlikely to gain access in the system.
Using Smarty security features, you can:

  • Allow or deny usage of PHP code in the templates
  • Allow only a set of PHP functions as variable modifiers
  • Restrict the folders from which templates can be included
  • Restrict the folders from which local files can be fetched by templates

My strong advice is to always think about security. Think about having a database with credit card details and your designer including unsafe PHP code in one web page. This would result in a disaster for your business.

Below is the Millennium Awaited Blog URL Where you will find every possible solution of you interview asked questions.

Interview Questions And Answers On SQL By Pinal Dave And Vinod Kumar

Do read And Enjoy This…….

Hi All “Cntrl+C“iers 🙂 (I am Among you :-)),

I am back with something new to me and willing to share what I learned.

I was looking for sending the mail from my localhost and I found a blog By Mr. CrazyCoder.  And I was delighted to find the way to do this using PEAR Library.

There few dancing DOS COMMANDS which would do your work. At last it will  Make You Shout “EUREKA!!!”

It Goes Like This:

We will be installing PEAR MAIL Package.

  • Move to the directory where WAMP Server or PHP is installed using the command prompt. For example C:\wamp\bin\php\php5.3.0\>
  • Then run “go-pear.bat” file for complete installation of PEAR
  • Edit php.ini file and include the path to pear(include_path = “.;e:\wamp\bin\php\php5.3.0\includes;e:\wamp\bin\php\php5.3.0\PEAR;e:\wamp\bin\php\php5.3.0\PEAR\Mail”) and also edit ini file extension and set extension=php_openssl.dll to enable openssl
  • ph5.3.0\>pear list (this command will list all the installed pear packages)
  • pear download Mail (A zip file will be downloaded)
  • pear install Mail
  • pear install -a Net_SMTP(-a switch for installing all dependencies)
  • Then go to the mail.php file in e:\wamp\bin\php\php5.3.0\PEAR\Mail\mail.php and add this line require_once “e:\wamp\bin\php\php5.3.0\PEAR\Mail.php”;(If not added it shows error that class Mail cannot be found )
  • A note: If you are using php 5.3 then you might get a problem when installing pear. It will say that the command cannot be found… To overcome this you have to download go-pear.phar file and save in with that name in the php5.3.0 directory

Once done installing you can go straight away with the program. Here is the simple mail program that sends mail from php using SMTP

< ?php
include "e:\wamp\bin\php\php5.3.0\PEAR\Mail\mail.php";
$from = " ";//Sender Mail Address
$to =  " ";// Recipient mail address
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "ssl://";
$port = "465";
$username = "";
$password = "";// Type your Password Here
$headers = array ('From' => $from,'To' => $to,'Subject' => $subject);
$smtp = Mail::factory('smtp',array ('host' => $host,'port' => $port,'auth' => true,'username' => $username,'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo( $mail->getMessage());

else {
echo(“Shout Eureka!! Message Sent successfully !!!!”);
Try The Magic Provided By PEAR PHP…… 🙂
And Yes Do read My Previously Posted Articles…..
Courtesy: Mr. Crazy Coder

I was Just Looking for the way to display the New Rupee Symbol on my website and I found a very very Useful solution and thought of sharing it through my blog.. this will need a CSS file to include with few lines of css code and Using it wherever Required..

Below Is the One Way TO Do this.. Which Will Work For Every Browser…

<link rel="stylesheet" type="text/css" href="">
    <script src= type=”text/javascript”></script>

Use it by :

<span class="WebRupee">Rs.</span>

COURTESY:Resource From Where I Got This.

Another Method:


Below is the CSS to be used:

CSS for Rupee Symbol

And Declare it wherever required..

<span style="font-family:rupee;font-size:20px">R</span>

COURTESY: Resource From Where I Got this.

I made a tongue-in-cheek comment in another question thread calling PHP a terrible language and it got down-voted like crazy. Apparently there are lots of people here who love PHP.

So I’m genuinely curious. What am I missing? What makes PHP a good language?

Here are my reasons for disliking it:

  • PHP has inconsistent naming of built-in and library functions. Predictable naming patterns are important in any design.
  • PHP has inconsistent parameter ordering of built-in functions, eg array_map vs. array_filter which is annoying in the simple cases and raises all sorts of unexpected behaviour or worse.
  • The PHP developers constantly deprecate built-in functions and lower-level functionality. A good example is when they deprecated pass-by-reference for functions. This created a nightmare for anyone doing, say, function callbacks.
  • A lack of consideration in redesign. The above deprecation eliminated the ability to, in many cases, provide default keyword values for functions. They fixed this in PHP 5, but they deprecated the pass-by-reference in PHP 4!
  • Poor execution of name spaces (formerly no name spaces at all). Now that name spaces exist, what do we use as the dereference character? Backslash! The character used universally for escaping, even in PHP!
  • Overly-broad implicit type conversion leads to bugs. I have no problem with implicit conversions of, say, float to integer or back again. But PHP (last I checked) will happily attempt to magically convert an array to an integer.
  • Poor recursion performance. Recursion is a fundamentally important tool for writing in any language; it can make complex algorithms far simpler. Poor support is inexcusable.
  • Functions are case insensitive. I have no idea what they were thinking on this one. A programming language is a way to specify behavior to both a computer and a reader of the code without ambiguity. Case insensitivity introduces much ambiguity.
  • PHP encourages (practically requires) a coupling of processing with presentation. Yes, you can write PHP that doesn’t do so, but it’s actually easier to write code in the incorrect (from a sound design perspective) manner.
  • PHP performance is abysmal without caching. Does anyone sell a commercial caching product for PHP? Oh, look, the designers of PHP do.

Worst of all, PHP convinces people that designing web applications is easy. And it does indeed make much of the effort involved much easier. But the fact is, designing a web application that is both secure and efficient is a very difficult task.

By convincing so many to take up programming, PHP has taught an entire subgroup of programmers bad habits and bad design. It’s given them access to capabilities that they lack the understanding to use safely. This has led to PHP’s reputation as being insecure.

(However, I will readily admit that PHP is no more or less secure than any other web programming language.)

What is it that I’m missing about PHP? I’m seeing an organically-grown, poorly-managed mess of a language that’s spawning poor programmers.

So convince me otherwise!

Courtesy: Stackoverflow

I started coding 2 years ago, and this community has helped me a lot understanding many things which I was not aware of. However, many reputed coders instructed me of some patterns, the way I have to code and the way I shouldn’t write codes. Although I accepted their suggestion with gratitude, there was many thing I couldn’t understand.

I want your point of view to understand the few questions which has been running over my mind from the past few days.


  1. Why is it that many coders gave me thumbs down whenever I used the * in the select statement? Why did they suggest using entityname.tablename even if sometimes I want almost all the data from a table?
  2. Is it okay if my code make a frequent trip to the database on a single page say about 5-8 request? To be more precise in a page I would want to update the value, insert the value, count the rows, sum up the values, and so on.I once made almost all the select statement as a single query and one of the reputed user of this community suggested me not to do it that way instead suggested me to use a user defined function. (BTW, user defined function helped me a lot to clean my code and understand the error more quickly). What is your take on this?


When I started learning PHP I knew little about programming and more about web, although I had learned the popular computer languages like C, C++, .NET, Java etc. in my college. It was just the formal and theoretical subject which I learned and when I knew I wanted to be a web developer internet was my best friend and the community helped me out.

Now when I have started my journey of learning programming I have set some goals and aims myself, I want to be a Pro PHP Developer, I want to Master the HTML, JS, CSS, MySQL etc. My question here is


Here’s  The Answer:


Using * is fine. When you start getting really complicated with MySQL queries – joining and comparing tables – then you want to look at using entityname.tablename just to keep yourself from getting confused.

The next question is too subjective. It depends on your server and the efficiency of your script. It also depends on how many people will be using the script. Obviously, as with anything, the less you use it the better. If you can do one sql query instead of 5 then do that, but if you’re only going to have a couple of hundred people viewing your blog then I wouldn’t worry too much. Its the same with functions. Obviously its much better to put everything into functions. This helps in the long run because you will only have to edit your script in one place to make changes. Lets put it this way – if you’re copying and pasting code then you should be using functions. But then if your script is only 1 file, 200 lines long, then I wouldn’t worry if you don’t want to.


Frameworks are difficult to gauge the usefulness of. Obviously learning things like Zend or Mage are powerful frameworks that will help you to create much more efficient and complex web projects. However, for learners it may confuse you. I would say definitely not to try and learn them until you get your head completely around PHP. Hopefully then you will have a great enough understanding that you won’t have a problem if you come across these. You miss the main point of a language if you learn a framework. For instance – you won’t learn javascript if you just learn jquery. You’ll learn a bit, but you’ll never completely understand it.

Thats my take, but its a very subjective question.