Wednesday, October 5, 2011

What is the difference between displaying a string in single quotes and double quotes in PHP?

1) With Single Quotes the performance is faster than double quotes because the PHP parser does not checks for any variables or special characters. Whatever is there it will display that.
2) With double quotes the parser will search for the variables embedded in the string.
3) Performance wise it is always better to use single quotes. And we can use the concatenation between the strings and the variables.
4) Double quotes recognizes the new line charactes like '\n','\t' etc.., where as single quotes does not.

Top 10 PHP MVC frameworks

A good framework is easy to learn, simple to use, intuitive to work with, easy to extend or to modify, rapid to build (maintain) applications with and of course stable.

Having said that, here is my top 10 PHP MVC Frameworks:

10- Ambivalence: A Java-Maverick Port
9- WACT: Web Application Component Toolkit
8- Achievo: A good RAD framework
7- Phrame: A Java-Struts port
6- Studs: A Java-Struts port to PHP
5- Prado: The winner of Zend coding contest
4- PHPOnTrax: a Rails port - PHP5 Only
3- CakePHP: Inspired by Rails PHP4/5
2- Mojavi: The first MVC framework I fell in love with

and the winner is:

1- Symfony: Based on Mojavi and inspired by Rails

This list is based on my personal tests and use. I have tested and played with many others, but I think these are the best frameworks out there.
- The first framework I fell in love with was Mojavi because of its elegant way to implement the MVC model.
- Symfony corrected some problems in Mojavi and improved it by taking the good sides of RubyOnRails and Propel.
- CakePHP is very promising, the only problem - really, I don't know if it is a problem - is: the development process is very slow.

Redirecting a Web Page Using a 301 Redirect with HTACCESS file

Below is the steps involved in redirecting a web page usinh HTACCESS file.
Know about .htaccess file
When a visitor/spider requests a web page, your web serverchecks for a .htaccess file. The .htaccess file containsspecific instructions for certain requests, includingsecurity, redirection issues and how to handle certainerrors.
Know about 301 redirect
301 redirect is the best method to preserve your currentsearch engine rankings when redirecting web pages or a website. The code "301" is interpreted as "moved permanently".After the code, the URL of the missing or renamed page isnoted, followed by a space, then followed by the newlocation or file name. You implement the 301 redirect bycreating a .htaccess file.
How to implement the 301 Redirect
1. To create a .htaccess file, open notepad, name and savethe file as .htaccess (there is no extension).
2. If you already have a .htaccess file on your server,download it to your desktop for editing.
3. Place this code in your .htaccess file:redirect 301 /old/old.htm http://www.you.com/new.htm
4. If the .htaccess file already has lines of code in it,skip a line, then add the above code.
5. Save the .htaccess file
6. Upload this file to the root folder of your server.
7. Test it by typing in the old address to the page you'vechanged. You should be immediately taken to the newlocation.
Notes: Don't add "http://www" to the first part of thestatement - place the path from the top level of your siteto the page. Also ensure that you leave a single spacebetween these elements:
          redirect 301 (the instruction that the page has moved)
          /old/old.htm (the original folder path and file name)
          http://www.you.com/new.htm (new path and file name)
When the search engines spider your site again they willfollow the rule you have created in your .htaccess file.The search engine spider doesn't actually read the .htaccess file, but recognizes the response from the server as valid.
During the next update, the old file name and path will bedropped and replaced with the new one. Sometimes you maysee alternating old/new file names during the transitionperiod, plus some fluctuations in rankings. According toGoogle it will take 6-8 weeks to see the changes reflectedon your pages.
Other ways to implement the 301 redirect:
1. To redirect ALL files on your domain use this in your.htaccess file if you are on a unix web server:
          redirectMatch 301 ^(.*)$ http://www.domain.com
          redirectMatch permanent ^(.*)$ http://www.domain.com
You can also use one of these in your .htaccess file:
          redirect 301 /index.html http://www.domain.com/index.html
          redirect permanent /index.html http://www.domain.com/index.html
          redirectpermanent /index.html http://www.domain.com/index.html
This will redirect "index.html" to another domain using a301-Moved permanently redirect.
2. If you need to redirect http://mysite.com tohttp://www.mysite.com and you've got mod_rewrite enabled onyour server you can put this in your .htaccess file:
          Options +FollowSymLinks
          RewriteEngine on
          RewriteCond %{HTTP_HOST} ^example\.com
          RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]
or this:
          Options +FollowSymLinks
          RewriteEngine
          OnRewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
          RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
Tip: Use your full URL (ie http://www.domain.com) whenobtaining incoming links to your site. Also use your fullURL for the internal linking of your site.
3. If you want to redirect your .htm pages to .php pagesandd you've got mod_rewrite enabled on your server you canput this in your .htaccess file:
          RewriteEngine on
          RewriteBase /
          RewriteRule (.*).htm$ /$1.php
4. If you wish to redirect your .html or .htm pages to.shtml pages because you are using Server Side Includes(SSI) add this code to your .htaccess file:
          AddType text/html .shtml
          AddHandler server-parsed .shtml .html .htm
Options Indexes FollowSymLinks Includes
DirectoryIndex index.shtml index.html

Wednesday, June 16, 2010

Segmentation fault when accessing a PHP page

Sometimes when one of our Apache web servers is restarted, we experience segmentation faults when any PHP page is subsequently accessed. The following line is printed in the httpd error_log:

[Wed Jun 16 10:59:33 2010] [notice] child pid 31513 exit signal Segmentation fault (11)

There will be one of these lines for each PHP page that is accessed. This appears to happen randomly - the "workaround" to-date is to restart httpd, which eventually fixes the problem (almost always after a single restart). Although we only see this happen rarely, it still happens frequently enough to be of concern.

So my question is, why is this happening in the first place? Is this a known bug with the version of Apache / PHP / Linux / etc that we are using? Any ideas?

The environment is:

  • Fedora 11
  • Apache 2.2.15 (Default settings)
  • PHP 5.2.13

I can provide more information if that would help narrow things down, since this error message is rather generic...

Any help is appreciated.

When it is necessary to use Classes in PHP

Hello,

I am a wordpress plugin developer. I saw the source of many pluginsand many plugin use "classes" in them and some without classes.

Many huge coded plugins like "wp-postratings" does not use Classes and some small plugins use Classes.

edit: Since classes have private, public and protected access specifiers, i feel a taste of security Does it increase security?

Other than PHP does other languages require classes ?

Is it compulsory to use Classes ?

I need some suggestions.

Get reply mail to my server for a mail sent through php mail function

Hi, I am developing a system to send mail to all of our clients. If they reply to that mail, I want to retrieve the reply mails to my server. There is a way to connect through the IMAP/POP3 server, But it is taking a long time to load the mails. Is there any way to get the reply mails directly to my server. or ay other alternate way to get the mails fastly through IMAP

Please Help me in solving this issue

How to Send Email from a PHP Script

All it takes is the right configuration (to send mail using a local or a remote server) and one function:

  • mail().

Send Email from a PHP Script Example

The first argument to this function is the recipient, the second specifies the message's subject and the third one should contain the body. So to send a simple sample message, we could use:

<?php
$to = "recipient@example.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("

Message successfully sent!

");
} else {
echo("

Message delivery failed...

");
}
?>

That's it!

Use Custom Headers (e.g. "From:") in Mail from a PHP Script

Do you want to set a custom From: address, maybe taken from the form you send, or another custom header line? It is but an additional argument you need.

Protecting Your Script from Spammer Exploit

If you use the mail() function (in combination with a web form in particular), make sure you check it is called from the desired page and protect the form with a CAPTCHA maybe. You can also check for suspicious strings in any arguments (say, "Bcc:" followed by a number of email addresses).

Send Email from a PHP Script with SMTP Authentication

If mail() does not work for you, you have options, too. The mail() function included with stock PHP does not support SMTP authentication, for example. If mail() does not work for you for this or another reason, try the PEAR Mail package, which is much more comprehensive and sending mail almost as easily from your PHP scripts.