12
Oct 09
I had a problem with your PHP code running or executing seemingly twice. To debug this phenomenon, I put some write-to-file code at the beginning of the script. Surprisingly, whenever I loaded my script in the browser, the file would be written to twice despite my one page load.
The problem was that The page I was developing had an <img> in it with the “src” attribute set blank. When the document was fully loaded, javascript was in place to dynamically assign the “src”. This worked perfectly fine in the pre-server-side-logic stage of development so it was an easy decision to begin debugging server-side logic.
The double execute happens when Firefox sees <img src=”" />. Not knowing what source to assign, it sends a request (the second request) to the current path (again) for the image. Therein lies the problem. It’s interesting to note that Firefox is not to blame, as it’s following HTML specification.
14
Aug 09
Recently I’ve had to import a client’s catalog data from Excel 2007 to the Magento eCommerce Platform. The data in Excel was unsurprisingly in a format that was unsupported by Magento’s import methods. Using code, I needed to parse Excel data into the format Magento required. In PHP, I wasn’t aware of any way to interface with .xls or .xlsx files, so I tried exporting the data to flat-file CSV, where it could be easily manipulated using PHP’s native CSV functions.
Read more »
9
Aug 09
At some point in our programming careers, we’ve had to reorder server-side (probably database driven) lists. For example, allowing users to set the specific sequence that image thumbnails are displayed on the front-end of a photo album.
For “move-item-forwards” functionality, the logic may look like:
move_item_up( index ){
Store the element at index 3 to a temporary variable.
Set the value of index 3 to the value of index 4.
Set the value of index 4 to the temporary variable's value.
}
The “technique” comes into play now, when you have to do the “move-item-backwards” functionality.
Instead of:
Simply use:
Moving an item backwards in a list is the same as moving the previous item forwards. This technique is rather simple and perhaps painfully obvious to some, though it may be useful to others.
31
Dec 08
Revisiting the topic of my previous post, I’ve played around some more with this PHP HTTP Class. This morning, I’ve figured out how to send files over HTTP (actually HTTPS, but it works the same way). If you’ve looked through the author’s test scripts, you see that for file uploads, the provided example is:
$arguments["PostFiles"] = array(
"userfile" => array(
"Data" => "This is just a plain text attachment file.",
"Name" => "attachment.txt",
"Content-Type" => "automatic/name",
),
"anotherfile" => array(
"FileName" => "test_http_post.php",
"Content-Type" => "automatic/name",
)
);
Read more »
30
Dec 08
I’ve found a great PHP script that can essentially turn a web server into a virtual browser. The script is small and lightweight compared to existing solutions (just 62KB) and it isn’t dependent on anything else. I needed it for sending/receiving data through POST (because GET is easy), and more importantly, doing it over SSL. I still need to figure out how to upload files through this, but I don’t think it should be too big of an issue. I’m sure it’s just a matter of encoding.
Read more »