Zend_Validate_StringEquals

23
Jan
0

If you ever wonder where that 'StringEquals' validator rule taken as example from the Zend_Filter_Input documentation page results in an error like below, well read again. It was clearly stated as 'hypothetical'.

Plugin by name 'StringEquals' was not found in the registry; used paths: Zend_Validate_: Zend/Validate/

Given such validator would be useful on a number of situations i.e. confirming passwords, emails, etc. I present to you my own version of the class.

  1.  
  2. <?php
  3. class Zend_Validate_StringEquals extends Zend_Validate_Abstract
  4. {
  5. const NOT_EQUAL = 'stringNotEqual';
  6. const MISSING = 'stringMissing';
  7.  
  8. /**
  9.   * @var array
  10.   */
  11. protected $_messageTemplates = array(
  12. self::NOT_EQUAL => "%field1% and %field2% are not equal.",
  13. self::MISSING => "One or both strings are missing."
  14. );
  15.  
  16. /**
  17.   * @var array
  18.   */
  19. protected $_messageVariables = array(
  20. 'field1' => '_field1',
  21. 'field2' => '_field2'
  22. );
  23.  
  24. protected $_case = false;
  25. protected $_field1 = null;
  26. protected $_field2 = null;
  27.  
  28. /**
  29.   * Sets validator options
  30.   *
  31.   * @param boolean $case
  32.   * @return void
  33.   */
  34. public function __construct($case = false)
  35. {
  36. $this->_case = $case;
  37. }
  38.  
  39. /**
  40.   * Defined by Zend_Validate_Interface
  41.   *
  42.   * Returns true if and only if the the 2 strings are equal
  43.   *
  44.   * @param array $value
  45.   * @return boolean
  46.   */
  47. public function isValid($value)
  48. {
  49. if(!is_array($value) OR sizeof($value) < 2) {
  50. $this->_error(self::MISSING);
  51. }
  52.  
  53. $this->_field1 = array_shift($value);
  54. $this->_field2 = array_shift($value);
  55.  
  56. if($this->_case === true) $function = 'strcmp';
  57. else $function = 'strcasecmp';
  58.  
  59. if(0 !== $function($this->_field1,$this->_field2)) $this->_error(self::NOT_EQUAL);
  60.  
  61. if (count($this->_messages)) {
  62. return false;
  63. } else {
  64. return true;
  65. }
  66. }
  67. }
  68.  

Here is a sample test case. Validate password and confirm password elements represented by 'password' and 'cpassword' element names respectively.

  1.  
  2. $filters = array('password' => 'StringTrim', 'cpassword' => 'StringTrim');
  3. $validators = array(
  4. 'Password' => array(
  5. 'presence' => 'required',
  6. array('StringLength',5,15),
  7. 'fields' => 'password',
  8. 'messages' => "Passwords must be between 5 and 15 characters in length."),
  9. 'Confirm password' => array(
  10. array('StringEquals'),
  11. 'fields' => array('password','cpassword'),
  12. 'messages' => array(
  13. 0 => array(
  14. Zend_Validate_StringEquals::NOT_EQUAL => "Passwords does not match.",
  15. Zend_Validate_StringEquals::MISSING => "Both password fields must be filled."))));
  16.  
  17. $inputdata = new Zend_Filter_Input($filter,$validators,$_POST,$options);
  18.  

Appreciating: Apprenticeship Patterns

31
Dec
0

Apprenticeship PatternsI was never really a big fan of reading. Sure I have got a stack of books just right beside me, with mostly reference technical books, I have to admit I never finished reading any of them. When the opportunity of grabbing a paperback copy of "Apprenticeship Patterns" presented itself, I quickly opted for one. This one book got me curious while browsing for a Christmas book shopping list. The line "Are you doing all you can to further your career as a software developer?", I quickly answered "Sure I am!" while deep inside I was really asking "Am I?".

Although the subject matter is new to me, the first few pages provided a quick grasp of what the book is all about. As a freelance web developer I would constantly look for ways to improve my craft, alone or with a virtual community of mailing lists and forums. After reading in its entirety I was already reevaluating on a different way to improve my skills. The book provides proven and tested patterns on how to constantly rise up as a software developer. These patterns, like its "software development patterns" counterpart, only applied to real world career mode, is meant to provide indispensable knowledge on how to gain an edge on our ever changing industry.

If you come to me with a cup that is already full, how can you expect me to give you something to drink?

A very encouraging one line to always remind us that what knowledge we know now is not enough, empty our cups to fill them something new.

MySQL Default DATETIME Value – A Quick Rant

20
Nov
0

I was reviewing a year old code which I am adding a feature to. It so happened I came to a familiar issue about having two timestamp/datetime columns, one which should have the CURRENT_DATE / NOW() as default value and the other with an 'ON UPDATE CURENT_TIMESTAMP'. Examine the simple structure below:

CREATE TABLE `stories` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`title` VARCHAR( 255 ) NOT NULL ,
`text` TEXT NOT NULL ,
`creationdate` DATETIME NOT NULL ,
`lastupdate` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE = MYISAM

When you want to store stories, you would also want to record when it was originally created as well track the last time it was updated. The problem here is that adding a `DEFAULT NOW()` clause will not work for the `CREATE TABLE` query above as it is not supported. So when your insert a new story you will have to explicitly add a `NOW()` function for the `creationdate` row so it will reflect the current date as creation date. This should've been a simple schema functionality, turns out after more than a year MySQL seems to ignore for some reason.

Go on have yourself a read here http://bugs.mysql.com/bug.php?id=27645

How about you, how many times have you have to work around this from your application code?

MSFTPSVC Event ID 8

8
Nov
0

Source MSFTPSVC Event ID 8: FTP Server could not create a client worker Thread for user at host xxx.xxx.xxx.xxx. The connection to this user is terminated the data is the error. (No error Code)

Where xxx.xxx.xxx.xxx is the host attempting to connect.

The MS KB article here http://support.microsoft.com/?id=293637 proposes a solution with regards to a related metabase error and how to delete such. However some users may not have the "ipsecurity" error described in the KB, so instead you will have to check each of you individual FTP sites. Make sure that in the Properties -> Directory Security tab, Granted Access is selected. If in any case Denied Access is selected, make sure the connecting host above is added in the exception list.

After making changes to the Directory Security property, double check with the KB article again as changes to the metabase have been made.

After the two checks above and you are still getting tons of Event ID 8, you can also check here http://technet.microsoft.com/en-us/library/cc783062%28WS.10%29.aspx

VMWare: Windows 2003 Host, CentOS 5 Guest – Bridged Networking

28
Oct
0

We would usually just setup a NAT based VM appliance for any new requirement. Most of the time, access is limited to ones desktops. When the need arise for a shared Linux VM on our local Windows 2003 server, the inexperienced may find it trouble setting up the CentOS guest as a reachable application server just like its host OS.

To achieve this, make sure the following items a re true:

  • HOST » VMWare » Edit » Virtual Network Editor
  1. Automatic Bridging - "Automatically choose an available physical network adapter to bridge to VMNet0" is UNCHECKED
  2. Host Virtual Network Mapping - VMNet0 is mapped to you chosen physical adapter, NOT automatically.
  3. You can disable NAT, DHCP and Host Virtual Network Adapters
  • HOST » Control Panel » Network Connections
  1. Right click your chosen physical adapter, then Properties. Make sure "VMWare Bridge Protocol" is CHECKED.
  • GUEST - Assign an unused static IP, the same network/netmask and gateway that is used on your host's physical adapter.

Other items worth checking when inbound and outbound connections from the guest OS:

  • Host firewall
  • Guest DNS server settings, resolv.conf.

This checklist should get you up and running with a virtualized development platform with the same network visibility as a physical machine in your office.

PCI Compliance

26
Oct
0

It has not been long that I've become involved on many a client requests to make their servers PCI compliant. More often than not they would just pass onto us at least a 30 page report of what's needed to be done to become "PCI Compliant". This would often cause a short debacle between us and the clients since merely looking at the report and evaluating what is needed to be done on our part already costs our time.

The point of this article is how much should we get involved on getting our customers "PCI Compliant"?

From a customer's point of view, generally they would expect all the technical work necessary be done out of the report. From my point of view, this should not be the case. Security compliance is another box when it comes to web hosting, if the customers are employing a third party security company then they should do most of the leg work. We do not need to analyze pages of report that those security comapnies are supposed to be doing. We'd more than happy to get the customer compliant, but we only need the specific technical points to do our part. Yes, the customer gets confused at first when we throw back at them these ideas, fortunately they would get our point and point back to the security vendor then the vendor liasing directly back to us.

I'd hope there is a much more structured process between the security vendor, the customer and the hosting company. How about you, how have you been doing so far as a customer, vendor or a hosting company  with your part on the PCI compliance process?

FFMpeg-PHP: undefined symbol: php_gd_gdImageSetPixel

2
Oct
3

I was recently updating ffmpeg-php on one of our servers to the latest SVN release  of the 0.6.3 branch. On a 64bit CentOS 5.3 with PHP 5.2.11, the extension compiled and installed fine however Apache will not load it and spit out the error below:

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/ffmpeg.so' - /usr/lib64/php/modules/ffmpeg.so: undefined symbol: php_gd_gdImageSetPixel in Unknown on line 0

Surely enough, the GD extension was there, but why is ffmpeg complaining about not finding that shared symbol? Because, ffmpeg is loading first than GD (alphabetically) and such symbol has not been loaded. After adding the GD extension line on top of ffmpeg making sure it loads first the error went away and all is well again.

1280×800 on Dell Inspiron 1501 with Slackware 12.2

19
Aug
0

Finally I got to free up this laptop to be an all around testing machine after I got my wife her new MacBook Pro. Since I'd like a little more education, I decided to get back to Slackware after a couple of years. Install went fine, nothing much has changed, as this what drives the distro and what attributes for it's utmost stability, I am not so surprised.

One problem everytime I install a Linux or BSD variant on any laptop is the widescreen resolution. Except for Ubuntu and Fedora, much of them needs manual intervention to have their native widescreen resolution working on that particular distro, Slackware included.

To cut the story short, if you are installing X server for whatever dekstop manager you intend, the default xorg.conf configuration will not help with the widescreen. Simple really, just run xorgsetup, follow your instinct and startx. You should have your beloved widescreen back.

Do you favor a “LAMP (Linux, Apache, PHP, MySQL) Integrator”?

2
Aug
0

I have been reading on a number of project management articles lately and trends on open source projects. There seems to be a lot of fellow PHP developers who are as well Linux administrators for many server functions inluding HTTP servers like Apache and database administrators like for MySQL. Many of them are certified for one or more while many are jumping between careers that emphasizes one to the other thus gaining essential experiences for each.

Looking at job posts from all over the internet, you should've noticed at one time a PHP gig that requires MySQL administration skills and/or knows their way around Linux. PHP does not come by itself anymore, at least commonly, thus I've thought the term "LAMP Integrator".  A quick Google search does not seem to turn much on how to define such, thus I have a simple one.

LAMP Integrator - is a PHP developer primarily using MySQL as data backend with strong Linux administration and Apache tuning skills.

It may sound primitive, I am writing as I am thinking so comments and revisions are welcome.

Google Blogsearch

22
May
0

I just found out about this from a Google ad on Gmail, it seems the giant is taking the blogging information seriously. Pretty much the same as for regular searches however for faster indexing on results you can automatically send pings to their Blogsearch Pinging service.

More information on Pinging at http://www.google.com/support/faqs/bin/static.py?page=faq_blog_search.html&hl=en.
More information on Blogsearch at http://www.google.com/support/faqs/bin/static.py?page=faq_blog_search.html&hl=en