Page 1 of 1
Complete Insanity!
Posted: Thu Dec 16, 2010 3:42 pm
by spacebiscuit
Ok this is completely insane, I have never seen anything like this in over 11 years of programming in php.
Consider this code - it copies a URL posted via form into a session variable and then outputs the session to screen.
Code: Select all
for($x=0; $x<=100; $x++){
$_SESSION[toreport][$x]=$_POST["link"];
print_r($_SESSION[toreport][$x]);
}
In Firefox it correctly outputs the url - 'http://...."
In IE it only output the first character - 'h'
I've not ever seen two different brwosers handle the same code differently - it is just not possible.
What is going on?
Rob.
Re: Complete Insanity!
Posted: Thu Dec 16, 2010 3:52 pm
by spacebiscuit
Ok so it gets worse....
If change any letter in the variable name 'toreport' it outputs correctly:
torepora - OK!
toreporb - OK!
toreporc - OK!
torepord - OK!
torepore - OK!
toreport - No!
Seriously - WTF?
Re: Complete Insanity!
Posted: Thu Dec 16, 2010 4:08 pm
by Jonah Bron
First, fix your code like this:
Code: Select all
for ($x = 0; $x < 100; $x++) {
$_SESSION['toreport'][$x] = $_POST['link'];
print_r($_SESSION['toreport'][$x]);
}
And why do you need 100 copies of the same string?
Re: Complete Insanity!
Posted: Fri Dec 17, 2010 2:16 am
by cpetercarter
Jonah Bron's suggestion is correct. Leaving the offset name "toreport" unquoted can have unexpected results.
However, the unexpected result should happen in the server, not in the browser, so I do not understand why the OP gets different results in FF and IE.
Re: Complete Insanity!
Posted: Fri Dec 17, 2010 3:19 am
by spacebiscuit
Yes - adding the quotations fixed the problem - but like you say it makes no sense that browsers display the output differently since PHP is server-side.
In answer to your question Jonah - I did not copy my code correctly the post link variable is suffixed with a variable, for example:
$_POST["link{$x}"]
Such that the same URL is not copied 100 times, this enables me to copy upto 100 URLs instead.
Thanks for your help.
Rob.
Re: Complete Insanity!
Posted: Fri Dec 17, 2010 5:31 am
by Darhazer
cpetercarter wrote:Jonah Bron's suggestion is correct. Leaving the offset name "toreport" unquoted can have unexpected results.
However, the unexpected result should happen in the server, not in the browser, so I do not understand why the OP gets different results in FF and IE.
Maybe there is an error reporting which interfere with site CSS and actually the output is the same in both browsers, but rendering is not

Re: Complete Insanity!
Posted: Fri Dec 17, 2010 11:33 am
by Jonah Bron
Darhazer wrote:Maybe there is an error reporting which interfere with site CSS and actually the output is the same in both browsers, but rendering is not

Man, I love the way you can upvote posts on Stackoverflow.
Re: Complete Insanity!
Posted: Sat Dec 18, 2010 2:07 am
by Darhazer
Jonah Bron wrote:Darhazer wrote:Maybe there is an error reporting which interfere with site CSS and actually the output is the same in both browsers, but rendering is not

Man, I love the way you can upvote posts on Stackoverflow.
sorry? I have no idea what you are talking about

Re: Complete Insanity!
Posted: Sat Dec 18, 2010 2:32 am
by spacebiscuit
I'm glad it was not just me!
Re: Complete Insanity!
Posted: Sat Dec 18, 2010 12:18 pm
by Jonah Bron
Darhazer wrote:sorry? I have no idea what you are talking about

I just wish I could upvote your post

Re: Complete Insanity!
Posted: Sat Dec 18, 2010 8:55 pm
by spacebiscuit
I can't find the verb 'upvote' in my Oxford English dictionary...