The VERY surprising thing that impresses the French about life in Britain
RANGERS CONFIDENTIAL: The young star who's been cast into the shadows by Vaclav Cerny... and the fringe men who could yet earn club a decent fee
The rise of ketamine as Gen Z's drug of choice: From 'ket walks' to k-holes, TikTokers share videos showing anaesthetic's effects amid fears social media is fuelling use
Tan Kesler reveals the truth about his shock Hull City exit for the first time - and why he wants to return to England one day
The Top Gun star who crashed to earth: He seduced some of Hollywood's great beauties. But Val Kilmer was also a 'psychotic' hellraiser loathed by directors: CHRISTOPHER STEVENS
Passenger clubs together with three strangers on 'mission' to get cans of Guinness delivered to their moving train
Wild moment Anthony Albanese falls off stage while trying to pose for a photo in campaign trail fail - before the Prime Minister gives a truly baffling explanation
Trump's Treasury Secretary issues blistering six-word warning to countries threatening tariff revenge
Tributes paid to 'excellent' Essex teacher killed in tragic crash
Ten hidden gems to take you off the tourist trail in Paris - from an unmissable viaduct 'park' to a secret VINEYARD
Amazon Set To Launch First Operational Satellites For Project Kuiper Network
Read more of this story at Slashdot.
Popular Chelmsford shop confirms exact date it will close for good
Major blow to new search for MH370 as Malaysia explains huge setback
Iconic UK theme park announces two new attractions
Jose Mourinho pinches the NOSE of Galatasaray boss Okan Buruk after Fenerbahce lose feisty Istanbul derby - with Chelsea legend facing another long ban amid chaotic first season in Turkey
Trump shuts major online shopping loophole in blow to bargain hunters as his sweeping tariffs take effect
Budget airline launches ice cream range with some seriously bizarre flavours - we test it out with VERY surprising results
Representative Line: Get Explosive
Sean sends us a one-line function that is a delight, if by delight you mean "horror". You'll be shocked to know it's PHP.
function proget(){foreach($_GET as $k=>$v){if($k=="h"){$GLOBALS["h"]=1;}$p=explode(",",$k);}return($p);} //function to process GET headersBased on the comment, proget is a shorthand for process_get_parameters. Which is sort of what it does. Sort of.
Let's go through this. We iterate across our $_GET parameters using $k for the key, $v for the value, but we never reference the value so forget it exists. We're iterating across every key. The first thing we check is if a key "h" exists. We don't look at its value, we just check if it exists, and if it does, we set a global variable. And this, right here, is enough for this to be a WTF. The logic of "set a global variable based on the existence of a query parameter regardless of the value of the query parameter" is… a lot. But then, somehow, this actually gets more out there.
We explode the key on commas (explode being PHP's much cooler name for split), which implies… our keys may be lists of values? Which I feel like is an example of someone not understanding what a "key" is. But worse than that, we just do this for every key, and return the results of performing that operation on the last key. Which means that if this function is doing anything at all, it's entirely dependent on the order of the keys. Which, PHP does order the keys by the order they're added, which I take to mean that if the URL has query params like ?foo=1&h=0&a,b,c,d=wtf. Or, if we're being picky about encoding, ?foo=1&h=0&a%2Cb%2Cc%2Cd=wtf. The only good news here is that PHP handles the encoding/decoding for you, so the explode will work as expected.
This is the kind of bad code that leaves me with lots of questions, and I'm not sure I want any of the answers. How did this happen, and why are questions best left unanswered, because I think the answers might cause more harm.
[Advertisement] Plan Your .NET 9 Migration with ConfidenceYour journey to .NET 9 is more than just one decision.Avoid migration migraines with the advice in this free guide. Download Free Guide Now!