Today I discovered that the Symfony framework does almost exactly (and more) what my own framework (FoRMAiD) aspires to be(come).
Now
what? Start learning to use Symfony2 and cease further development of
my own framework? Rewrite my own framework so that it builds on Symfony2
and add what is not available in it? Or stubornly ignore Symfony2 and
continue as planned?
The first option, and maybe the second,
seem appropriate, but still it is a bit disheartening to realise that
all the time and effort that has gone into FoRMAiD might have been better spent.
But
then again, I managed to create a working OOP based PHP framework, that
is fully compliant with the PEAR coding standard. So I learned a lot and gained some
valuable skills doing so. :)
Tuesday, October 30, 2012
Time to move on?
Posted by
Dieter Adriaenssens
at
16:48
0
comments
Labels: developing, FoRMAiD, php
Sunday, May 16, 2010
New department website launched
Last week, the new website of my department, that I've been working on for the last few weeks, was launched. In its first week, it got about 1200 visitors.
Although not completely finished, I thought it had reached a stage were it could be made public. I consider it a starting point anyway, a basis to start improving on by adding new features.
The previous website was created about 4-5 years ago, and was in need of a face lift. I could just have replaced the css file, to refresh the layout, but the code running in the background was replaced as well.
After some comparing, I decided to use Drupal 6 as the CMF of the new website. I hadn't worked with Drupal before, but heard and read good things about it, being developed in PHP and strong focus on modules as strong points.
First, I started developing a custom theme that reflects the corporate style of my university. I didn't do this before either, so it took me some time to understand how a page is built in Drupal and what parts it consists of, but in the end I got it working.
The new website should be bilingual (English-Dutch), so I had to look for a way to do this. Luckily, Drupal provides some modules (Locale, Internationalization) to make a website multilingual, and tools to do the translation (core module Content Translation).
I wanted to integrate the login system into the single sign-on system (CAS) of my university, so that the users of the website wouldn't have to create yet another account with matching password for this website.
There is a CAS module available for Drupal, but I got a custom one from a colleague, which I modified further, to take advantage (through CAS) of groups that are defined in the LDAP system of my university and of groups I defined in a seperate database, and thus assigning the right roles to each user on login.
With the different roles defined and assigned, I used the taxonomy module (in Drupal core) to define different parts of the website. My department consist of three research groups, so each lab has it's own section within the website. All sections have a public and private (intranet) part, so by using Taxonomy Access Control access to these pages could be linked to the defined roles.
Some pages are just static HTML, being maintained using a WYSIWYG editor, provided by Drupal module CKeditor.
Others are dynamic, getting their data from a database table, using a PHP script to generate the page. Module Cache Exclude was needed to keep these PHP generated pages from being cached by Drupal. Otherwise changes made in the database, would not show.
And core module PHP filter, to be able to execute PHP code in a page.
As I mentioned before, I'm new to Drupal so I'm still discovering possibilities, new modules and ways to do things, every day. Things that are still on my list is learning how to write modules, find a way to integrate my current database management PHP code with Drupal, basically using the Form API, not only to insert data into a database, but also update and delete data, and expand the features of the new website (both on the intranet as on public pages). Luckily I've got a good guide for the upcoming developing journey.
Posted by
Dieter Adriaenssens
at
16:35
0
comments
Labels: drupal, php, UGent, web development
Thursday, March 18, 2010
phpMyAdmin accepted for Google Summer of Code 2010
Since 2005, Google organises the, by now, well known event Google Summer of Code (GSoC). This programming event gives students the opportunity to participate in popular Open Source projects. When they successfully complete their assignment by the end of the summer, they even get paid. :)
Today, the list of mentoring organisations for GSoC 2010 was made public : phpMyAdmin, an Open Source project that provides a webinterface for popular database MySQL, written in PHP, is one of them.
From now on (18 until 29 March), would-be student participants are invited to discuss the ideas that phpMyAdmin proposes. If you're interested, take a look at the guidelines and discuss your ideas on the developers mailinglist. Other ideas are possible too.
You can find the full time line and more information on the GSoC 2010 website.
Posted by
Dieter Adriaenssens
at
23:13
0
comments
Labels: developing, GSoC 2010, MySQL, php, phpmyadmin
Friday, November 06, 2009
Checking for empty variables in PHP
While writing some php code I checked for an empty string, using the empty() function, but I got this error :
PHP Fatal error: Can't use method return value in write contextI found this very strange because I've used the empty() function many times before. It turns out that the empty() function can not handle the return value of a function or method. You can only check variables using this function.
The solution is simple, store the return value of a function in a variable, and then check the variable with the empty() function :
wrong
if ( empty ( some_function() ) ) {
$some_variable = some_function();
if ( empty ( $some_variable ) ) {
On a side note, using the empty() function, is the best way to check for an empty variable, because it combines multiple checks, and works for different variable types. See documentation for details. When relying solely on strlen() or isset(), you can get an unexpected result.
Posted by
Dieter Adriaenssens
at
11:28
0
comments
Labels: php, programming
Wednesday, March 11, 2009
Rename multiple tables in MySQL database
Having to rename multiple tables with a similar pattern (prefix, suffix, ...) by replacing the recurring pattern, isn't an easy task, because there is no simple function or statement for doing it, not as far as I know.
Renaming tables like 'table_1234' and 'table_3456' to 'new_table_1234' and 'new_table_3456', is pretty straightforward in SQL:
RENAME TABLE `database`.`table_1234`
TO `database`.`new_table_1234`;
RENAME TABLE `database`.`table_3456`
TO `database`.`new_table_3456`;
or in one SQL statement :
RENAME TABLE
`database`.`table_1234` TO `database`.`new_table_1234`,
`database`.`table_3456` TO `database`.`new_table_3456`;
But when renaming a lot of tables, this method becomes tedious and time consuming.
This PHP script automates the renaming of multiple tables in a MySQL database. It lists all tables in a MySQL database, which contain a defined string pattern. The script creates and executes a series of SQL statements, which rename the table by replacing the search pattern in the original table name with another pattern in the new table name.
This script can easily be modified to rename multiple databases, or when stripping the original pattern (f.e. a prefix) and adding a new pattern (f.e. a suffix) is needed.
<?php
$db_server = "localhost"; // hostname MySQL server
$db_username = "username"; // username MySQL server
$db_password = "password"; // password MySQL server
$db_name = "database"; // database name
$pattern = "pattern_"; // search string
$new_pattern = "new_pattern_"; // replacement string,
// can be empty
// login to MySQL server
$link = mysql_connect( $db_server, $db_username, $db_password);
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
// list all tables in the database containing the search pattern
$sql = "SHOW TABLES FROM `" . $db_name . "`";
$sql .= " LIKE '%" . $pattern . "%'";
$result = mysql_query ( $sql, $link );
if (!$result)
{
die("Invalid query: " . mysql_error( $link ));
}
$renamed = 0;
$failed = 0;
while ( $row = mysql_fetch_array ($result) )
{
// rename every table by replacing the search pattern
// with a new pattern
$table_name = $row[0];
$new_table_name = str_replace ( $pattern, $new_pattern, $table_name);
$sql = "RENAME TABLE `" . $db_name . "`.`" . $table_name . "`";
$sql .= " TO `" . $db_name . "`.`" . $new_table_name . "`";
$result_rename = mysql_query ( $sql, $link );
if ($result_rename)
{
echo "Table `" . $table_name . "` renamed to :`";
echo $new_table_name . "`.\n";
$renamed++;
}
else
{
// notify when the renaming failed and show reason why
echo "Renaming of table `" . $table_name . "` has failed: ";
echo mysql_error( $link ) . "\n";
$failed++;
}
}
echo $renamed . " tables were renamed, " . $failed . " failed.\n";
// close connection to MySQL server
mysql_close( $link );
?>
Posted by
Dieter Adriaenssens
at
20:00
18
comments
Labels: MySQL, php, programming, rename multiple tables, structure
Wednesday, July 16, 2008
Todo list
This post is a work in progress, listing things I would like to do in the near and more distant future.
Some may be completed soon, while others will take a long time or may never be completed.
While some items are in preparation of another item on the list, others have no set goal or defined purpose, yet. Thus, the items on this list are in no particular order :
- Learning new programming languages and improving my knowledge of the ones I'm already familiar with :
- Erlang
- C++
- Perl
- Linux :
- Continue work on some small PHP-projects
- Think about the feasibility of the semantic web, Turing tests, universal machines and time travel.
- (Re)paint my bathroom
- Find a new hobby
- Get a girlfriend
Posted by
Dieter Adriaenssens
at
19:44
0
comments
Labels: linux, php, programming, semantic web, structure, time management, to do
Saturday, May 05, 2007
md5-hash of strings are not the same with different charactersets
I maintain a website which hosts a forum, using popular forum software. This forum stores an md5-hash of the passwords of the users of this forum in a database. This website also has an admin section which is protected by a password. The passwords of the forum database are used to get access to the admin section. To do this the md5-hash of the submitted password is compared with the md5-hash stored in the database, exactly the same way as it is done by the forum software.
This week one of the users of the website reported to me that he was unable to access the admin section, but was still able to log in to the forum. The mechanism to check the password is identical for the admin section and the forum (as described in the previous paragraph), so at first I didn't understand why he couldn't access the admin section of the website. After some debugging I found out that the md5() function produced a different hash of the same password. It produced a correct hash, which was identical to the hash stored in the database, on the forum, but a different hash came up on the admin section.
I then remembered that the webserver (Apache 1.3) was upgraded a week earlier. The new webserver (Apache 2.0) uses a different default characterset (UTF-8), causing the website to work perfectly, but some special characters were replaced with question marks. This problem was solved by changing the characterset, in a .htaccess file in the directory of the forum, as the problem only occured there :
In .htaccess I added:
AddDefaultCharset ISO-8859-1
Only the forum used the old characterset, while the rest of the website, including the admin section, used the new default characterset of the webserver. Everything seemed to work fine.
Until this week, when that user couldn't access the admin section, while some other users still could login to the admin section. After some investigation I found out that the user that couldn't login used some special characters in his password. Then I started to realise that the md5() function must produce a different hash of the same string when it is encoded in a different characterset.
This makes perfect sense. In a lot of charactersets, normal alphanumeric characters (a-z, A-Z, 0-9) are in the same place, but some special characters like é or @, can have a different place in another characterset. When a string encoded in different charactersets contains special characters, it has a different value (on a binary/hexadecimal level). Thus when a hash is calculated of these strings, different hashes are produced.
Now that I understood what was happening I solved the problem by applying the same characterset to the entire website. The user who reported the problem was again able to login to the admin section.
Posted by
Dieter Adriaenssens
at
02:38
0
comments
Labels: internet, php, programming, structure