$STDERR= fopen("php://stderr","w");
June 1, 2009
February 12, 2009
Xdebug and NetBeans for PHP on Mac OS X
I really used to like JEdit. It understands almost every shell/programming/database language and it colors source code accordingly. You can have 100+ files open, switch quickly between them and you can split the editor horizontally and vertically as you need.
But somehow JEdit on Mac OS didn’t like scrolling wheel recently – it jumped up and down, skipping many pages. So I’ve tried NetBeans 6.5. with PHP support. It looks beautiful. If you get PHP-only version of NetBeans rather than full version, it loads up quickly too.
While using NetBeans, I’ve noticed it can debug PHP via Xdebug. So I’ve installed Xdebug 2.0.4 on my Mac OS from sources – seemed easy. In Apache error log it just read: Failed loading /path/to/xdebug.so (null). But it didn’t load up in PHP. Then I’ve tried MacPorts Xdebug package, but still the same.
After I’ve tried several ways to resolve this, I’ve come across a solution at http://patrickgibson.com/news/andsuch/000198.php
Debugging PHP in NetBeans rocks! You can see variables, arrays, objects, set up breakpoints…. lovely!
December 19, 2008
DokuWiki fix
Some time ago I’ve customized DokuWiki for our purposes – extra integration with LDAP and Novell iChain, and making it all nicer. Today I’ve fixed two bad errors that appeared when I was updating it to version 2008-05-05.
DokuWiki is perfect for users and it has many plugins. But if you want to customize or fix anything in it, then you’ll find that it is really disorganised inside.
September 11, 2008
Unicode emails via PHPMailer
My web app has a form and then it sends emails via PHPMailer. But it didn’t work for Unicode messages.
I added accept-charset=”utf-8″ to the <form> tag. Then I changed $CharSet setting from default ‘iso-8859-1′ to ‘utf-8′. That worked for Unicode email body, but not for Unicode subject. In order to get Unicode subjects work I had to update PHPMailer to version 2.0.2.
var $CharSet = ‘utf-8′; //’iso-8859-1′;
var $ContentType = ‘text/plain’;
var $Encoding = ‘8bit’;
August 20, 2008
File upload problems in Safari
I had a weird problem: a simple HTML form with a file upload input, processed by PHP. It worked in Firefox but in Safari the uploaded file (small size) didn’t make it to the server about half the times. Not even a first line of PHP was invoked.
It’s a known issue. Solution – an extra header. See http://www.webmasterworld.com/macintosh_webmaster/3300569.htm
June 13, 2008
How to configure PHP settings in .htaccess
When I need to configure PHP settings in .htaccess, I need ‘AllowOverride All’ line in Apache config. Then I can add something like following to .htaccess:
# 6143 is value of E_ALL
php_value error_reporting 6143
April 9, 2008
How to set PHP values in .htaccess
Sometimes I need to set PHP values in .htaccess. And when I forgot that it’s php_flag statement, then I found nice examples of it at http://support.easystreet.com/hosting/unix/dynamic-config.htm
php_flag display_errors on
# Following disables warning when accessing uninitialized array entries like $_SESSION['user_id']
# 4097 = E_ERROR + E_RECOVERABLE_ERROR
php_value error_reporting 4097
If I need to disable access to a folder, I add this to .htaccess:
Order Deny,Allow
Deny from al
December 11, 2007
C-like shortcuts leading to errors in PHP
Today I’ve come across yet another tricky error in PHP… I had the following code. $info in it is an LDAP result array. I wanted to extend the if(..) condition to check whether $info['count'] is exactly 1. So I took
if( $info=$myObject->All($res) ) {
}
and changed it into
if( $info=$myObject->All($res) && $info['count']==1 ) {
}
Suddenly it stopped working, even for the LDAP results about which I knew they had exactly one item. As usual, it was the programmer’s error – but supported by PHP as it doesn’t check types in compile time. What I should have done was
if( ( $info=$myObject->All($res) ) && $info['count']==1 ) {
}
Yet another reason to use strong-typed languages like Java, rather than script lingos as PHP.
November 21, 2007
File uploads with Apache/PHP and Flex; TCP dump
File upload with Apache/PHP
- if your HTML form has a hidden input MAX_FILE_SIZE and you submit a file bigger than that, you won’t get any warning by the browser, and the file won’t be submitted to the server!
File upload in Flex using FileReference
- the file size must be above 0!
TCP dump filtering
sudo tcpdump -i en0 -s 0 -w csv_processing_tcpdump.dmp
-s 0 => print whole packets
tcpdump -s 0 -n -e -A -vvv -r DumpFile.dmp host ip-of-the-target-host
-A => prints packet in ASCII
November 17, 2007
PHP and LDAP, PHP debuggers
26 Sep 07
Delete all values of an LDAP attribute in PHP
ldap_mod_del( $connection, $dn, array( 'attrib-name' => array() ) );
Copy a directory recursively and keep the symlinks- use cp -R - not cp -r
Relative inclusion of files using include/require in PHP
from comments on www.php.net: When I'm dealing with a package that uses relative includes of its own, rather than modify all of their includes, I found it was easier to change PHP's working directory before and after the include, like so:
<?
$wd_was = getcwd();
chdir(“/path/to/included/app”);
include(“mainfile.php”);
chdir($wd_was);
?>
This way neither my includes nor theirs are affected; they all work as expected. Or:
ini_set(‘include_path’, (ini_get(‘include_path’).’;’.$SITEROOT_PATH));
PHP ldap_mod_del()
– it requires attribute values to be indexed by consecutive int keys starting at 0!
PHP debuggers
http://uk3.php.net/debug_backtrace
http://uk.php.net/manual/en/function.class-exists.php
http://www.ibm.com/developerworks/library/os-debug/
http://pecl.php.net/package/apd
http://xdebug.org
– installs OK on Mac OS X 10.4
– if you activate it in php.ini, then commandline PHP stops working!
– error traces refer to PHP sources with lines starting at 0, not starting at 1!
http://gubed.mccabe.nu/?/article/articleview/Download&Gubed=f06cc6837ecb7ab00b0cb1791ad8274e&themex=public
When updating/creating an LDAP object in PHP and you get a funny attribute value
- if the attribute schema is a DN to (any) object
- and if the attrib value shows up as [Root] in ConsoleOne of Novell eDirectory
- and if the attrib values shows as null/empty string in PHP ldap_search and commandline ldapserch
- then you saved/created the object passing PHP null as the value of that attribute to PHP ldap_mod_add()
- solution: remove PHP null values when creating a new LDAP object. If updating an existing LDAP object, remove any existing values of that attribute by ldap_mod_del()