|
|
|
| Non-WTF Job: Interface Designer/Front-end Developer at Naviance (DC) |
| « Prev | Page 1 | Page 2 | Page 3 | Next » |
Re: A Rather Curious Pattern
2008-05-12 08:10
•
by
Pete from Perth
(unregistered)
|
|
Probably easier to simply send the header or meta strings needed properly rather than resort to this sort of ugly hack.
|
|
Why didn't they use a for loop?
|
But that way your code is not portable in different time zones! |
|
// add a useless comment
I love the way every line of code is preceded by a useless comment. // laugh out loud lol // say what captcha was captcha=feugiat |
Re: A Rather Curious Pattern
2008-05-12 08:16
•
by
Dave
(unregistered)
|
Would it be more likely to work if multiple servers were running (ie serving up a page at the same time)? |
|
Salt is a perfectly valid technical term in cryptography, being a random string or value added into the encryption process to obfusticate the process or the original value being encrypted. It's just an extra obstacle for people trying to recover the original value, though it does smell a little of security through obscurity.
The use here is not consistent with the proper definition of salt though, so I imagine the original author got confused somewhere along. |
Re: A Rather Curious Pattern
2008-05-12 08:27
•
by
http://jobs.thinkaloud.in
(unregistered)
|
|
I know another term that will act as "an extra obstacle for people trying to recover the original value, though it does smell a little of security through obscurity. "
its called PEPPER CAPTCHA : validus |
Re: A Rather Curious Pattern
2008-05-12 08:28
•
by
Andrew
(unregistered)
|
|
perhaps he's a seasoned developer *rim shot*
|
|
Perhaps. But he's not worth his salt. *drum solo*
|
|
Now taking bets on how long it'll take for some dweeb to helpfully inform us that "PHP is the real WTF". And no, this post doesn't count.
|
Re: A Rather Curious Pattern
2008-05-12 08:40
•
by
Mork
(unregistered)
|
|
we have a winner.
|
Re: A Rather Curious Pattern
2008-05-12 08:43
•
by
anon
(unregistered)
|
|
//wtf
the only reason I can think of to do this was if they wrote a skeleton in comments and then added the code. |
Actually, when hashing passwords, adding a salt will prevent people from just looking up the hash in their precomputed hash database. |
|
The real WTF is that a programmer would go quietly change code without enquiring why it was that way, worst case is there's no good reason and someone learns something, worst case just quietly changing it is you reintroduce a bug that someone had fixed, do that a couple times with me and you'd be getting the boot rather fast. So go learn how to work as a team.
can i have a drum roll too please? |
Re: A Rather Curious Pattern
2008-05-12 08:57
•
by
Broken sarcasm-detector-detector
(unregistered)
|
|
Perhaps it is used to stop/use serverside caching?
if (not fileexists(nocache)) { //return FILE_NOT_FOUND string s = getContent() stream_to_file(nocache) } stream_file_to_browser(cocache) |
Re: A Rather Curious Pattern
2008-05-12 08:57
•
by
byron
(unregistered)
|
|
The real WTF is that the code makes perfect sense to me.
Also, if you replace it with just time(), then you're not dealing with multiple requests per second. Slow site? |
|
I think this says it all:
and
|
|
generally i use the last modified time of the file in question rather than the current time. let the browser cache it if it hasn't changed.
|
Re: A Rather Curious Pattern
2008-05-12 09:01
•
by
I walked the dinosaur
(unregistered)
|
|
Seriously - this isn't any real WTF. Alot of php code does small little stupid things like this.
So, as someone mentioned above, the real wtf is nitpicking at PHP code. |
|
Now now, don't put someone down for commenting their code, after all how would we know what was going on in this snippet without comments??
What is the last line about though?
Surely if you're generating the random code as part of the header, you're not going to need to call the function again, because you could just use the $random that is assigned there? The real WTF is algebra... Addendum (2008-05-12 09:09): bah... by "header" there I mean an included file before the main page source. Not anything to do with the html header |
|
My favourite bit:
// Set i = 0 |
Re: A Rather Curious Pattern
2008-05-12 09:07
•
by
Iain Collins
(unregistered)
|
|
Of course setting the HTTP headers appropriately is the right thing to do (as Pete from Perth points out) but it's worth nothing that in some situations some browsers (MSIE and Safari in particular I've noted) cache certain GET requests regardless.
I've found this is usually when are doing something like dynamically loading content in a frame or iframe, or as the result of an AJAX GET request, and I think also possibly when bouncing the client around with HTTP redirects (for a single sign on platform). I've used a GET request with microtime in it myself in those cases and in some instances it's all you can do. If it's just a regular website though (and not making use of Ajax or iframes in some way) then setting headers appropriately will work just fine. For PHP, something like the following should suffice:
I think what usually happens is that a lot of people try setting one or two of the headers above notice they still don't work some of the time and give up on that approach and go straight for something like a dynamic element to the GET request when setting all the appropriate headers would suffice. |
|
Hey! That's my code!
And it's perfectly valid. I found it in the PHP documentation, it was one of the user submitted examples. So it must be right. Like yours is better!? What if two pages were requested at the same time? What then smartarse!? |
Re: A Rather Curious Pattern
2008-05-12 09:19
•
by
A Nonny Mouse
|
Addendum (2008-05-12 09:24): got my quoting a bit muddled there, sorreh.. |
|
Well, the most remarkable thing about this code snippet are the comments...
|
Re: A Rather Curious Pattern
2008-05-12 09:24
•
by
DaveAronson
|
I often do that. It helps me plan out how to implement a function. Think of it as ultra-low-level design. However, after writing the code, the "clean" thing to do, is to remove the superfluous comments, leaving only those that describe code that is difficult to understand. That of course should be a small fraction. (But rarely is. That's a whole 'nother WTF....) |
The function generates a random string that was originally intended to be used as a salt. Somebody came along later and realized that the function did exactly what they needed it to do for some other purpose, so they reused it without renaming the local variables. Small WTF. |
Ignoring your sarcasm: Even if adding a random string to the end of the url in a get variable was a good way to prevent caching, the original code was way to obscure and long winded. It would be better to allow a browser to cache the two pages served on the same second TO THE SAME CLIENT anyway. It isn't caching pages server side then throwing them out, it is using ECHO which means, if two different people access it at the same time they will get the same string but different CONTENTS, which is fine. |
|
Actually, this code is correct. Some caching proxies are built to ignore time stamps of all formats and look for deeper changes in the page to determine whether the page should be cached or not. A random string, coupled with the appropriate headers and pragmas, is the best way to go.
Kind of lame too to unearth old code from PHP4 days, and then claim that it is wrong because it is now deprecated under PHP5. Should the developers replacing the poster in PHP6 days chuckle at this person for using code that is perfectly valid at the moment of writing ? |
|
I am under the impression that IE does not bother to cache stuff with parameters even if they are the same. I may be wrong though and I am not sure about the other browsers.
|
|
I think we have agreement that the comments were the most WTFy part. So I fixed the comments:
|
Re: A Rather Curious Pattern
2008-05-12 09:41
•
by
Robert Synnott
(unregistered)
|
Oh, if only this were the case. Sadly, there's always some bloody stupid browser and/or caching proxy which refuses to behave itself; this approach is sometimes necessary. |
Re: The comments were the problem
2008-05-12 09:59
•
by
Joe
(unregistered)
|
|
Feature this one please. Excellent and funny.
QFT |
Re: The comments were the problem
2008-05-12 10:11
•
by
The real wtf fool
(unregistered)
|
Brillant |
Re: The comments were the problem
2008-05-12 10:12
•
by
Rob
(unregistered)
|
|
Second that, Dark FTW!
|
Re: A Rather Curious Pattern
2008-05-12 10:29
•
by
Thunder
(unregistered)
|
Erm... it helps to read what people write before commenting. For example, that's what OP said, though with many more words. Captch: capio. Usage: I'm gonna bust a capio haid. |
Re: A Rather Curious Pattern
2008-05-12 10:31
•
by
Paul
(unregistered)
|
|
I suspect this was written (at least initially) for ye olde tyme WML 1.1 browsers, none of which (except for the Openwave browsers) supported caching headers or meta tags.
If that's the case, the only problem I see with replacing the no_cache by the current time is, content sent to those old browsers was limited to 1400 bytes of compiled WML, so if this increases the size of the URL string, you lose several bytes, and with multiple links you lose a multiple. Of course, the name of the URL attribute "no_cache", makes all that unlikely, since that alone uses up multiple bytes. Hence when I was working with WML, I had to use only single byte attribute names. |
Ah, you're one of those people who like it when dynamically generated content gets cached client-side! Given this is php I'm guessing that the content changes far more often than the script get edited. Thank you for pre-emptively answering the question "Doesn't PHP have some method of setting cache-control dynamically for pages that you don't want caching?". OK, some user agents / caching servers may ignore the headers, but given that it's an HTTP 1.1 standard maybe those programs need taking out and shooting? It would be hackish and childish of me to say that TRWTF is MSIE, so I won't (honest guv). The only problem I had with unwanted caching in IE was in a dynamic javascript I was loading into a page via DOM (yes, it's a cheap hackish way of doing AJAX without the AX!) - and setting cache-control to no-cache worked fine for me... |
Re: A Rather Curious Pattern
2008-05-12 10:34
•
by
SomeCoder
(unregistered)
|
I was wondering the same thing. How many bugs did he introduce by making that change? I'm willing to give him the benefit of the doubt though and say that his change was appropriate. |
Re: A Rather Curious Pattern
2008-05-12 10:44
•
by
Martin
(unregistered)
|
This will be the future thread on Daily Advanced WTF 2.0 ... I just quitely replaced it with content.php?rnd=<?= time() ?> |
Re: A Rather Curious Pattern
2008-05-12 10:46
•
by
Boner
(unregistered)
|
that doesn't matter, it's not like you're caching webpages for me. |
|
What's sad is that a while ago a coworker of mine did pretty much the same thing, though I'd say on a much worse scale. Here's what I managed to dig out of the repos
|
Re: A Rather Curious Pattern
2008-05-12 10:57
•
by
me
(unregistered)
|
You SO obviously don't understand just how fucked up that code was... |
Thus demonstrating that you have no more clue than the author of that abomination. I don't say that everybody has to know about how to control caches in HTTP (although not knowing HTTP basics speaks volumes about your competency as web apps developer, even a newbie should study it a bit), but any programmer worth being called that should immediately realize that this problem must be common and there's almost certainly a proper solution to it that they should use instead of ugly hacks like adding time() to URL. |
These are all tasteless comments. *Bongos, congas, shakers, rattles and a marimba* |
Re: A Rather Curious Pattern
2008-05-12 11:18
•
by
captcha: quis
(unregistered)
|
You know, we shouldn't overlook it just because lots of PHP code does stupid things. Knowing the difference between stupid code and clever code is what separates us from the animals. |
Bob: no drum roll for you - too verbose and not witty enough. Sorry! Coder: I don't agree that the change was appropriate; for instance, we don't know if the content.php script made use of the NoCache later in the code (I assume it didn't, but can't be sure) and the renaming of the parameter from NoCache to rnd is worthy of a quiet WTF itself; at least the old name was descriptive: whereas future maintainers are going to look at the code and wonder why the content.php page is being passed the value of the date() function under the variable name rnd. And that's without mentioning that this is a hack relying on undefined behaviour (caching of pages which include querystrings), rather than following clearly defined standards (setting cache-control headers). The appropriate thing to do would've been to thoroughly review the codebase, check whether removing these references would have any other side effects, and then implemented the appropriate headers on the scripts (meaning you can remove this code from every page that references those scripts). But hey, this is PHP, isn't it... ;^) |
|
Or you could just use the pragma nocache headers...
|
Re: A Rather Curious Pattern
2008-05-12 12:31
•
by
Jay
(unregistered)
|
I particularly love it when programmers include such useless comments rather than tell me what I really want to know. One of my favorites was:
Like, wow, thanks for that helpful comment telling me that "+" means to add. They never taught me about that subtle and rarely used feature of C in college. But it would have been nice if you could have given me a hint what "n2" and "n5" hold. I managed to guess that "totchg" had something to do with "total charge" to a customer, but even that was obscure, as the program also had a variable named "chgtot" that was apparently something different. |
| « Prev | Page 1 | Page 2 | Page 3 | Next » |