Category: Programming

  • Data scraping: how to prevent

    Data scraping is common these days with so many data driven web applications out there. Regardless of the legality and ethics of the subject, it just sucks to know that there may be people out there who might hammer at your site to “take” all your hard work for their selfish use. That being said, it’s almost impossible to prevent people from taking your data, especially if your data is easily accessible by the public.

    You’re probably here because you’re suspicious of possible data scraping activities happening in your website. While there are preventive measures you can take to keep the scrapers out, there are always holes for the smart ones to get through and eventually take the data they want. What we want to do is make it very difficult for the average scraper to hack away the data.
    (more…)

  • SQL Server: SELECT INTO inside both IF and ELSE blocks

    I ran across this problem earlier today, and thought I should address this here in case anyone is interested in my solution.

    When doing a SELECT INTO command against the same temp table in both IF and ELSE blocks, you will quickly learn that SQL Server complains that there “is already an object named ‘#temp’ in the database”. What one can do to avoid this problem is declare the temp table before the IF/ELSE block and insert into the table afterwards, but what if you want to use SELECT INTO instead?

    if @var = 1
    	select 'abc' into #temp;
    else
    	select 'def' into #temp;
    
    select * from #temp;
    

    (more…)

  • PHP Warning: json_encode() [function.json-encode]: Invalid UTF-8 sequence in argument in god_i_hate_this.php

    Ever get the following error?

    • PHP Warning: json_encode() [function.json-encode]: Invalid UTF-8 sequence in argument in…

    Then you are in the same boat I was in, and unfortunately for me, the solution wasn’t as straightforward as I thought it was. The problem we are seeing is that the value being encoded to json is not UTF-8 encoded data. PHP function json_encode, unfortunately, will only accept UTF-8 as its parameter. (more…)

  • Convert XML to array and vice versa in PHP

    As a developer, it is common to search the web for an existing (open source) code snippet to re-use for an application, but it is rare for the developer to just copy code online and use it straight in their application without modifying it first.

    I am one of many developers who like to save time if possible by using open source code if coding from scratch takes longer than a couple of minutes, but there are times when one cannot be found. I ran into such situation when I wanted a function that converts an XML string into an array. Unfortunately, most are overly complicated for what I wanted, so I decided to create my own and share with the world. The following function converts XML strings into a PHP array while retaining the level depths of the XML but all attributes are ignored. (more…)

  • php.js

    If you are a PHP programmer struggling with javascript, then php.js is your answer.
    (more…)

  • PHP MVC framework war

    Back when CakePHP’s v1.2 was still in its beta stage, I started learning the PHP language using the MVC (model-view-controller) framework, and I grew to love the language. I became more fluent with the language as I grew more biased towards cake. I would often google MVC comparisons like “CakePHP vs codeigniter“, or “CakePHP vs symfony“, etc, but in my heart, I knew CakePHP was the one for me.
    (more…)