DISQUS

ProDevTips: The worst PHP code in the world

  • R · 1 year ago
    @peecs

    Thats so pretty...my favorite is:

    // Please do not touch my code.

    to which my answer would be:

    thank you

    ;) But looking back, i got loads of old code thats not too pretty, probably those guys improved too.

    Love
  • Peec · 1 year ago
    Lol that was funny.
    I found this snippet , pretty funny, i still try figure why to use this code when he could use pure html...

    <?php
    // DYNAMIC Product list for my products.!
    // Based on the General Publci Liesencec!!!!!!!!!!!!!!!!
    // Please do not touch my code.
    echo "";

    echo "";

    // DYNAMIC ARRAY OF MY TABLE HEADERS
    $array[0][key] = 0;
    $array[0][Value] = Price;
    $array[1][key] = 1;
    $array[1][Value] = ID;
    $array[2][key] = 2;
    $array[2][Value] = Name;
    $array[3][key] = 3;
    $array[3][Value] = Type;
    $array[4][key] = 4;
    $array[4][Value] = Description;
    $array[5][key] = 5;
    $array[5][Value] = Weight;
    $array[6][key] = 6;
    $array[6][Value] = Code;
    $array[7][key] = 7;
    $array[7][Value] = Product;
    $array[8][key] = 8;
    $array[8][Value] = MoneyCurrency;
    $array[9][key] = 9;
    $array[9][Value] = Paymentmethod;
    $array[10][key] = 10;
    $array[10][Value] = PayPal;


    if ($array[10][Value] == PayPal){

    function addPayPal(){
    return "PAYPAL OK";
    }
    }

    echo "

    (ID: $array[0][key])-$array[0][value]
    (ID: $array[1][key])-$array[1][value]
    (ID: $array[2][key])-$array[2][value]
    (ID: $array[3][key])-$array[3][value]
    (ID: $array[4][key])-$array[4][value]
    (ID: $array[5][key])-$array[5][value]
    (ID: $array[6][key])-$array[6][value]
    (ID: $array[7][key])-$array[7][value]
    (ID: $array[8][key])-$array[8][value]
    (ID: $array[9][key])-$array[9][value]
    (ID: $array[10][key])-$array[10][value]


    ";

    /*


    TODO: Put in the list of items here in table tags
    */


    echo "";

    echo "";

    ?>
  • Ronald · 1 year ago
    After reading the first lines of code, I could not help myself.....

    if($controlip == ""){
    echo"Sie ?bertragen an unser System keine IP-Adresse und haben damit leider nicht die Rechte sich diese Seiten anzusehen!";
    }else{
    function func_header($text = "")
    {
    echo "$text";
    }
    if($goon == "logout")
    {
    $ask= "UPDATE `adminuser` SET logintime=logintime-3600 WHERE `adminuser`='$adminuser'";
    $result = mysql_query($ask) or die(mysql_error());

    The function really got to me..............lmfao.............

    thanks for this man........loved it.....
  • Anonymous · 1 year ago
    Trying to post this anonymous for obvious reasons. The PHP website I work for is far worse than that. Imagine taking that code as it is:
    * styles all embedded in html. really no CSS whatsoever
    * queries embedded directly in pages, copy-pasted to multiple places

    Add in:
    * the site uses frames. extensively :(
    * payments, for instance, were reimplemented in a dozen or so places using copy-paste. bugs were often fixed in only one place, or fixed in different ways in different places.

    The worst though - there were no 'echo' statements for printing HTML. The previous developers figured out echo statements were bad. Now hear what their solution was:

    For every echo statement, they moved the html into a text .inc file and included it from the php page. These .inc files were strictly HTML only, and named with seemingly random abbrevations, eg. index_a.inc, index_qp.inc, index_lj.inc.

    You may be wondering, "How did they handle things like looped HTML tables?"

    By putting every line in its own file. There was a .inc file for the begin table tag. A separate file for the end table tag. A separate file for the TR begin tag, and a separate file for the TR end tag. Another file for each TD that had to be looped on. Rinse and repeat for every single page in this rather large website.

    And this is now the my "baby" along with the rest of the dev team. Most of our time is taken up with maintenance and bugfixes, and projects require hard decisions on how much to rewrite. That's a very hard decision - Do we have time to rewrite X, or do we need to continue implementing some of this new project using X, which is horrendous and horribly broken?
  • K · 1 year ago
    Take a look at OS Commerce. It puts that to shame, plus it is insecure.
  • bdm · 1 year ago
    conditions without "typing" methods called inside conditions, defineless code , what's that mess ?

    choose life drop the if :)
  • Greg Winn · 1 year ago
    WOW, that is the best shit i have ever seen! Very classic guys! I feel bad for you!! I love the $ask, $ask1, $ask2 and so on!! LOL WOW!
  • Henrik · 1 year ago
    Anonymous: Ouch! I feel with you man, that sounds excruciating :( In fact I will hand it to you, THAT is the world's worst PHP code, not mine. I wish you good luck poor brave soul, you have my deepest sympathies.

    K: I have seen OS Commerce and it doesn't put it to shame but it's not pretty either that I can agree with you on!
  • Eugene · 1 year ago
    Sometimes big companies have projects with such 'worst code'. Yes, it's bad, but they can't pay for rewriting it from scratch while it's working.

    Then they need our companies to support such code -- We dislike bad code too but we work on it for money. $20 hourly.
    www.kauroff.com
  • k3vin · 1 year ago
    The sad thing is that my code used to look somewhat like that 5 years ago. Given, that I was in 8th grade.. and it was for a personal website. And I knew what a loop was. Okay, maybe even then it was slightly better but I have to say that I had had HTML being echoed all over the place.
  • Henrik · 1 year ago
    k3vin: Still you were better than this, even in 8th grade. This is a grown up man's work, a professional, he got paid to do this.

    I mean the equivalent in the "real world" would be if for instance a plumber installs a lot of piping in your house and it all works to begin with. After awhile though all hell breaks loose and your house ends up flooded. It's nothing less than a scam that you can sue for. And this should not be any different.
  • Hugo · 1 year ago
    What a hell is that noob code ????
  • kane77 · 1 year ago
    wow.. this code really smells.. my first tries with php were better than this (it still sucked but not as much as this)
  • localjoost · 1 year ago
    I had to work with PHP code from a "system administrator". He place echo = ""; on every single line :|
  • GNUb · 1 year ago
    Actually, this looks like a cut-and-paste from Dreamweaver or Frontpage code. Try it in DW/FP and you'll see similar code being generated.
  • Jan · 1 year ago
    Oh. My. God.

    I feel for you guys. It makes me glad I get to go back over some of my awful coding mistakes on routine code rewrite cycles!

    The issue is there's no minimum barrier of entry for PHP - anyone can use it, including noobs. It doesn't punish you for bad coding habits, like - say - java.

    Thanks for sharing this. You made me feel much better about the 'bad smells' in my own code =)

    Jan
  • Henrik · 1 year ago
    GNUb: Interesting observation, I'll definitely check this out. If you're right then these two softwares are doing a lot of damage on an incalculable scale.
  • Heron · 1 year ago
    Say NO for digital inclusion!

    Probably made by someone's nephew

    lol
  • Ray · 1 year ago
    lol, good one. You dont see many of these related to coding its usually hardware helpdesks and some numpty that cant switch on a PC.

    Working with someone elses code is a nightmare, especially if they really havent got a clue. I assume this was a true story? If so what size where the DB date and click logs, lol.

    I especially like the end and those immortal words....

    "I need a Chang, a big one" - usually helps.
  • Henrik · 1 year ago
    I wish it was just bullshit but it's not. The cleanup job is ongoing as we speak. The DB was 1.5GB at the time of writing, I don't even want to know what it is now...
  • Dale · 1 year ago
    Oh my... and I thought my code was bad!

    Though mine is messy and bad, it still works fine, but not as messy as that above. That just takes the p...
  • Otto · 1 year ago
    I'm sitting in the office looking at a few idiots who really code like this!!

    And they tell everyone they know PHP!! Its sad but true. I'm going to start a site where we can blacklist these what I like to call "Cowboy Programmers" (YEEEHAAA!!!! Lets build a system in PHP!!! YEEEHAAA!!!) because they soil the job market and ruin companies with great ideas forever.

    Also have worked on lots of projects with comments like:
    //Must put search results here
    - with no further code to search any database - What a joke!!

    This is the type of stuff I used to see in "sites" built by "programmers" using ASP and Access!! ROFL!!

    I started coding when I was 11. I taught myself from books (GW Basic). I can not relate to you guys who say your code used to look like that, sorry. So I'll just say I have never done anything so idiotic. Its just easier to write an HTML site than to try and work with that drivel!!

    The best part is how surprised the poor site owner seems to be. LMFAO!! "Really?" - Yes. You got screwed, man! Sorry to be the bearer of bad news!