MyBB Community Forums

Full Version: Geek Humor: 2 'Experts' are fighting over an answer to my PHP question @Stackoverflow
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
These guys are really going at it, one of them can't stand having his answer down-rated Toungue

@ The bottom answer (currently w/ a -1 score) they have 'fought' back-and-forth over a total of at least 12 comments.

##

Note: Here is the original question.
  • Can you answer it, before looking at the experts opinion?

Hi,
The variable ' $return10 ' (for example) is a url, and I need to append ' &var2=example ' to the end. Like this:

 header( "Location: $return10&var2=example" );
 header ("Content-Length: 0");
  exit;

The challenge is not knowing if the url contained in ' $return10 ' will already have a query string.

Choice A) If I use ' &var2=example ' , then sometimes the final url will be ' ://example.com&var2=example ' , with no '?' to start the query string.

Choice B) If I use ' ?var2=example ' , then sometimes the final url will contain two "?"'s starting two different query strings??

Is there a third choice? Thank you.

###
Tip: There is a pretty easy answer, but it doesn't cover every possible issue with (or component of) a http:// URL.

####
Would you ever fight so hard over reputation points at a website? Angel
...
..
.
After reading the question i already had an answer. When reading the referenced thread, i saw that one person had almost the right answer but gave the reversed solution.

The simple solution is :

if(strpos($return10, "?"))
  $return10 .= "&var2=example"
else
  $return10 .= "?var2=example"
Hi exdiogene,
Yes, simple and almost correct (i.e. correct for most situations), but the simple way will not work when using an anchor @ the end of the source url.

Also, if the guy with 14,600 reputation points is correct then:
Quote:...not down voting you for ignoring only fragment. I'm down voting you for ignoring scheme, host, user, pass and fragment
I use some anchors, so will go with the 'complex' way. Smile


I am sorry, but the way the question was asked, it was the correct answer!

No restriction was ever introduced in the question except the fact that a third solution better than the two already given was wanted. So my solution is the logical one and believe me that i would have given full points to one of my students having given it...

The way you resume the situation is like asking what you can offer to a kid for lunch if he refuse soup and vegetables and after receiving the suggestions you tell the people that they are wrong because the kid is allergic to peanuts and milk.

Unfortunately the first solution proposed by one of the coder was given upside down and would not have worked. The other two were just criticizing each other method about a situation that was not described as POTENTIAL by the person asking the question!

This is like walking in the street with a medieval armor in case you get hit by a car...

People have to be smart enough and evaluate the logical probabilities...

Wink
(2010-09-27, 01:09 PM)exdiogene Wrote: [ -> ]I am sorry, but the way the question was asked, it was the correct answer!
...

I won't try to debate that.

(2010-09-27, 01:09 PM)exdiogene Wrote: [ -> ]People have to be smart enough and evaluate the logical probabilities...

Wink

"Smart enough" can mean a lot of different things;
I've known more than one person who was truly brilliant in one (or more) area(s), and in other ways they were barely smarter than an average-sized rock. Toungue
[Image: layers.jpg]

Experience is a huge factor too, I would have noticed (and learned from) "the anchor issue" only after it caused problems.
The one guy was able to see beyond the initial question, and give an answer that will work when anchors are used, etc.

// Geek Humor: It was slightly amusing, IMO, to see how hard the guys fought over a single down vote.

Positive feedback feels good, and can be addictive, but ultimately you need to 'impress yourself' (or whatever the best way to say that would be), not other people. Smile
I agree with the fact that a solution including all possibilities is the one that must be considered by someone needing it. Wink

But to see people debate over a solution that was beyond the need of the question is quite amusing in fact, but at the same time instructive for many readers.

I can tell you that i was quite discouraged to see even university teachers ask ambiguous questions that no student could really answer correctly without asking questions to understand the question itself! Toungue

That's good we seem to agree on a couple of things (above)

(2010-09-27, 02:40 PM)exdiogene Wrote: [ -> ]....I can tell you that i was quite discouraged to see even university teachers ask ambiguous questions that no student could really answer correctly without asking questions to understand the question itself! Toungue
^^^
Is that similar to Sock-Rat-Tease?
I forget the details, at least one of the "great classical teachers" encouraged students to ask many questions.

Confusion says:
Life is really simple, but men insist on making it complicated. ~Confucius

######

By all means, marry. If you get a good wife, you'll become happy; if you get a bad one, you'll become a philosopher. ~Socrates

Death may be the greatest of all human blessings. ~Socrates

^^^
Wow!
I'm glad I never spent time with his wife ~Seeker Toungue


Yeah, thats fun a fun discussion. The only thing that wasn't suggested that I would have added would have been to include
if(!function_exists(http_build_url)) {}

Around the pure HTTP version of the function inside an inc/functions.php file or similar so that the application is portable Big Grin
(2010-09-26, 01:54 PM)exdiogene Wrote: [ -> ]
if(strpos($return10, "?"))
  $return10 .= "&var2=example"
else
  $return10 .= "?var2=example"

MyBB should be doing this... currently it appends ? or & based on whether MyBB SEF URLs are active or not (way more complicated if than the strpos above), without actually checking what's already in the URL. So MyBB ends up making broken URLs when a plugin like Google SEO changes links around, and I have to fix them with rewrite rules.

The solution is simple and 100% correct assuming you already know there won't be any surprises in the input URL, i.e. if there really are just these two choices.
(2010-09-27, 10:09 PM)Dylan M. Wrote: [ -> ]Yeah, thats fun a fun discussion. The only thing that wasn't suggested that I would have added would have been to include
if(!function_exists(http_build_url)) {}

Around the pure HTTP version of the function inside an inc/functions.php file or similar so that the application is portable Big Grin

(2010-09-28, 07:56 AM)frostschutz Wrote: [ -> ]
(2010-09-26, 01:54 PM)exdiogene Wrote: [ -> ]
if(strpos($return10, "?"))
  $return10 .= "&var2=example"
else
  $return10 .= "?var2=example"

MyBB should be doing this... currently it appends ? or & based on whether MyBB SEF URLs are active or not (way more complicated if than the strpos above), without actually checking what's already in the URL. So MyBB ends up making broken URLs when a plugin like Google SEO changes links around, and I have to fix them with rewrite rules.

The solution is simple and 100% correct assuming you already know there won't be any surprises in the input URL, i.e. if there really are just these two choices.

Thanks all, for adding info and suggestions, I love to learn. Smile