LovingTech For Sale: Contact Ryan for more information. (August, 2010)
|
Bad PHP
|
|
Feb-04-2010, 05:57 PM
Post: #1
|
|||
|
|||
|
Bad PHP
I was asked by someone to modify a basic forum script he used. Talk about some bad practises. They were using $_REQUEST instead of $_POST leaving it open to abuse. They had quotes around some HTML attributes but not around others. Oh and the best one.
eval(gzinflate(base64_decode('craphere'))); That is how they stopped people from removing the copyright footer and how they hid the anti spam function they had. But they didn't just use it once. No they would base64_encode the PHP then Gzip it then base64_encode the gzipped code and then gzip that. They would do this several times. I think they had done it ten times for the anti spam function. Can you imagine the overhead that would create for something that achieves nothing in reality. It was from PHPJunkYard's forum script. They do the same in their guestbook script as well. C a r b o n i z e Free ebook links (fiction) |
|||
|
Feb-05-2010, 11:39 PM
Post: #2
|
|||
|
|||
|
RE: Bad PHP
WHAT!, are you actually kidding me?
The moral of the story really, don't use other peoples scripts and especially not scripts from people that don't know what they are doing. Want to play some games? ![]() My personal blog |
|||
|
Feb-06-2010, 12:54 AM
Post: #3
|
|||
|
|||
|
RE: Bad PHP
I'd call that surprising, except that going in and cleaning up other people's code was my specialty when I was doing this stuff for work. I've seen far, far, far worse than that.
Some of the worst PHP stems from people not removing old code, or making assumptions that apply to another language that don't work in PHP. Core amongst those issues: Brute force writing functions that already exist in PHP - you'll see that one all the time. Because it's an interpreted language anything you can do as a native function will be faster as a native function; this is why out of the box PHP has more in-built functions than most any other language. Leaving in 'dead' code or legacy bits - PHP is a bytecode interpreted language - the more code there is the slower it's gonna run, it's not like in a compiled language where unused bits don't get compiled into the final version. A great example is a job I did two years ago, where a client had their contact form plugged into their goldmine application... The HTML form had a hidden input in it that had a 'encoded' copy of the destination e-mail address of the goldmine server. IT WAS PASSING THE REAL DESTINATION IN THE FORM!?!?! Worse, was the encode/decode method used for it, the original looking something like this: Code: function Decode($strValueIn)What's wrong with that? Like five unused variables, redundant/uneccessary logic... ****ed up part was I rewrote it BEFORE I figured out it was to decode information that shouldn't be sent through the form in the first place... The following is functionally identical: Code: function Decode($inString) {Bad code is everywhere, most of the time it's spagetti mish-mash or programmers being too smart for their own good. That dual encode gzip/eval is the tip of the iceberg in terms of bad code, but a great example of overthinking/overcomplicating code for no good reason. A LOT of developers are obsessed with things like code obfuscation when it comes to the internet - you want obfuscation, use a compiled language like C and make a native application - or use something like a server side java crapplet. One should not waste time trying to pull those types of stunts in a language intentionally designed NOT to hide anything from anyone. It is said that the future is always born in pain. The history of war is the history of pain. If we are wise what is born of that pain matures into the promise of a better world - because we learn that we can no longer afford the mistakes of the past. - Citizen G'Kar |
|||
|
Feb-06-2010, 12:04 PM
Post: #4
|
|||
|
|||
|
RE: Bad PHP
Stupidest thing in that script is not only does he eval(gzinflate(base64_decode it several times, and by that I mean it would look like eval(gzinflate(base64_decode(eval(gzinflate(base64_decode(eval(gzinflate(base64_decode ..., he actually uses it three times and two of the occurrences are to obfuscate the same code:
Code: $link = true;And just to take the piss here is the second bit of code he obfuscates. It's just a spam post checker. Code: function JunkMark($email,$comments) {C a r b o n i z e Free ebook links (fiction) |
|||
|
Feb-06-2010, 06:30 PM
Post: #5
|
|||
|
|||
|
RE: Bad PHP
Well lets be honest - this ALONE
<p align="center"><font class="smaller"> Screams "idiot" It is said that the future is always born in pain. The history of war is the history of pain. If we are wise what is born of that pain matures into the promise of a better world - because we learn that we can no longer afford the mistakes of the past. - Citizen G'Kar |
|||
|
Jun-23-2010, 01:48 PM
Post: #6
|
|||
|
|||
|
RE: Bad PHP
Untwisted Vortex - An American Living in the Philippines |
|||
|
Jun-23-2010, 02:52 PM
Post: #7
|
|||
|
|||
RE: Bad PHP
(Jun-23-2010 01:48 PM)RT Cunningham Wrote: Not by itself. If it was written before CSS took hold... I still see it on static sites.Actually it still would; since the FONT tag is used for a class that means CSS, which means the class could go on the paragraph tag; at which point that class should be used to apply the align, not the markup... Though you're right about the whole age of the codebase thing, which is why I get annoyed when I see people still doing that on what's supposed to be a 'new' website. It is said that the future is always born in pain. The history of war is the history of pain. If we are wise what is born of that pain matures into the promise of a better world - because we learn that we can no longer afford the mistakes of the past. - Citizen G'Kar |
|||
|
« Next Oldest | Next Newest »
|







![[Image: logo.jpg]](http://buttonbashers.co.uk/images/logo.jpg)