Category: "PHP"
Simple Hit Counter Example
Apr 18th
Hit counters are valuable because they allow site visitors to see how many people visited or used a server-based tool.
This is a very simple implementation of a counter. You can see it run at the link above.
The counter code is in the back-end/server-side logic.
PHP5 version
$iCount=file_get_contents('count.txt');
file_put_contents('count.txt',$iCount+1);
echo '<p><span style="font-weight:bolder;border:1px solid #000;padding:2px;">'.$iCount.' gradients created.</span></p>';
PHP4 version
$iCount=file_get_contents('tri.count.txt');
$fp=fopen('tri.count.txt','w+');
fwrite($fp,$iCount+1);
fclose($fp);
echo '<p>'.$iCount.' downloads</p>';
Gradient Generator Notes
Apr 15th
Value
The value of this utility is in its simplicity. Image, photo, and graphical editors are very action-intensive. This tool allows a selection of a single color, the width/height, and then it creates all four gradients. This is a very fast way to create custom gradients, and it is easy to use.
UI
- Page should not require scrolling to operate, read instructions, and access gradients and text.
- Interface should allow both mouse and keyboard control. Gradients can be generated by mouse only, or keyboard.
- Interface should allow entry of hex color code and width/height directly.
- It is assumed the gradient will have enough color that a white title will be visible.
LAMP Stack
- CSS/divs are used to layout the page.
- ColorPicker is a dojox widget. Additional widgets are the width/height input and the slider. Client-side validation is run off the widgets.
- Two buttons are offered, one that creates the gradients and one that resets the inputs to the default values.
- When the create button is clicked, the form is validated and submitted to the server.
- PHP5 is used for the back-end script because it supports json_encode.
- HTML is returned from the back-end script and placed in the dojo ContentPane.
- The background image for the page is set to one of the gradients. This is a good preview method and it makes the page more interesting.
- ImageMagick is used to create the gradients. It creates one gradient and rotates it to create the remaining three.
- Directory index should not be accessible. This is accomplished by another file.
- File system - image files must be writeable by Apache.
Optional Parameters - Extending Existing Functions
Apr 14th
Both PHP and javascript allow optional parameters and variable arguments.
PHP
- func_get_args() - allows you to get the arguments for a function. Great if you need a variable number of arguments, perhaps for something like sprintf. http://us3.php.net/manual/en/function.func-get-args.php
- Default arguments - allows you to set a default value for an argument. This also effectively makes the argument optional, since if it isn’t passed, the function won’t crash. Important if you have to add something to a function without disrupting existing code that calls it. http://us3.php.net/manual/en/functions.arguments.php#functions.arguments.default
javascript
- The arguments sent to a function in javascript can be accessed as function_name.arguments. To find out how many arguments were passed, you can use function_name.arguments.length. http://www.w3schools.com/jS/js_functions.asp
- Implementing default arguments with javascript can be done by using the arguments array.
Multi-Dimensional Array Sorts for PHP
Apr 2nd
To sort a multi-dimensional array in PHP, you can use usort, like so:
usort($aArray,"cmp_func");
function cmp_func($a,$b)
{
return strcasecmp($a['x'],$b['x']);
}
dojox Grid Select Indicator Demo
Mar 7th
Demonstration of a selection indicator for a dojox grid.
Notes:
- Grey checkmark serves as select all/deselect all, if no rows are selected, clicking on the checkmark will select them all, if any rows are selected, all will be deselected.
- Row selector uses a green checkmark to indicate selection. Additional styling can be applied.
- Add and remove rows work, but no save is performed.
- Icons from Crystal Project (http://everaldo.com/crystal)
* Demonstration is for the design, not operation of grid.