hadoob024 wrote:Cool. Thanks. That's what I was thinking too. I found this solution too for dealing with keeping your MySQL passwords safe:
I think I might try using this approach. Any thoughts on this? I figure it's good for info that you don't want anyone to read. But my particular case is that I don't care if someone can read the value, I just don't want anyone to be able to change it.
I think either approach would work fine. I prefer the include approach myself, not that it's more efficient or will get you more attention from the ladies, it's just my preferred method in coding.
In fact if you look at most of the websites I've done from the web side and view the source code, you'll generally only find one or two lines of code on the actual webpage itself, just a few function calls to functions that are defined in the include file.
Being inherently lazy I generally try to reuse code as much as humanly possible, so whenever I'm coding anything I break it up into functions, all the functions go into an include file and then when I need to access them from the webpage I do the include() and then the one or two function calls necessary to do the task.
I like this particular approach for two reasons, it hides my source code from prying eyes and it keeps it safe from harm. Even if by some miracle someone managed to hack into the server over the web the worst they could do is scramble up the html. The real workings of the site are tucked safely away in a directory that isn't accessible from the web.
In fact one of my favorite coding projects was for a gentleman who was running a personal website on his home PC - he'd made some rather unfortunate enemies during his days on IRC and as a result they were constantly hacking his website. He asked me for some assistance, and the solution I came up with was.. well, in his words, diabolical.
I replaced his entire website with one index page. Nothing else was stored in directories accessible to the web, everything was accessed dynamically using PHP and drawn from directories outside the directory accessible to the web.
When you clicked on a link to another page other than the index page, what was actually happening is that PHP would reload the index page and pull all the content from outside files using functions that simply read in the entire html file into one variable and then echoed it back out when index was reloaded.
From the users perspective it still looked and felt like any other website, but from a hacker perspective the thing was a nightmare. Worst case scenario if anyone did ever manage to hack into the site all they could do would be to mess with the index page, but since all the content was elsewhere it was completely safe. All he had to do was keep a copy of the index page saved elsewhere and if he did get hacked he just copied the index page back into that directory and viola! Website restored.
Of course his hacking problems ceased when we replaced the chintzy webserver software he was using with Apache, but given his paranoia level I decided to up the ante a bit and make absolutely sure his site was going to be as hacker proof as I could make it.