Tag Archive for 'code'

A better phpinfo

The phpinfo() command comes in very useful when you want to check details about your PHP install and server setup. However, there is a lot of output and you won’t need it all. Not everyone knows that you can pass parameters to the function to narrow the scope of the information displayed.

I came up with this simple method to view the results of using these parameters and make it easy to switch between them.

< ?php

	$options = array('CONFIGURATION', 'ENVIRONMENT', 'MODULES', 'VARIABLES', 'GENERAL', 'CREDITS', 'LICENSE', 'ALL');
	$display = (empty($_GET['display']) || !in_array(strtoupper($_GET['display']), $options)) ? 'ALL' : strtoupper($_GET['display']);

	$navigation = array();

	foreach($options as $key=>$value) {
		$navigation[] = ($value != $display) ? '<a href="' . $_SERVER['SCRIPT_NAME'] . '?display=' . $value . '">' . $value . '</a>' : '<strong>' . $value . '</strong>';
	}

	ob_start();

	switch($display) {
		case 'CONFIGURATION':
			phpinfo(INFO_CONFIGURATION);
			break;

		case 'ENVIRONMENT':
			phpinfo(INFO_ENVIRONMENT);
			break;

		case 'MODULES':
			phpinfo(INFO_MODULES);
			break;

		case 'VARIABLES':
			phpinfo(INFO_VARIABLES);
			break;

		case 'GENERAL':
			phpinfo(INFO_GENERAL);
			break;

		case 'CREDITS':
			phpinfo(INFO_CREDITS);
			break;

		case 'LICENSE':
			phpinfo(INFO_LICENSE);
			break;

		case 'ALL': default:
			phpinfo();
			break;
	}

	$content = ob_get_clean();

	if (('CREDITS' === $display) &amp; preg_match('/<h1><a href="([^"]+?)">PHP Credits< \/a>< \/h1>/', $content, $matches) & !empty($matches)) {
		$content = file_get_contents('http://' . $_SERVER['HTTP_HOST'] . $matches[1]);
	}

	echo str_replace('<body>', '</body><body><div class="center options"><p>' . implode(' | ', $navigation) . '</p></div>', $content);

?>

It’s also worth pointing out that the information exposed by this function can be useful to people who want to locate any weaknesses in your system so I would recommend restricting access to this file with a password, by an IP address range or only uploading the file to your webserver temporarily and removing it as soon as you’re finished with it.

Patently obvious

US Patent law is frankly in somewhat of a mess. Any system that allows a man to hold a patent on a method for playing on a swing needs or awarded on a staple element of computing (like the linked list) to be looked at in my opinion. The Patent Office just doesn’t have the staff to give each application the diligence it needs and the subsequent backlog is increasing as is the number of submarine patents and patents awarded despite overwhelming prior art. Obviousness and prior art is supposed to invalidate a patent but this doesn’t stop anyone from trying their luck. Amazon are frequently quoted in geek forums for this. Trying to cash in once someone big enough does something of note (Smartphones) or popular (online games) that may possibly be covered by a vague patent is big business.

Finally, the tide may finally be turning.

Speaking as a developer I was glad to hear about a project that aims to address the inherent problems with the system with regard to software. Imaginatively called End Software Patents, it seeks to highlight the absurdity in the idea that source code and natural mathematics can somehow be patented.

Microsoft has been sabre-rattling of late, claiming that Linux infringes on hundreds of patents that they hold (read: purchased). Co-incidentally, they do have a very pertinent patent for detecting user frustration when using their software.

Just as I was beginning to think that the UK was understanding some of the problems with legal aspects of software and the implications of software patents it looks like we’re heading in the same direction. The UK government is currently embroiled in a legal case with Symbian which will hopefully clarify things.

Just don’t get me started on gene patents.