Tag Archives: PHP

Site with useful online tools and utilities launched

Today we launched a new website full with useful tools and utilities – Urih.com

Some of featured services:

  • What is My IP – shows your IP address, that is seen by web servers and other network users.
  • Subnet Calc – network subnet calculator that supports dotted decimal and CIDR notation.
  • SilverBench – online multicore CPU benchmarking tool, that has very nice CPU stress test feature.
  • And many more…

In the coming days I will write some more details and some usage examples. Currently, some facts:

  • All is running on PHP 5.2 and 5.3, Apache, MySQL and Linux – LAMP. Technology: HTML 4.01 strict and CSS 3.
  • SilverBench is written in C#, Silverlight 3, .NET.
  • All is done in spare time by 3 people.
  • The only image used in site is the Favicon. As a consequence, site does not work with IE6.
  • Site tested and works on all major browsers: Mozilla Firefox 3 and 4; Internet Explorer 8 and 9; Opera 10; Apple Safari 5.
  • Home logo is displayed incorrectly in Google Chrome version 10, however Chrome 9 and 11 Beta displays it correctly.

Same path – different files

You probably know from DOS / Windows / Linux / Mac OS, that it is impossible to create two files with the same name and extension in the same folder / directory.

Yesterday, I saw a miracle – two programs show the same file differently. One program was PHP interpreter (fread funciton), other FAR Manager.

First reaction – PHP must be mishandling binary data. Quick search – fread is Binary-safe file read… second thought – PHP ord is converting using Windows code page… no bin2hex is giving the same result.

Second reaction – if two programs show this file differently, and as an example I was using .exe file, this must be some virus or worm, that has installed some poorly coded rootkit.

Today, with fresh view on this strange behavior, I started to get picture from memory. PHP is 32-bit program, FAR that I am using is 64-bit. Raymond Chen or someone else from Microsoft has written, that Windows does not allow 32-bit programs access 64-bit dlls, so that must be it.

A little search and – Registry and file redirection (Article ID: 896456):

The WOW64 subsystem isolates 32-bit binaries from 64-bit binaries by redirecting registry calls and some file system calls. The WOW64 subsystem isolates the binaries to prevent a 32-bit binary from accidentally accessing data from a 64-bit binary. For example, a 32-bit binary that runs a .dll file from the %systemroot%\System32 folder might accidentally try to access a 64-bit .dll file that is not compatible with the 32-bit binary. To prevent this, the WOW64 subsystem redirects the access from the %systemroot%\System32 folder to the %systemroot%\SysWOW64 folder. This redirection prevents compatibility errors because it requires the .dll file to be specifically designed to work with 32-bit programs.

My test file path was: C:\Windows\System32\Notepad.exe and 32-bit application accessed redirected version – C:\Windows\SysWOW64\notepad.exe. This is by design in 64-bit world.

P.S. OS version Windows 7 Ultimate 64-bit.

PHP $_POST returns only one item for SELECT multiple HTML tag

PHP developers decided that values posted from HTML select tag with attribute multiple, somehow overwrites some internal variable data. Basically it goes like this – you have the following form with a select tag:
<form action="/post.php" method="post">
  <select name="MyMultiSelect" multiple>
  <input type="submit" value="send">

and in PHP you try to access $_POST (An associative array of variables passed to the current script via the HTTP POST method):

And guess what? When you select, lets say one, two and three in browser, the array looks something like:
array(1) { ["MyMultiSelect"]=> string(5) "three" }

Strangely, the cause is some overwrite that is described in PHP FAQ: How do I get all the results from a select multiple HTML tag? For me it is mystery, why did PHP developers choose to overwrite values posted by HTTP standard post?

The problem is, that they propose to add square brackets to HTML code, like:
<select name="MyMultiSelect[]" multiple>

Beside, that I do not like ‘[]’ in my Valid HTML 4.01 Strict code, the problem is, that you may not have access to that HTML code. In my case it is legacy application, that is available in binary form only.

The solution that I come up is, to use raw $_POST data using PHP file_get_contents in combination with PHP input/output streams namely php://input

php://input allows you to read raw POST data.

Here is a sample code:
$data_from_post = file_get_contents("php://input");

And output is:
string(...) "MyMultiSelect=one&MyMultiSelect=two&MyMultiSelect=three"