|
|
|
It amazes me how many developers just use something along the lines of:
if($var != '')
to check for an empty value.
Yet, if someone just hits the spacebar, $var won't be empty, and will appear OK to the above
conditional.
Whitespace has value people. For that matter, so do newlines and tabs (\n and \t,
respectively, along with a few more (consult your languages' manuals. They are, almost, the
best friends you have as a programmer).)
In PHP, use trim() to hack off whitespace, then use empty() to make sure it's, you guessed it,
not empty.
http://www.php.net/manual/function.trim.php
http://www.php.net/manual/function.empty.php
In Perl use something like:
if($var !~ /^\s*$/)
And, of course, always filter your input, when your data will be coming from an outside source,
to ensure that you'll get exactly what you're looking for.
For PHP, there are a host of terrific functions for this purpose. Check them out:
http://www.php.net/manual/ref.strings.php
For Perl (CGI), you will most certainly want to enable Taint checking. Stick the -T switch at the
top of your script/application:
#!/usr/bin/perl -T
use strict;
You'll see errors, and it's in your best interest to learn what they mean.
|
|
| Checking to see if a file exists with PHP Categories : PHP, Filesystem, Perl | | | How would s/(http:\/\/.*?) /<a href=$1> $1 <\/a>/g; look in php? Categories : PHP, Perl, Regexps | | | STR - a Perl-like string manipulator class - The str class provides 4 perl-like methods for manipulating strings and
other scalar variables. Categories : PHP, PHP Classes, Perl, Strings | | | Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP, PHP, HTML, PDF, Excel | | | PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use! Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP | | | PHP Object Example of the Perl DBI with MySQL Categories : PHP, PHP Classes, MySQL, Databases, Perl | | | Retrieve text from table and email to your e-
address in pipe delimited format. Categories : PHP, MySQL | | | Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs. Categories : Databases, PHP, MySQL, Complete Programs | | | A PHP function to encrypt and decrypt a number or string or a combination of the two. Categories : PHP, Encryption, Security | | | Using $PHP_AUTH_USER and $PHP_AUTH_PW to authenticate. Categories : Authentication, PHP | | | file class , uploade file , download file already uploaded on another website Categories : PHP, PHP Classes, Filesystem, Web Services | | | Authorize.net AIM Interface Class v1.0.0 Categories : PHP, PHP Classes, Ecommerce, Payment Gateways | | | Cut your MySQL Connections to 1 line of code Categories : PHP, Beginner Guides, Databases, MySQL | | | A simple class with some HTML output functions that would come in handy for consistent page layout etc. Categories : PHP, PHP Classes, HTML and PHP, HTML, Navigation | | | recode -- Recode a string according to a recode request Categories : PHP, PHP Functions, Recode | |
|
|
|