How should I choose an authentication library for CodeIgniter? [closed]

Update (May 14, 2010): It turns out, the russian developer Ilya Konyukhov picked up the gauntlet after reading this and created a new auth library for CI based on DX Auth, following the recommendations and requirements below. And the resulting Tank Auth is looking like the answer to the OP’s question. I’m going to go … Read more

Get table column names in MySQL?

You can use DESCRIBE: DESCRIBE my_table; Or in newer versions you can use INFORMATION_SCHEMA: SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = ‘my_database’ AND TABLE_NAME = ‘my_table’; Or you can use SHOW COLUMNS: SHOW COLUMNS FROM my_table; Or to get column names with comma in a line: SELECT group_concat(COLUMN_NAME) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = ‘my_database’ AND … Read more

Why would one omit the close tag?

Sending headers earlier than the normal course may have far reaching consequences. Below are just a few of them that happened to come to my mind at the moment: While current PHP releases may have output buffering on, the actual production servers you will be deploying your code on are far more important than any … Read more

Can I try/catch a warning?

Set and restore error handler One possibility is to set your own error handler before the call and restore the previous error handler later with restore_error_handler(). set_error_handler(function() { /* ignore errors */ }); dns_get_record(); restore_error_handler(); You could build on this idea and write a re-usable error handler that logs the errors for you. set_error_handler([$logger, ‘onSilencedError’]); … Read more

Send email using the GMail SMTP server from a PHP page

// Pear Mail Library require_once “Mail.php”; $from = ‘<fromaddress@gmail.com>’; $to = ‘<toaddress@yahoo.com>’; $subject=”Hi!”; $body = “Hi,\n\nHow are you?”; $headers = array( ‘From’ => $from, ‘To’ => $to, ‘Subject’ => $subject ); $smtp = Mail::factory(‘smtp’, array( ‘host’ => ‘ssl://smtp.gmail.com’, ‘port’ => ‘465’, ‘auth’ => true, ‘username’ => ‘johndoe@gmail.com’, ‘password’ => ‘passwordxxx’ )); $mail = $smtp->send($to, $headers, … Read more

When do I use the PHP constant “PHP_EOL”?

Yes, PHP_EOL is ostensibly used to find the newline character in a cross-platform-compatible way, so it handles DOS/Unix issues. Note that PHP_EOL represents the endline character for the current system. For instance, it will not find a Windows endline when executed on a unix-like system.

Difference between array_map, array_walk and array_filter

Changing Values: array_map cannot change the values inside input array(s) while array_walk can; in particular, array_map never changes its arguments. Array Keys Access: array_map cannot operate with the array keys, array_walk can. Return Value: array_map returns a new array, array_walk only returns true. Hence, if you don’t want to create an array as a result … Read more