Hello,
I'm in the situation described in Newbie FAQ sticky; i.e. my scripts won't work. I've learned PHP/mySQL fairly well in the past, but most of it is lost in the back of my filing system and i'm starting over.
I'm working out of Kevin Yank's "Build Your Own Database Driven Website" (SitePoint) First Edition, which is like seven years old, but i have the new code samples downloaded from SitePoint, so i can see the more obvious changes like using $_GET() to retrieve variables, etc..
My problem is i seem to have run into a catch-22 where i don't want to write any scripts without understanding the security consequences, but most the advice makes no sense to me because i haven't read far enough yet to know how to implement it.
E.g. i found out this morning that $_SERVER['PHP_SELF'] is insecure if improperly implemented. The advice given in this case, "write a function for everything", doesn't compute because i don't even understand the functions given as examples.
Then there's all the ambiguously stated advice such as "escape all user input" or "Don't output unescaped input". Even the more specific advice such as given in the sticky i.e. "make sure you use strip_tags(); and use the htmlentities etc." isn't very helpful if i don't know how to use them, in what circumstances, or what is "etc.".
The article linked from the PHP_SELF example says, among other things, "only a fool would "echo $_GET['param'];"", and yet that's precisely what my reference material is telling me to do, even in the current (Third Edition) code samples.
For my immediate purposes, i'd just like to know:
1.) Is the example solution:
htmlentities($SERVER['PHP_SELF'])
...a direct replacement for $SERVER['PHP_SELF'], or if it might do something unexpected to my output and leave me wondering what's wrong.
and,
2.) I'd like to know, if only a fool would
echo $_GET['param'];
...then what should i do as an alternative? I want to guess "the same thing i did to PHP_SELF" but i don't really want to guess.
Aside from those two questions, i'd just really appreciate if someone could point me at a N00b-language resource for best security practices, so i can start out doing things right, (e.g. converting the code samples which say "echo $_GET['param'];" to whatever is a better solution), rather than learning the wrong way and having to go back and re-learn.
Thanks,
-jb
P.S., OT, it would also be nice to find a resource called something like "Parentheses, Curly Braces, and Single and Double Quotation Marks for N00bs", because it just seems to me like a lot of the newer code i'm seeing looks much cleaner and more direct than the stuff i saw five years ago, with fewer of the above-mentioned characters.