Resize image in PHP

July 27, 2008 · Posted in php · Comment 

Uploaded images from user can be of any size.  If you need to use these images, they need to be resized upon upload. Here is a helper class to manage resizing of the images.

Let me know if you find any bugs.

Enable register_global through .htaccess

June 17, 2008 · Posted in apache, php · Comment 

I would not recommend to enable register_globals, but if you need to enable the register_globals for a particular web folder, you can edit the .htaccess file and append the following to it

php_flag register_globals on

Restart apache and you are on your way.

PHPImpact: 30 useful PHP classes

May 30, 2008 · Posted in php · Comment 

PHPImpact has posted 30 useful PHP classes here.

Which ones do you use? I have used the following:

Still a lot more interesting ones which I haven’t tried.

PHP single quotes Vs double quotes

May 27, 2008 · Posted in php · 1 Comment 

Any time you put something in “double” quotes, you are asking PHP interpreter to check that content for a variable. So even though the line do not contain variables within the double quotes, PHP will waste precious computing time scanning them anyway.

$sql = 'select * from employee';

will be much faster than

$sql = "select * from employee";

mysql_insert_id() returns NULL or 0

February 29, 2008 · Posted in php · Comment 

If you have multiple mysql connections (i.e. mysql_connect() or mysqli_connect()) on the page you will need to specify the the connection you are using when calling this function.

example:

mysql_insert_id($MY_CONN);

Downloading a page in PHP

August 13, 2007 · Posted in php · Comment 

If you ever need to download a HTTP/FTP or any page, try not to use fopen() and fread() functions. They work but will take enormous amounts of time as compared to curl functions. Try doing as follows:

To GET a page using a url
<?
$url=”http://any.url”;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$store = curl_exec ($ch);
$xml = curl_exec ($ch);
curl_close ($ch);
?>
To POST to a page using values and fields:
<?
$url=”http://any.url”;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, “fieldname=fieldvalue&fieldname=fieldvalue&”);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$store = curl_exec ($ch);
$content = curl_exec ($ch); # This returns HTML
curl_close ($ch);
?>

For more information, check the curl function on PHP website.

PHP Data Objects

August 8, 2007 · Posted in php · Comment 

I was looking for a quick reference/tutorial to implement Data Objects with PHP, very similar to what exists in Java. Found a nice explanation at PHP Data Object

  • Calendar

    February 2012
    M T W T F S S
    « Jan    
     12345
    6789101112
    13141516171819
    20212223242526
    272829