25. August 2010 von Andreas Heigl
It took me about an hour to spot a strange behaviour in my PHP skript:
Have a look at this code:
$foo = array ( 'a', 'b', 'c' );
foreach ( $foo as $bar );
echo $bar . "\n";
// Expected Output:
// a
// b
// c
// Actual Output:
// c
What happened?
Would I have used phpcs it would have been obvious. I used a semicolon instead of a bracket after the foreach statement.
So instead of calling the echo command with each iteration the foreach silently iterated through $foo and assigned $bar on each iteration. That left $bar with the last value of the array that gave the strange output.
I can not actually remember whether there had been closing brackets but I did not get an Error regarding that.
phpcs would have detected the missing brackets — if that would be observed by the used sniff.
More on phpcs later.
Tags: behaviour, echo, error, foreach, php, phpcs, strange
Geschrieben in Development | 0 Kommentare »
24. August 2010 von Andreas Heigl
Danke Herr Becker:
Ich muss sagen, Vegetarier – schön und gut!
Aber immer nur Fritten is ja auch nix.
Geschrieben in Allgemein | 0 Kommentare »
22. August 2010 von Andreas Heigl
This is a plugin that allows you use your LDAP to authenticate and authorise users to access your wordpress web-log.
Installation should be as simple as instalaltion of every wordpress-plugin. Simply unzip the downloaded file, put it into your wordpress-installations plugins-folder and activate it.
After activation you can configure the plugin via the options-panel.
How does the plugin work?
Well, as a matter of fact it is rather simple. The plugin verifies, that the user seeking authentification can bind to the LDAP using the provided password.
If that is so, the user is either created or updated in the wordpress-user-database. This update includes the provided password (so the wordpress can authenticate users even without the LDAP), the users name according to the authLDAP-preferences and the status of the user depending on the groups-settings of the authLDAP-preferences
Writing this plugin would not have been as easy as it has been, without the wounderfull plugin of Alistair Young from http://www.weblogs.uhi.ac.uk/sm00ay/?p=45
Configuration
Usage Settings
- Enable Authentication via LDAP
- Whether you want to enable authLdap for login or not
- debug authLdap
- When you have problems with authentication via LDAP you can enable a debugging mode here.
Server Settings
- LDAP Uri
- This is the URI where your ldap-backend can be reached. More information are actually on the Configuration page
- Filter
- This is the real McCoy! The filter you define here specifies how a user will be found. Before applying the filter a %s will be replaced with the given username. This means, when a user logs in using ‘foobar’ as username the following happens:
- uid=%s
- check for any LDAP-Entry that has an attribute ‘uid’ with value ‘foobar’
- (&(objectclass=posixAccout)((!(uid=%s)(mail=%s)))
- check for any LDAP-Entry that has an attribute ‘objectclass’ with value ‘posixAccout’ and either a UID- or a mail-attribute with value ‘foobar’
This filter is rather powerfull if used wisely.
Creating Users
- Name-Attribute
-
Which Attribute from the LDAP contains the Full or the First name of the user trying to log in. This defaults to name
- Second Name Attribute
-
If the above Name-Attribute only contains the First Name of the user you can here specify an Attribute that contains the second name.
This field is empty by default
- User-ID Attribute
-
This field will be used as login-name for wordpress. Please give the Attribute, that is used to identify the user. This should be the same as you used in the above Filter-Option.
This field defaults to uid
- Mail Attribute
-
Which Attribute holds the eMail-Address of the user?
If more than one eMail-Address are stored in the LDAP, only the first given is used
This field defaults to mail
- Web-Attribute
-
If your users have a personal page (URI) stored in the LDAP, it can be provided here.
This field is empty by default
User-Groups for Roles
- Group-Attribute
-
This is the attribute that defines the Group-ID that can be matched against the Groups defined further down
This field defaults to gidNumber.
- Group-Filter
-
Here you can add the filter for selecting groups for the currentlly logged in user
The Filter should contain the string %s which will be replaced by the login-name of the currently logged in
Tags: auth, ldap, wordpresss
Geschrieben in authLdap | 2 Kommentare »
21. August 2010 von Andreas Heigl
Last week I had the problem, that – due to a wrong database-entry – a serialized value got scrambled. And due to that (and some missconfiguration of the server) the application broke. Instead of a search result the user simply got an error message about not being able to unserialize the value due to an offset-error.
So how could I avoid the error (which actually is a notice) being thrown and besides that get to know whether unserializing worked or not?
The hack I finaly came up with is as follows:
- suppress the notice in any way
- check whether the returned value is a boolean false and the given string is ‘b:0;’ (which represents a boolean false in a serialized string).
- If so, the unserialize() failed, so lets throw an InvalidArgumentException
And here it is:
public function my_unserialize ( $value )
{
$unserialized = @unserialize ( $value );
if ( false === $unserialized && 'b:0;' !== $value ) {
$le = error_get_last ();
throw new InvalidArgumentException ( $le['message'] );
}
return $unerialized;
}
Tags: error, exception, notice, php, serialize, throw, unserialize
Geschrieben in Development | 0 Kommentare »
18. Juni 2010 von Andreas Heigl
Unit-Testing
There has been much said about the advantages or disadvantages of unit-testing. So I will not recap on that.
But where to go after you have choosen to use unit-testing?
The following short tutorial will give you an ovberview of how to install the necessary software, how to come to unit-tests from your requirements and how to write your tests and your code simultaneously.
Weiterlesen »
Tags: Development, php, php5, phpunit, QA, tdd, test, unit
Geschrieben in Development | 0 Kommentare »