Apache + PHP installation error: The specified module could not be found.\r\n in Unknown on line 0

Common Apache error: “PHP Warning:  PHP Startup: Unable to load dynamic library ‘C:\\php5\\ext\\php_pdo_mysql” in the Apache log file (C:\Program Files\Apache Group\Apache2\logs\error.log).

I just installed Apache and Tomcat servers on my new laptop in order to run php and java at the same time; however I ran into an issue with MySQL database connection when I execute a php page.  There’re a few things that you can try to make your server work properly.

First: check php.ini file to make sure that you have extension_dir = “C:\php5\ext”.

Second: go to php directory, copy the libmysql.dll file and paste it to Apache bin directory. Remember not to remove it from php directory. Then restart your server to take effect.

Comparison of PHP json libraries

Today I start a project of building an Android Application that allows lenders to search for a certified and trained appraisers within their preferred area. To build a simple app, you can use REST to return data. You will need Json extension on the PHP server to have the task done. If you would like to know how to install JSON on your PHP server (only PHP version below 5.2), go to http://www.php.net/manual/en/json.installation.php. Most of the hosting servers nowadays have PHP version 5.2 that comes with json enabled by default, so you don’t have to install anything.

Feature Matrix

Feature PHP json PEAR json ZEND json XMLRPC json
Version 1.2.1 2006/03/31 1.31 2006/06/28 20061105-1470 CVS Id 1.25 2006/11/05
PHP version compatibility 4 (for windows the dll for php 4.3 and above is available on pecl4win), 5 4.0.6, 5.0 5.0 4.2, 5
PHP files used 0 1 6 2
Encodes to 7-bit ASCII clean JSON strings, using unicode escape sequences Yes Yes No Yes
Supports encoding php strings from different charsets Assumes UTF-8 Assumes UTF-8 Does not convert string data: it is up to the user to take care about conversion to the desired charset UTF-8, ISO-8859-1, ASCII
Supports decoding JSON data that has not an an array or object as top level element No Yes Yes Yes
Supports decoding JSON objects as either php arrays or objects Yes Yes Yes Yes
Supports distinguishing a failed decoding from decoding a single NULL value Yes (single NULL value cannot be decoded) No Yes (exception thrown) Yes
Supports decoding JSON to different charsets Only UTF-8 UTF-8, ISO-8859-1, ASCII
Supports features of Javascript outside the scope of JSON None: only data in accord with the Json spec is accepted Parses almost everything as valid (within an array) Some Tries to mimic the behaviour of common web browsers js engines;
keeps type information for float and integer php values (a float value of 1.0 will be encoded ad later decoded by the lib as float, even though in js only ‘numbers’ exists)
Extra features Provides a compatibility layer that implement the same API as the PHP native json extension;
adds support for the json-rpc webservice dialect

Sample codes

Goal PHP json PEAR json ZEND json XMLRPC json
Encode a php value to JSON string $out = json_encode($data); $value = new Services_JSON();

$out = $value->encode($data);

$out = Zend_Json::encode($data); $value = php_jsonrpc_encode($data);

$out = $value->serialize();

Decode a JSON string to PHP value (Json objects as php objects) $out = json_decode($data); $value = new Services_JSON();

$out = $value->decode($data);

try {
$out = Zend_Json::decode($data, Zend_Json::TYPE_OBJECT);
} catch (Exception $e) { }
$value = php_jsonrpc_decode_json($data);

if ($value) $out = php_jsonrpc_decode($value, array(‘decode_php_objs’));

Decode a JSON string to PHP value (Json objects as php arrays) $out = json_decode($data, true); $value = new Services_JSON (SERVICES_JSON_LOOSE_TYPE);

$out = $value->decode($data);

try { $out = Zend_Json::decode(); }

catch (Exception $e) { }

$value = php_jsonrpc_decode_json($data);

if ($value) $out = php_jsonrpc_decode($value);

How to cut down page-not-found error records in your Watchdog table?

Some of you who own Drupal website may notice that now and then people are trying to hack your server with tons of call to phpMyAdmin/scripts/. I’ve checked all IP addresses that are used to visit my site, I found those in Watchdog table in DB. Those IP addresses are from all over the world such as China, Russia, Canada, USA, Ukraine, … you name it. This is very annoying when the watchdog table is loaded with not-found-page errors instead of system errors that you’re more interested in. Today I will show you how to stop all of these nonsense log from inserting into your Watchdog table.
Step 1: Open the common.inc file from /includes/ directory. Search for the function named drupal_not_found().

Step 2: Having some fun changing the way how Drupal inserting error to watchdog table. Add the codes below at the beginning of the function.

$get_error_text = check_plain($_GET['q']);
$pattern = "/config/i";

if(!preg_match($pattern, $get_error_text )){
//place this watchdog function call inside this condition
watchdog('page not found', $get_error_text, NULL, WATCHDOG_WARNING);
}

You’re done. Upload this common.inc file to your web server. You will notice that there’s no more log of this type of error recorded to your database again. All other interested errors are still recorded.


Why does your website get hacked?

I have seen so many websites got hacked from the Admin User Interface. Most files on the server have been overwritten with embedded codes such as <iframe> or Javascript or something else. Why? If hacker gain the access to admin of your website, they can do everything. They can view your configuration file. They’ll know all credentials that have been set up to run your website including DB access, SMTP mail server, FTP access. So to prevent this happens, you have to rename a few files or type some exit() function in some files that are the hackers’ targets.

If your system has phpMyAdmin installed, go to directory /scripts/ , open the file setup.php and type exit(); on the second line. This will make sure that hackers won’t have a chance to execute this setup file. If you have configuration.php or config.php or wp-config.php anywhere on your system, set permission level 0444 only, not higher than that. You shouldn’t have any directory called /admin in the root of your directory. Below is all names of directories you should avoid. This list has been recorded on my server to see how hackers behave when they’re trying to gain access to my server. Of course, they can never get into my server since I’m monitoring them closely.

In case, if you already got hacked, you should change FTP and Database credentials right away. Do not wait!


How to fix a link to input type button if it doesn’t work in IE 7.0/8.0

If you use a form button (or input of button type, either one) within an anchor, instead of using text or creating a graphic. This link will work fine in across all other browsers but IE either 7.0 or 8.0. Even though the correct URL in the status line and the tooltip is showing, it DOES NOT initiate the link.

The code is initially coded:

<a href="http://www.adomain.com/anypage.html"><input type="button" name="mybutton" value="Click Me" class="blue_btn"></a>

There’re a few ways you can fix it.

Method 1: Use form around the input. This technique will make sure that it always works in all browsers including IE. If the link to a page that is non html/php/jsp/asp such as .pdf, jpg,… you may want to use method 2 below. The <form> method doesn’t do any good in this case.

<form action="http://www.adomain.com/anypage.html">
<input type="submit" value="Click Me" class="blue_btn">
</form>

Method 2: Use onClick Javascript plugged in directly to the input tag, or call a JavaScript function that will open another page.

This Script will open a page within the same frame.

<input type="button" class="blue_btn" onClick="top.window.location='http://www.adomain.com/anypage.html">

This Script will open another page in another frame.

<input type="button" onClick="window.location='http://www.adomain.com/anypage.html">