Feb 28, 2012

PHP :: Advice on using count()

I may be a little late realising this, but a few dozen thousand lines of PHP code in, it's better late than never.

Let's look at example #1 on count() manual

$result count(null); // $result == 0
$result count(false); // $result == 1

Does this strike you as a bit odd? Why the hell should count(0) or count(false) be equal to 1?

Well strangely enough, that's how it is. So for example, if you wrote a mysql_query() wrapper where you return false if the query fails and if you expect an array where you check the number of items, you find out that if the query fails, the count will return 1, and you might get some unexpected results.

Keeping computer security in mind, it's best to avoid count() when just checking if some data is returned.

Alternatives are empty() if checks if a variable contains something other than 0, '0', null, false, array() or ''.

OR, in your wrapper functions, if the query fails, just return NULL!

Apache :: Could not determine fully qualified domain name

Error message:

apache2: Could not reliably determine the server's fully qualified domain name, using for ServerName

Is preety much self-explanatory

Add this
ServerName localhost

In your server configuration file.

Apache :: VirtualHost overlap on port

Errors like

[warn] _default_ VirtualHost overlap on port 443, the first has precedence

are caused because the virtualhosts are not named.
(The same applies for any other port, for example 80)

Add this in your apache configuration file

NameVirtualHost *:443

In Ubuntu server, Linux, that configuration is actually located in the ports.conf file in /etc/apache2.

NameVirtualHost *:80
NameVirtualHost *:443

Listen 80

Feb 26, 2012

MySQL not starting when restoring files in /var/lib/mysql

If you get errors like:

120226  1:54:14 [Note] Plugin 'FEDERATED' is disabled.
120226  1:54:14  InnoDB: Initializing buffer pool, size = 8.0M
120226  1:54:14  InnoDB: Completed initialization of buffer pool
120226  1:54:15  InnoDB: Started; log sequence number 0 44233
120226  1:54:15 [ERROR] Event Scheduler: Failed to open table mysql.event
120226  1:54:15 [ERROR] Event Scheduler: Error while loading from disk.
120226  1:54:15 [Note] Event Scheduler: Purging the queue. 0 events
120226  1:54:15 [ERROR] Aborting

120226  1:54:15  InnoDB: Starting shutdown...
120226  1:54:20  InnoDB: Shutdown completed; log sequence number 0 44233
120226  1:54:20 [Note] mysqld: Shutdown complete


120226  1:59:18 [Note] Plugin 'FEDERATED' is disabled.
mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
120226  1:59:18 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
120226  1:59:18  InnoDB: Initializing buffer pool, size = 8.0M
120226  1:59:18  InnoDB: Completed initialization of buffer pool
120226  1:59:18  InnoDB: Started; log sequence number 0 44233
120226  1:59:18 [ERROR] mysqld: Can't find file: './mysql/host.frm' (errno: 13)
120226  1:59:18 [ERROR] Fatal error: Can't open and lock privilege tables: Can't find file: './mysql/host.frm' (errno: 13)

You need to check the file permissions.

The user and group is mysql:mysql
File permissions are rw for user and group (660)

chown mysql:mysql -R /var/lib/mysql
chmod 660 -R /var/lib/mysql

Feb 22, 2012

NETBIOS / Samba share does not accept username and password

If your username and password gets rejected when logging in MS file share, try using the INT domain for login.


username: INT\your_username
password: your_password

Feb 21, 2012

Linux/Ubuntu :: pure-ftpd does not allow login to user with /usr/sbin/nologin shell

You have created a user with /usr/sbin/nologin shell (ftp-only user) in Linux/Ubuntu.
If you SSH to the box with this username and password it should not work.
If you FTP to the box with this username and password it should.

Pure-ftpd does not permit login if the shell is set to /bin/false or /usr/sbin/nologin.
If you change the shell to /bin/bash it works.

Connected to localhost.
220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 2 of 50 allowed.
220-Local time is now 17:53. Server port: 21.
220-This is a private system - No anonymous login
220-IPv6 connections are also welcome on this server.
220 You will be disconnected after 15 minutes of inactivity.
Name (localhost:root): ftponly
331 User ftponly OK. Password required
530 Login authentication failed
Login failed.
Remote system type is UNIX.
Using binary mode to transfer files.

You need to add the nologin or false shell to the file /etc/shells.

[email protected]:/# cat /etc/shells
# /etc/shells: valid login shells

Feb 18, 2012

PHP :: sending SMS via najdi.si FREE SMS

You need to make an account on https://id.najdi.si before you can use the code.

Example usage:
$sms = new sms();
$sms->send('090666666','one does not simply send an SMS');