Showing posts with label PHP techniques. Show all posts
Showing posts with label PHP techniques. Show all posts

Thursday, December 3, 2009

50 Extremely Useful PHP Tools

By Jacob Gube

PHP is one of the most widely used open-source server-side scripting languages that exist today. With over 20 million indexed domains using PHP, including major websites like Facebook, Digg and WordPress, there are good reasons why many Web developers prefer it to other server-side scripting languages, such as Python and Ruby.

PHP is faster (updated), and it is the most used scripting language in practice; it has detailed documentation, a huge community, numerous ready-to-use scripts and well-supported frameworks; and most importantly, it’s much easier to get started with PHP than with other scripting languages (Python, for example). That’s why it makes perfect sense to provide the huge community of PHP developers with an overview of useful tools and resources that can make their development process easier and more effective.

This post presents 50 useful PHP tools that can significantly improve your programming workflow. Among other things, you’ll find a plethora of libraries and classes that aid in debugging, testing, profiling and code-authoring in PHP.

Debugging Tools

  • Webgrind
    Webgrind is an Xdebug profiling Web front end in PHP 5. It implements a subset of the features of kcachegrind, installs in seconds and works on all platforms. For quick ‘n’ dirty optimizations, it does the job.

    Webgrind in 50 Extremely Useful PHP Tools

  • Xdebug
    Xdebug is one of the most popular debugging PHP extensions. It provides a ton of useful data to help you quickly find bugs in your source code. Xdebug plugs right into many of the most popular PHP applications, such as PHPEclipse and phpDesigner.
  • Gubed PHP Debugger
    As the name implies, Gubed PHP Debugger is a PHP debugging tool for hunting down logic errors.
  • DBG
    DBG is a robust and popular PHP debugger for use in local and remote PHP debugging. It plugs into numerous PHP IDE’s and can easily be used with the command line.
  • PHP_Debug
    PHP_Debug is an open-source project that gives you useful information about your PHP code that can be used for debugging. It can output processing times of your PHP and SQL, check the performance of particular code blocks and get variable dumps in graphical form, which is great if you need a more visual output than the one given to you by print_r() or var_dump().
  • PHP_Dyn
    PHP_Dyn is another excellent PHP debugging tool that’s open-source. You can trace execution and get an output of the argument and return values of your functions.
  • MacGDBp
    MacGDBp is a live PHP debugger application for the Mac OS. It has all the features you’d expect from a fully featured debugger, such as the ability to step through your code and set breakpoints.

Testing and Optimization Tools

  • PHPUnit
    PHPUnit is a complete port of the popular JUnit unit testing suite to PHP 5. It’s a tool that helps you test your Web application’s stability and scalability. Writing test cases within the PHPUnit framework is easy; here’s how to do it.
  • SimpleTest
    SimpleTest is a straightforward unit-testing platform for PHP applications. To get up and running with SimpleTest quickly, read through this pragmatictutorial that shows you how to create a new test case.

    Simpletest in 50 Extremely Useful PHP Tools

  • Selenium
    Selenium Remote Control (RC) is a test tool that allows you to write automated Web application UI tests in any programming language against any HTTP website using any mainstream JavaScript-enabled browser. It can be used in conjunction with PHPUnit to create and run automated tests within a Web browser.
  • PHP_CodeSniffer
    PHP_CodeSniffer is a PHP 5 script for detecting conformance to a predefined PHP coding standard. It’s a helpful tool for maintaining uniform coding styles for large projects and teams.
  • dBug
    dBug is ColdFusion’s cfDump for PHP. It’s a simple tool for outputting data tables that contain information about arrays, classes and objects, database resources and XML resources, making it very useful for debugging purposes.

    11 Dbug in 50 Extremely Useful PHP Tools

  • PHP Profile Class
    PHP Profile Class is an excellent PHP profiling tool for your Web applications. Using this class will help you quickly and easily gain insight into which parts of your app could use some refactoring and optimization.

Documentation Tools

  • phpDocumentor
    phpDocumentor (also known as phpdoc and phpdocu) is a documentation tool for your PHP source code. It has an innumerable amount of features, including the ability to output in HTML, PDF, CHM and XML DocBook formats, and has both a Web-based and command-line interface as well as source-code highlighting. To learn more about phpDocumentor, check out the online manual.
  • PHP DOX
    An AJAX-powered PHP documentation search engine that enables you to search titles from all PHP documentation pages.

Security Tools

  • Securimage
    Securimage is a free, open-source PHP CAPTCHA script for generating complex images and CAPTCHA codes to protect forms from spam and abuse.
  • Scavenger
    Scavenger is an open-source, real-time vulnerability management tool. It helps system administrators respond to vulnerability findings, track vulnerability findings and review accepted and false-positive answered vulnerabilities, without “nagging” them with old vulnerabilities.
  • PHP-IDS
    PHP-IDS (PHP-Intrusion Detection System) is a simple-to-use, well-structured, fast and state-of-the-art security layer for your PHP-based Web application.
  • Pixy: PHP Security Scanner
    Pixy is a Java program that performs automatic scans of PHP 4 source code, aimed to detect XSS and SQL injection vulnerabilities. Pixy takes a PHP program as input and creates a report that lists possible vulnerable points in the program, along with additional information for understanding the vulnerability.

Image Manipulation and Graphs

  • PHP/SWF Charts
    PHP/SWF Charts is a powerful PHP tool that enables you to create attractive Web charts and graphs from dynamic data. You can use PHP scripts to generate and gather data from databases, then pass it to this tool to generate Flash (SWF) charts and graphs.
  • pChart – a chart-drawing PHP library
    pChart is a PHP class-oriented framework designed to create aliased charts. Most of today’s chart libraries have a cost; this one is free. Data can be retrieved from SQL queries or CSV files or can be manually provided.

    Chart in 50 Extremely Useful PHP Tools

  • WideImage
    WideImage is a PHP library for dynamic image manipulation and processing for PHP 5. To be able to use the library, you should have the GD PHP extensioninstalled on your Web server.
  • MagickWand For PHP
    MagickWand For PHP is a PHP module suite for working with the ImageMagickAPI, which lets you create, compose and edit bitmap images. It’s a useful tool for quickly incorporating image-editing features in your PHP applications.

PHP Code Beautifier

  • PHP_Beautifier
    PHP Beautifier is a PEAR package for automatically formatting and “beautifying” PHP 4 and PHP 5 source code.
  • PHPCodeBeautifier
    PHPCodeBeautifier is a tool that saves you from hours of reformatting code to suit your own way of presenting it. A GUI version allows you to process files visually; a command-line version can be batched or integrated with other tools (like CVS, SubVersion, IDE, etc.); and there is also an integrated tool of PHPEdit.
  • GeSHi – Generic Syntax Highlighter
    GeSHi is designed to be a simple but powerful highlighting class, with the goal of supporting a wide range of popular languages. Developers can easily add new languages for highlighting and define easily customizable output formats.

Version-Control Systems

  • Phing
    Phing is a popular project version-control system for PHP. It is a useful tool for organizing and maintaining different builds of your project.
  • xinc
    xinc is a continuous integration server version-control system written in PHP 5 (i.e. continuous builds instead of nightly builds). It works great with other systems such as Subversion and Phing.

Useful Extensions, Utilities and Classes

  • SimplePie
    SimplePie is a PHP class that helps you work with RSS feeds. Check out the online RSS and Atom feed reader, which demonstrates a simple Web application that uses SimplePie.

    Spie in 50 Extremely Useful PHP Tools

  • HTML Purifier
    HTML Purifier is a standards-compliant HTML filter library written in PHP. HTML Purifier not only removes all malicious code (better known as XSS) with a thoroughly audited, secure yet permissive white list, it also makes sure your documents are standards-compliant. Open source and highly customizable.
  • TCPDF
    TCPDF is an open-source PHP class for generating PDF documents.
  • htmlSQL
    htmlSQL is a unique tool. It is a PHP class for querying HTML values in an SQL-like syntax. Check out the live demonstration of how htmlSQL works.
  • The Greatest PHP Snippet File Ever (Using Quicktext for Notepad++)
    “A little something for all coders: a snippets file that I use for PHP coding. This is designed to be used with Quicktext for Notepad++, but feel free to adapt it to whatever text editor you prefer.”
  • Creole
    Creole is a database abstraction layer for PHP5. It abstracts PHP’s native database-specific API to create more portable code while also providing developers with a clean, fully object-oriented interface based loosely on the API for Java’s JDBC.
  • PHPLinq
    LINQ is a component that adds native data querying capabilities to PHP using a syntax reminiscent of SQL. It defines a set of query operators that can be used to query, project and filter data in arrays, enumerable classes, XML, relational databases and third-party data sources. [via]
  • PHPMathPublisher
    With PhpMathPublisher, you can publish mathematical documents on the Web using only a PHP script (no LaTeX programs on the server and no MathML).

    Math in 50 Extremely Useful PHP Tools

  • phpMyAdmin
    If you’re working with PHP, there’s a big chance you’re set up in a LAMP configuration. phpMyAdmin is Web-based tool for managing, building, importing, exporting and exploring MySQL databases.
  • PHPExcel
    PHPExcel is a set of useful PHP classes for working with Microsoft Excel files. PHPExcel allows you to read Excel files and write to them. This is useful for dynamically generating Excel spreadsheets for downloading.
  • Phormer
    Phormer is a PHP-based photo gallery management application that helps you to store, categorize and trim your photos online.
  • xajax PHP Class Library
    xajax is a PHP class for easily working with PHP AJAX applications. It gives you an easy-to-use API for quickly managing AJAX-related tasks. Check out thexajax Multiplier demo and the Graffiti Wall demo to see the xajax PHP class in action.
  • PHP User Class
    PHP User Class is an excellent script that helps you create a system for user authentication (i.e. registration, log in, account profile, etc.). It’s a useful utility to have around if you require user registration for your Web applications.
  • PHP-GTK
    PHP-GTK is a PHP extension for the GTK+ toolkit (a robust toolkit for developing GUIs). It is a suite of useful OOP functions and classes to help you rapidly build cross-platform, client-side GUI’s for your application.

PHP Online Tools and Resources

  • Minify!
    Minify is a PHP 5 app that can combine multiple CSS or JavaScript files, compress their content (i.e. remove unnecessary white space and comments) and serve the results with HTTP encoding (via Gzip/deflate) and headers that allow optimal client-side caching. This will help you follow several of Yahoo!’sRules for High Performance Websites.

    Minify in 50 Extremely Useful PHP Tools

  • HTTP_StaticMerger: Automatic “merging” of CSS and JavaScript files
    This library automatically merges sets of static files (CSS or JavaScript) and speeds up page loading (by lowering the number of HTTP queries). It is recommended to use this together with caching reverse-proxy to minimize the response time.
  • PHP Object Generator
    PHP Object Generator is an open-source Web-based tool that helps you quickly construct PHP objects and leverage object-oriented programming (OOP) principles in your code.

    03 Object Generator in 50 Extremely Useful PHP Tools

  • gotAPI/PHP
    gotAPI is a useful online tool for quickly looking up PHP functions and classes. Also check out the Quick PHP look-up widget example in case you’d like to include this awesome look-up feature on your website.

    04 Gotapi in 50 Extremely Useful PHP Tools

  • koders
    koders is a search engine for open-source and downloadable code. It currently has over a billion lines of code indexed and isn’t limited to just PHP.
  • PECL
    PECL is a directory of all known PHP extensions and a hosting facility for downloading and developing PHP extensions.

In-Browser Tools (Firefox Add-Ons)

  • FirePHP
    FirePHP is a Firefox extension that allows you to log data in Firebug. It has a variety of useful logging features, such as the ability to change your error and exception handling on the fly and to log errors directly to the Firebug console. To learn more about what FirePHP can do, check out the FirePHP guide onhow to use FirePHP. For developers using the Zend PHP framework, you might find this guide on using FirePHP with Zend useful.

    01 Firephp in 50 Extremely Useful PHP Tools

  • phpLangEditor
    phpLangEditor is a very handy Firefox add-on for translating language files and variables in your script.

    02 Phplangeditor in 50 Extremely Useful PHP Tools

  • PHP Lookup
    PHP Lookup is a built-in search bar to help you quickly look up references to PHP syntax.
  • PHP Manual Search
    PHP Manual Search is a handy search bar that searches official PHP documentation from within your Web browser.

Frameworks for PHP

  • Dwoo
    Dwoo is a PHP 5 template engine positioned as an alternative to Smarty. It is (nearly) fully compatible with its templates and plug-ins, but it is being written from scratch and is aimed to go one step further with a cleaner code base.
  • CodeIgniter
    CodeIgniter is a powerful, high-performance, open-source PHP framework that helps you author PHP applications rapidly. CodeIgniter is known for having a light footprint, thereby reducing your server’s work. You can get up and running with CodeIgniter in a jiffy: it has an awesome online manual, a couple of helpful video tutorials and an active user forum.

    Codeigniter in 50 Extremely Useful PHP Tools

  • YII Framework
    Here is a high-performance component-based PHP framework that is supposed to be more efficient than CodeIgniter, CakePHP, ZF and Symfony. An optimal solution for developing large-scale Web applications. Yii supports MVC, DAO/ActiveRecord, I18N/L10N, caching, jQuery-based AJAX support, authentication and role-based access control, scaffolding, input validation, widgets, events, theming and Web services.
  • NetBeans
    A dedicated PHP coding environment and complete integration with web standards. The NetBeans PHP editor is dynamically integrated with NetBeans HTML, JavaScript and CSS editing features such as syntax highlighting and the JavaScript debugger. NetBeans IDE 6.5 fully supports iterative development, so testing PHP projects follows the classic patterns familiar to web developers.
  • Solar
    Solar is a PHP 5 development framework for Web applications derived from the Savant templating engine. Solar uses the MVC architectural pattern and has a host of classes and functions for securing your Web app against SQL injection, cross-website scripting (XSS) and other common exploits.

    Solar in 50 Extremely Useful PHP Tools

  • symfony
    symfony is an open-source PHP 5 Web application framework that is well known for its modularity and useful library of classes. To get up and running as fast as possible, you should check out the pragmatic symfony online tutorial called “The symfony 1.2 advent calendar tutorial,” which takes you through a step-by-step example of building your own symfony-based Web application.
  • PEAR – PHP Extension and Application Repository
    PEAR is a popular framework and distribution system for reusable PHP components. The purpose of the framework is to provide a structured library of open-source code for PHP users, a system for code distribution and package maintenance and a standard style for PHP code.
  • Propel
    Propel is an Object-Relational Mapping (ORM) framework for PHP 5. It allows you to access your database using a set of objects, providing a simple API for storing and retrieving data.
  • {{macro}} template engine
    {{macro}} compiles initial templates into executable PHP scripts with very clean syntax (much cleaner than WACT and Smarty) and executes them very fast. The engine doesn’t use an XML-like syntax; there are only two data scopes, global and local, and no more data sources (all data is displayed with regular PHP variables); and the system supports all WACT features such as templates wrapping and including.Macro in 50 Extremely Useful PHP Tools
  • Zend Framework
    The Zend Framework by Zend Technologies (the creators of PHP’s scripting engine) is a popular PHP Web application framework that embraces the principles of PHP OOP; it’s very extensible and has built-in utilities for working with free Web service APIs, such as those of Google, Flickr and Amazon.
  • Qcodo
    Qcodo is an excellent open-source PHP Web application framework. It’s subdivided into two parts: (1) Code Generator, and (2) Qforms. Code Generator handles the creation of object code and PHP and HTML front-end code from your data model. Qforms is an intuitive system for handling and creating complex PHP-driven HTML Web forms. Check out demos of applications that use Qcodo and presentational material that covers Qcodo.

    Qc in 50 Extremely Useful PHP Tools

  • SAJAX
    SAJAX is a JavaScript and AJAX application framework that works well with PHP (as well as several other server-side scripting languages). See SAJAX at work by going to Wall live demonstration.
  • Smarty
    Smarty is a popular PHP templating system to help you separate PHP logic and front-end code (HTML, CSS, JavaScript). It will keep your projects modular and easier to maintain.
  • CakePHP
    CakePHP is one of the leading PHP frameworks for creating robust, fully-featured Web applications. CakePHP has an extensive and well-organizedonline manual. If you want to learn via video tutorials, check out the CakePHP screencasts.

    Cake in 50 Extremely Useful PHP Tools

  • Savant2
    Savant2 is another popular object-oriented PHP templating system. Instead of a special syntax unique to Savant2, you use PHP syntax to develop your project’s template.
  • PHPSpec
    PHPSpec is a simple and intuitive PHP framework. It follows the Behavior-Driven Development principle and therefore allows you to write behavior-oriented code, oftentimes in plain English.

PHP IDEs and Editors

  • PHPEclipse
    PHPEclipse is a popular PHP source-code editor that is open source and runs on all the major operating systems, such as Windows, Linux and Mac OS. It has all the features you’d expect from a PHP source-code editor, such as code-folding, syntax highlighting, hover-over tool tips and support for XDebug and DBG.

    07 Php Eclipse in 50 Extremely Useful PHP Tools

  • PhpED
    PhpED is an excellent IDE for Windows users. It is one of the most robust and feature-packed IDEs currently out on the market and has useful features such as a built-in source-code profiler to find bottlenecks in your PHP source code and excellent integration with third-party apps and services just as front-end code validation.

    08 Phped in 50 Extremely Useful PHP Tools

  • phpDesigner
    phpDesigner is a lightweight PHP editor/IDE that also handles front-end code and markup remarkably well. Check out the phpDesigner online tutorials, as well as screencasts on phpDesigner to help you learn more about the IDE.

    09 Phpdesigner in 50 Extremely Useful PHP Tools

  • Zend Studio
    Zend Studio is an excellent PHP IDE for Eclipse. It’ll help you develop, deploy and manage Rich Internet Applications (RIAs) in an intuitive interface.

    10 Zend Studio in 50 Extremely Useful PHP Tools

  • Aptana PHP
    Aptana PHP is an open-source IDE extension/plug-in to be used in conjunction with Aptana Studio. To learn more, be sure to check out the online documentation about Aptana PHP.
  • PDT
    PDT is a PHP Development Tools framework that’s part of the Eclipse project. PDT includes all the necessary tools for you to create PHP-based Web applications.
  • VS.Php
    VS.Php is a PHP IDE for MS Visual Studio, making it a great IDE for recently converted ASP developers who have used MS VS to develop Web applications. To get you up and running ASAP with VS.Php, check out Jcx.Software’s online tutorials as well as its online documentation.
  • PHPEdit
    PHPEdit is an excellent PHP editor/IDE with a ton of useful features and a very intuitive user interface. To learn more about why PHPEdit is a good IDE, read the 10 reasons to use PHPEdit and view the introductory screencast about PHPEdit.

Source: http://www.smashingmagazine.com/2009/01/20/50-extremely-useful-php-tools/

Software Testing Services

Wednesday, November 4, 2009

MySQL University: GRAPH computation engine for MySQL

One of the things relational databases are not very good at is handling structures like trees (for example structure of categories in forum) or graphs (for example network of friends on social networking site).

GRAPH is a MySQL plugin which promises to handle such data in an easy and efficient manner using normal SQL syntax. I don't know any details, as MySQL University announcement was the first time I ever heard of this. Nevertheless the topic seems interesting, so if you would like to know more, attend MySQL Uni session this Thursday, November 5th at 10:00 GMT.

As usual session recording in flash format will also be available at a later time.

More information about GRAPH is available at OpenQuery's site

For more information about MySQL University, go to my introductory post

Source: http://www.phpfreaks.com/blog/mysql-university-graph-computation-engine-for-mysql

Friday, July 3, 2009

10 Ways to Avoid Writing Crappy Code

1. Learn OOP and common OO principles

This is an absolute requirement. If you are still coding procedural, this is no small task. What are you waiting for?

1. Employ Test Driven Design

Code that is buggy or simply doesn't work at all can safely be considered "crappy code". TDD gives you the confidence that your code works, and the side effects force better and more flexible software design.
If you are not familiar with TDD yet, and this post has prompted you to try it, be warned: at first it will seem very cumbersome. What definitely will help is this piece of advice, which is at the core of Test Driven Design: don't write tests afterwards, write them first. Without going to much into the details, and somewhat simplified the general mantra is this: write a test first, make it work by writing the application code, refactor, write another test, make it work, refactor, etc etc. It's a cycle. The application code follows the test code, not the other way around.
I recommend PHPUnit. It has the most features and the largest adoption.

2. Refactor, refactor, refactor

Refactoring means "to improve the design of existing code". Making changes to code results in an increasing loss of quality of that code, this is known as "software decay". To battle this phenomenon, you have to constantly evaluate if the code hasn't lost it's quality, and look for opportunities to improve the design beyond it's original. But there's a catch. And it isn't the time that refactoring takes, if you do it properly you'll save those hours by having avoided software decay. It is the risk of change.
I can understand if you are hesitant to change code that works (at least for now). But this is where number two comes back into play: as long as you've written the right tests, you can make sure your changes don't break anything.

3. Simpler is better

Your mind should constantly be waging a battle between simplicity and flexibility. Avoid unnecessary complication.

4. Use Design Patterns

Design Patterns describe real world software design problem and solutions. Make sure you are familiar with them, buy some books. If you encounter a design problem that seems familiar take your trusty GoF and PoEAA from the shelf and look it up.

5. Don't Use Design Patterns

Once you are familiar with Design Patterns, or even just with the existence of them, it can be tempting to start sprinkling pattern implementations over your application code, just because you can. Don't. Remember a Design Pattern consists of a problem and one or more solutions to that problem. Until you have the problem, don't use the solution.

6. Accept the limitations of your language

Believe me, I know that as a programmer it is difficult to accept limitations on bending your code to your will, but trying to change the behaviour of PHP is not the solution. PHP has limitations, you'll have to live with them. If you try to "patch" them, chances are you will do more harm than good.

7. Pretend you are writing a book

It has been said that "code should be easy to read rather than easy to write". Maybe somebody else will need to understand your code at some stage. Maybe two years from now, you will revisit this code and need to re-learn it's inner workings.
Semantics, meaningful docblocks and clear execution flow are everything. Imagine reading an instruction manual without pictures, filled with meaningless abbreviations, and with the pages in arbitrary order, without page numbers. That's how someone, maybe you, will feel if you ignore this advice.

8. Peer Review

Believe it or not, you don't know everything and you aren't always right. Nobody is. Getting a "second opinion" can only improve the end result.

9. E_STRICT is your friend

Make sure your code runs properly with E_STRICT turned on. Although, if you have gotten this far, I don't think that will be a problem.

10. Create a distinction between "source code" and a "build"

Even though PHP is an interpreted language, this is an important distinction in my opinion, even though practically noone employs this in the PHP world. A build in PHP is a copy of (part of) the source code, which includes assets like HTML, CSS and JavaScript, and is stripped of anything not necessary for running the application. Maybe your build is a Phar file, or maybe you have combined some source files into a single file (like the guys at Doctrine do). Maybe you can provide different build of the same project to server different purposes..
How does this help you avoid crappy code? It allows you to have the source code and build differ, avoiding any compromises you might be tempted to make to facilitate runing or developing the application. Bonus points if you allow the user to choose between placing everything in the server document root or just a bootstrap and the static files.

There are various build tools available, personally I use PHPUnderControl, which is a patch for CruiseControl and gives you a variety of build server features. It uses Ant by default, but I also use Phing.

Tuesday, June 23, 2009

Using MySQL Administrator with WampServer

For those readers who do not develop PHP on Windows platform WampServer is probably the most popular Apache + MySQL + PHP package for Windows. MySQL Administrator on the other hand, is a part of MySQL GUI Tools package.

The problem with this pair, is that they don't want to work together. At least not right out of box. MySQL Administrator fails to find mysql service process as installed by WampServer. This leads to infamous 'Could not find settings' error message.

You still will be able to use MySQL Administrator, but some of its features will be unavailable - among them quite important 'Startup variables' that lets you configure your server.

The reason is simple. WampServer keeps MySQL's config file in a directory, that is not checked by MySQL Administrator's searching algorithm.

Luckily, the solution is also simple.

Open registry editor
Windows XP: Go to Start > Run... type in regedit and press Enter
Vista: Go to Start, type regedit into search box and press Enter

A word of warning: be careful when using registry editor, as you might break your system if you change wrong variables.

Using tree on the left go to:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\wampmysqld

In the window on the right find ImagePath variable, double click it's name.

In the dialog that opens you should see something like this:
c:\wamp\bin\mysql\mysql5.1.33\bin\mysqld.exe wampmysqld
(MySQL's version may vary)

Change it like this:
"c:\wamp\bin\mysql\mysql5.1.33\bin\mysqld.exe" --defaults-file="c:\wamp\bin\mysql\mysql5.1.33\my.ini" wampmysqld
(be careful not to miss any double quotes!

Close registry editor, then restart you MySQL server from WampServer's tray menu.

MySQL Administrator should work fine now.

That would be it ;)

----

MySQL Forums post, where I've found this solution|Database Software Development by Expert Developers, UK

Thursday, April 9, 2009

Microsoft Q&A: Running PHP on Windows Server 2008

Microsoft has been recently engaging in a number of open source projects. They have been working on enhancing performance, security and stability of PHP applications on Windows Server platforms.

In relation to that we would, in cooperation with Microsoft, invite you to trial a Windows based web stack consisting of IIS 7, PHP 5 and SQL Server. Via the PHP on WS 2008 website you will be able to request a 30-day trial with a Microsoft hosting partner, and you'll be able to request a downloadable trial for installation on your own computer. You will be able to find more information on that page as well. Alternatively, if you have Windows Vista you can install IIS 7 and test its FastCGI capabilities.

We have setup a dedicated board, PHP on Windows Server 2008 - Microsoft Q&A, where you will be able to post your feedback and discuss it in general. Commencing April 20th, Hank Janssen and his team from the Microsoft Open Source Center will be available to respond on the feedback, and answer whatever questions that may arise.

We hope you will take part in this Q&A to enhance PHP, and specifically to enhance it on the Windows platform.

Do feel free to ask in the board if you have any questions.

PHP Web Development services at Script2please.com

SEO Web Design - Web Rankings - UK based White Label SEO Web Design Agency. Search Engine Optimisation, Search Engine Marketing, Web Design, PPC, Conversion Specialists.

Web Design Agency - Web Design, Web Development & Web Marketing Agency based in Surrey

Media Buying - Media planning & buying, including digital from Space & Time Media.

SEO - Learn how search engine marketing, PPC management, conversion enhancement and web analytics tracking can boost your online profitability. Visit our website and harness the web with Alkemi

Thursday, January 29, 2009

Dynamic Image Generation

Long and boring back-story....

One of the standard features of a message board is allowing members to have a signature, which is appended to the bottom of each post they make. Posters can put whatever they want into the signature (within forum settings). Putting quotes in one's signature is one of the more popular things to do.

A lot of people put in some motto they live by, some funny quote by some famous person, whatever. Some people like to quote things other posters on the board have said. I am one of those people. I think it's fun and promotes a sense of belonging to the community.

I've been a member of the phpfreaks forum for a number of years now, and over the years, I have posted and come across quotes that were (to me, anyways) worth collecting. But having a bunch of quotes in a sig isn't very convenient.

Click Here to Read Full Article from www.phpfreaks.com

Friday, January 16, 2009

PHP Cheat Sheet

The PHP cheat sheet is a one-page reference sheet, listing date format arguments, regular expression syntax and common functions.



You may down load the orginal image from the below links
http://www.addedbytes.com/download/php-cheat-sheet-v1/png/
http://www.addedbytes.com/download/php-cheat-sheet-v2/png/

Find some other interesting and helpful Cheat sheets
http://feeds.feedburner.com/CheatSheets-ILoveJackDanielscom

Maloy Bookmarks

Monday, January 5, 2009

Standardizing Variables to Code Faster

If you’ve been coding for a while you probably have some set ways in which you work. I recommend you also widen this method to naming variables, which when done consistently can be a huge help, especially when you are using some fancy MySQL along with your PHP code. If you are building a site with 15 MySQL tables it is helpful if you know all the column names because you always name them in the same way, but the same thing goes for simple variables, and even ids and classes for HTML elements.

A very common example can be variables which hold a user’s data. In my case I always use the variable ‘$u’ for holding the username, and the variable ‘$p’ for holding the password. If you are grabbing a lot of data, like first name, last name, email and so on you can make up your own standard set, I use ‘$fn’, ‘$ln’ and ‘$e’ respectively for the three.

Since you usually use these variables in the same script the importance of naming them consistently may not seem like a huge time saver. However when you get into session variables it saves you a lot of time if you don’t always have to look at where you are defining them to find out the names of each. I pull user data using a mysql query when a user logs in and I immediately place the whole array in a session variable name “$_SESSION['user']“. The names of the columns represent the values of this array, so the username and email would respectively become “$_SESSION['user']['Username']“, “$_SESSION['user']['Email']“. This is the same in my case for every single website I build where applicable.

User data naming consistency is also very prominent in the MySQL tables themselves. As you can see above my columns are also named the same in each case, a user’s email is always “Email”, his last name is always “LastName”. I steer clear of abbreviations with MySQL tables so other coders can easily see what’s going on as well. Consistency doesn’t just apply to the actual names, you can also apply it to cases. As you can see all my column names are always capitalized, they are like wikiwords, but user session variables which don’t come from MySQL are not capitalized. For example, when a user logs in he is assigned a time, which is usually one hour. If he/she is inactive for more than this time (no refreshes), he/she is logged out. There is no need to store this in the database, and so I know that this is not in there the session variable here is “$_SESSION['user']['time']“. This means that if I come back to work on a site a year after completion I know exactly where variables come from.

Even if you don’t yet know any PHP, you’re just getting into HTML and CSS you can still use these good practices. When assigning ids and classes to elements try and work out a structure for yourself that you always use. I use empty div tags to clear floats a lot, so I have a separate class named “cl” for this purpose. Whenever I start out a new webpage I include this class by default in the stylesheet since I know I will most likely need it.

That’s about it for standardizing your coding work, most of it is just common sense really. Try and work out your own method which works best for you. It takes time and a lot of practice to get a system working well since there is so much to think of, but if you always keep this in mind somewhere while coding you’ll be a faster and better coder in no time at all!

Script2please.com is one of the leading offshore outsourcing companies in India, We Offer Rich php web development services, and custom web development

Source: http://www.ghacks.net/2009/01/02/web-development-standardizing-variables-to-code-faster/

Friday, December 5, 2008

PHP 5.2.7 Released

Security Enhancements and Fixes in PHP 5.2.7:
  • Upgraded PCRE to version 7.8 (Fixes CVE-2008-2371)
  • Fixed missing initialization of BG(page_uid) and BG(page_gid), reported by Maksymilian Arciemowicz.
  • Fixed a crash inside gd with invalid fonts (Fixes CVE-2008-3658).
  • Fixed a possible overflow inside memnstr (Fixes CVE-2008-3659).
  • Fixed incorrect php_value order for Apache configuration, reported by Maksymilian Arciemowicz.
  • Fixed safe_mode related security issues detailed in CVE-2008-2665 and CVE-2008-2666.
  • Crash with URI/file..php (filename contains 2 dots) (Fixes CVE-2008-3660)
  • IMAP toolkit crash: rfc822.c legacy routine buffer overflow. (Fixes CVE-2008-2829)
Some of the key enhancements in PHP 5.2.7 include:
  • Fixed several memory leaks inside the readline and sqlite extensions
  • A number of corrections relating to date parsing inside the date extension
  • Fixed bugs relating to data retrieval in the PDO extension
  • A series of crashes in various areas of code were resolved
  • Several corrections were made to the strip_tags() function interms of <>
  • A number of bugs were fixed in extract() function when
  • EXTR_REFS flag is being used
  • Added the ability to log PHP errors to the SAPI (Ex. Apachelog) logging facility
  • Over 170 bug fixes.
For users upgrading from PHP 5.0 and PHP 5.1, an upgrade guide is available here http://www.php.net/migration52), detailing the changes between those releases and PHP 5.2.7. For a full list of changes in PHP 5.2.7, see the ChangeLog (http://www.php.net/ChangeLog-5.php#5.2.7).

PHP Web Development - PHP mysql web development services, php solutions, custom development of Internet applications using PHP for high performance and enterprise ready web application.

Thursday, November 6, 2008

creating a fully featured registration script

PHP web Development

In this tutorial you will learn how to create a fully featured registration script, users will be able to enter your site, visit the registration page, fill in the info, submit the form, receive an activation e-mail and be able to activate there accounts.

Alright, this tutorial won't teach you anything about design, so the finalized script won't look pretty at all, but it is very easy to implement into any design.

First, we are going to need to create a table in our database so that we can store all of our registration info. We are going to call this table, users since that's what it will store!

MySQL:
  1. CREATE TABLE users (
  2. id INT(11) NOT NULL AUTO_INCREMENT,
  3. username VARCHAR(30) NOT NULL,
  4. password CHAR(40) NOT NULL,
  5. email VARCHAR(70),
  6. active CHAR(32),
  7. PRIMARY KEY(id)
  8. );

That little SQL creates our table to store all of our user information in, now we need a way to connect to the database.

PHP:

  1. // CHANGE THESE VALUES
  2. DEFINE ('DB_USER', 'database username');
  3. DEFINE ('DB_PASSWORD', 'database password');
  4. DEFINE ('DB_HOST', 'localhost');
  5. DEFINE ('DB_NAME', 'database name');

  6. $dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error());

  7. @mysql_select_db (DB_NAME) OR die('Could not select the database: ' . mysql_error() );
  8. ?>

This is just a file that we can use to connect to our database with, now all we need to do is include it any file that we want to query the database from.

Now that we have our table and mysql connection file setup, we need to create the PHP file that allows the person to register.

Let's start off by creating the form processing part of the file, it will be included in the same file as the form.

PHP:

  1. if (isset($_POST['submitted'])) {

  2. $errors = array();
  3. require_once ('mysql_connect.php');

This part is easy, all it does is start a new PHP section, then our first if() statement is saying IF our form is submitted, then continue. We also start a new variable, and assign an array to it. So that we can echo out our errors (if there are any) at the end. We also include our mysql_connect.php file, since we will be querying the database.

PHP:
  1. if (eregi('^[[:alnum:]\.\'\-]{4,30}$', stripslashes(trim($_POST['username']))) ) {
  2. $user = mysql_real_escape_string($_POST['username']);
  3. $query = "SELECT username FROM users WHERE username = '$user'";
  4. $result = @mysql_query($query);
  5. $num = @mysql_num_rows($result);

  6. if ($num> 0) {
  7. $errors[] = 'The username you have chosen has already been taken, please try again.';
  8. } else {
  9. $username = mysql_real_escape_string($_POST['username']);
  10. }
  11. } else {
  12. $errors[] = 'Please provide a valid username between 4 and 30 characters.';
  13. }

This is where we check our first field, the username field. We use regular expressions to validate that the username is good. It must only contain numbers, letters, periods and it must be between 4 and 30 characters. If our regular expressions passes all the tests, we query the database and check if the username has been taken, if it has been taking we add an error to our $error array. If it is not taken then we it is assigned to the $username variable.

**UPDATE V1.1** - I have fixed the error that so many people are getting, I made a mistake, I have now added extra security to the script and it should be pretty much bug free.

PHP:
  1. if (!eregi('^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+){1,2}', stripslashes(trim($_POST['email'])) )) {
  2. $errors[] = 'Please provide a valid email address.';
  3. } else {
  4. $email = mysql_real_escape_string($_POST['email']);
  5. }

This little tid-bit of code just validates there e-mail address using another regular expression.

PHP:
  1. if (!empty($_POST['password1'])) {
  2. if ($_POST['password1'] != $_POST['password2']) {
  3. $errors[] = 'The 2 passwords you have entered do not match.';
  4. } else {
  5. $password = $_POST['password1'];
  6. }
  7. } else {
  8. $errors[] = 'Please provide a password.';
  9. }

This is where we validate our password(s). First we check if they entered in the first password, then if it isn't empty, we make sure that password 1 and password 2 are the exact same (password, and verify password). If they do not match each other, we add an error to our $errors array. If they do match each other, we continue.

PHP:
  1. if (empty($errors)) {
  2. $a = md5(uniqid(rand(), true));
  3. $query = "INSERT INTO users (username, email, password, active) VALUES ('$username', '$email', SHA('$password'), '$a')";

  4. $result = @mysql_query($query);

  5. if (mysql_affected_rows() == 1) {

  6. // Send the E-Mail
  7. $body = "Thank you for registering at the User Registration site. To activate your account, please click on this link:\n\n";
  8. $body .= "http://www.whateveraddressyouwanthere.com/activate.php?x=" . mysql_insert_id() . "&y=$a";
  9. mail($_POST['email'], 'Registration Confirmation', $body, 'From: admin@sitename.com');

  10. // Show thank you message
  11. echo '

    Thank You!

  12. You have been registered, you have been sent an e-mail to the address you specified before. Please check your e-mails to activate your account.';
  13. } else {
  14. echo 'You could not be registered, please contact us about the problem and we will fix it as soon as we can.';
  15. }

This is the part where we do our error checking, if our $errors variable is empty (no errors) then we continue on with the form. So we insert everything into our users table, run the query, then check if it worked using mysql_affected_rows() == 1. If our query only affected 1 row (only inserted 1 user, no more and no less.) then our query worked, you are shown a message and the e-mail is sent to the user.

**UPDATE V1.2** - The query has been fixed, and everything has been personally tested and works now. If there is still more bugs please tell me.

If it didn't work, (the query didn't work) you are shown an error message.

PHP:
  1. } else {
  2. echo '

    Error!

  3. The following error(s) occured:
    '
    ;

  4. foreach ($errors as $msg) {
  5. echo " - \"red\">$msg
    \n";
  6. }
  7. }
  8. }
  9. ?>

This is the finishing of the PHP section of our registration script, this is always where we check for errors. If the $errors array was not empty then the user is shown an error message and we use a foreach loop to display all of our errors and echo them out to the user. Then we end our PHP section.

HTML:
  1. text" name="username" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" size="30" maxlength="30" /> Username


  2. type="password" name="password1" size="30" maxlength="40" /> Password


  3. type="password" name="password2" size="30" maxlength="40" /> Confirm Password


  4. type="text" name="email" size="30" maxlength="30" value="" /> Email Address


  5. submit" name="submit" value="Register" />

  6. hidden" name="submitted" value="TRUE" />

So I lied, there is still a little tiny bit of PHP but very simple stuff. Here we just create our form, with the corresponding names as in our PHP script. Make sure you name your the hidden input as submitted, this is how our PHP script knows that the form is submitted.

That is it for our registration part of our script, now we just have to do the activation part, this is a simple little script.

PHP:

  1. if (isset($_GET['x'])) {
  2. $x = (int) $_GET['x'];
  3. } else {
  4. $x = 0;
  5. }
  6. if (isset($_GET['y'])) {
  7. $y = $_GET['y'];
  8. } else {
  9. $y = 0;
  10. }

  11. if ( ($x> 0) && (strlen($y) == 32)) {

  12. require_once ('mysql_connect.php');
  13. $query = "UPDATE users SET active=NULL WHERE (user_id=$x AND active='" . $y . "') LIMIT 1";
  14. $result = mysql_query($query);

  15. if (mysql_affected_rows() == 1) {
  16. echo "

    Your account is now active. You may now log in.

    "
    ;
  17. } else {
  18. echo '

    Your account could not be activated. Please re-check the link or contact the system administrator.

    '
    ;
  19. }


  20. } else {

  21. echo 'Activation link not valid!';

  22. }
  23. ?>

This is just a simple little script, we start off by checking the x and y values in the URL to check if they are valid (or if someone is messing with us), we inclue our mysql_connect.php file into our script, since we will be using the database to query the right user. A user is considered active when the active field for there name is NULL (empty), so if the x and y values are right and everything works, we then set the active field to NULL. If only 1 account was affected, we echo out a success message and everything is done! If not, then the appropriate error message is echoed and the script stops.

Source - http://www.example.com/php/registration-script/