Archives for the 'PHP' Category

Apache 2.2 + PHP 5.1.1 on Windows

After adding the following lines to the end of httpd.conf:
LoadModule php5_module “c:/php/php5apache2.dll”
AddType application/x-httpd-php .php
PHPIniDir “C:/php”
You restart Apache and get the following error:
The Apache2.2 service terminated with service-specific error 1 (0×1)
The solution is to download php5apache2.dll-php5.1.x.zip courtesy of Steffen. Overwrite php5apache2.dll in your PHP folder and copy httpd.exe.manifest to your Apache2 bin folder.

23 March 2007 | Software engineering, PHP | 1 Comment

PHP 32-bit Left Shift Function

function leftshift32($number, $steps)
{
// convert to binary (string)
$binary = decbin($number);
// left-pad with 0’s if necessary
$binary = str_pad($binary, 32, “0″, STR_PAD_LEFT);
// left shift manually
$binary = $binary . str_repeat(”0″, $steps);
// get the last 32 bits
$binary = substr($binary, strlen($binary) - 32);
// if it’s a negative number return the 2’s complement
// otherwise just return the number
if ($binary{0} == “1″)
{
return -(pow(2, […]

16 November 2006 | Software engineering, PHP | 3 Comments

Adventures in 64-bit PHP: 32-bit Left Shift on a 64-bit Machine

My team member was looking for source code that can parse Excel files and found PHP-ExcelReader. It worked fine on her computer, so she ported it to production. After running it for a few times the server became totally unresponsive.
I went over to take a look at the server and the mouse pointer […]

16 November 2006 | Software engineering, PHP | 1 Comment

Encode Your URL Parameters

If you wish to query a URL using the HTTP GET method, problems will arise if your parameters contain characters such as ? and &.
The solution is to use encodeURIComponent (client-side Javascript) or Server.URLEncode (ASP) or urlencode (PHP).
There is no need to do any extra work at the server side for Request.QueryString(”…”) or $_GET[”…”].
encodeURIComponent example:
location.href […]

21 October 2006 | Software engineering, HTTP, Javascript, ASP, PHP | No Comments

Leaky PHP Session Variables

If you create a session variable, e.g. $_SESSION[”username”], it will conflict with a local variable named $username.
Therefore, the best practice would be to prefix all session variables with a leading underscore, e.g. $_SESSION[”_username”], so that they do not conflict with local variables.
Reference:
http://www.php.net/manual/en/ref.session.php#45534

19 October 2006 | Software engineering, PHP | 1 Comment

idea rumah