php functions to prevent hacks
Categories: php
strip_tags() removes html and php tags from string. should be immediately called on data input and before any data processing functions.
nl2br() converts newlines to <br />. run strip_tags before calling this function or the <br /> will be stripped.
htmlspecialchars() convert special chars to html entities. & (ampesand) becomes &, < becomes < etc.
2008-12-17 14:53:54 • Link • Comments • Trackbacks
php: is gd library installed?
Categories: php
to check if the server has gd library,
PHP:
if (extension_loaded("gd")) | |
echo "yes!"; |
another way is to check any gd related function, eg
PHP:
if (function_exists("gd_info")) | |
echo "yes!"; |
2008-12-11 14:11:21 • Link • Comments • Trackbacks
php: get image size
Categories: php
Tags: getimagesize, image, php
to access basic image information like width and height, call getimagesize, which returns data in array format such as
Code:
Array | |
( | |
[0] => 640 // width | |
[1] => 426 // height | |
[2] => 2 // not sure what this is. anyone? | |
[3] => width="640" height="426" // for <img> param | |
[bits] => 8 | |
[channels] => 3 | |
[mime] => image/jpeg // mime type | |
) |
note: this function does not require gd library.
2008-12-04 16:06:14 • Link • Comments • Trackbacks
php: image manipulation
Tags: fedora, gd, image, php, ubuntu
the gd image library provide functions to manipulate image files.
on some installations, this does not come as default and needs to be installed.
on fedora, the command is
yum install php-gd
on ubuntu, the command is
sudo apt-get install php5-gd
2008-12-04 10:57:59 • Link • Comments • Trackbacks
php: increase memory limit
Categories: php, unix, apache2
errors like ‘allowed memory size of x bytes exhausted’ or ‘zero size reply’ usually means there’s not enough memory allocated for php. you need to increase the value.
if you have admin access, you can edit /etc/php.ini, locate and update ‘memory_limit’ to values like 16M, 32M, 64M. this change is global to the system. restart apache after update.
if not, add this in php script:
PHP:
ini_set("memory_limit", "32M"); |
2008-10-31 10:21:59 • Link • Comments • Trackbacks
