Webmaster Forum


Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Coding Forum Problems with your code? Let's hear about it.

   

Reply
 
LinkBack Thread Tools Display Modes
Old 01-26-2007, 12:11 PM   #1 (permalink)
Contributing Member
 
I like pie's Avatar
 
Join Date: 10-12-03
Location: California
Posts: 254
iTrader: 0 / 0%
Latest Blog:
None

I like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the rough
Send a message via ICQ to I like pie Send a message via AIM to I like pie Send a message via MSN to I like pie Send a message via Yahoo to I like pie
array weirdness in php

I set something up on my dev site the other day, and it works fine. i updated the live site with the current files and everything appeared to be well... except i 'm experiencing something rather strange.

i can set an array to contain a certain value on one site, and the EXACT same code doesn't work on the other site:

Code:
$strip['strip_id'] = $_GET['strip']; foreach($strip as $key => $value) { echo "key is ".$key." and value is ".$value."\n"; } die;
There's no chance it's a typo, they're both pulling the same file from a common repository. but take a look at the pages:

http://dev.foohonpie.net/snat/index.php?strip=20040206

http://foohonpie.net/snat/index.php?strip=20040206

something different is happening here, but i don't know what or why. has anybody had something like this happen to them before?
I like pie is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-26-2007, 12:54 PM   #2 (permalink)
v7n Mentor
 
Taltos's Avatar
 
Join Date: 11-22-06
Location: Phoenix, AZ
Posts: 1,816
iTrader: 0 / 0%
Latest Blog:
None

Taltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web pro
Just out of curiosity....if you alter your code to give a simple numeric index to the array and then try to output the contents with a for loop rather than foreach...what happens?

Or just try to output $strip['strip_id'] and see what happens. The only guess I have is that the array has something else in it besides what we saw from your code. That "something else" is somehow an illegal array index or and illegal value. The test above would tell you that the repository code is definitely OK and not the problem. It might, in the case of the for loop, tell you what else is in that array that shouldn't be.

Good luck on that one!
__________________
Experimenting
Taltos is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-26-2007, 01:11 PM   #3 (permalink)
Contributing Member
 
I like pie's Avatar
 
Join Date: 10-12-03
Location: California
Posts: 254
iTrader: 0 / 0%
Latest Blog:
None

I like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the rough
Send a message via ICQ to I like pie Send a message via AIM to I like pie Send a message via MSN to I like pie Send a message via Yahoo to I like pie
well... i output $strip['strip_id'] and get "2"... and i also noticed that it seems to be a problem with the name of the array, and i have no idea why.

this is what i have now:

Code:
$strip['strip_id'] = $_GET['strip']; foreach($strip as $key => $value) { echo "key is ".$key." and value is ".$value."\n"; } echo "<br>$"."strip['strip_id'] is ".$strip['strip_id']; $strip_2['strip_id'] = $_GET['strip']; echo "<br>$"."strip_2['strip_id'] is ".$strip_2['strip_id']; die;
$strip_2 works fine, but $strip is all goofy still. and if i do this:

Code:
$strip = '';
before it, it works. but honestly, i shouldn't have to do that... that's a rather sketchy fix to something that might be indicative of a problem down the road.

again, the same exact file...

http://dev.foohonpie.net/snat/index.php?strip=20040206

http://foohonpie.net/snat/index.php?strip=20040206

I'll try that for loop thing.. it'd be nice to see exactly what it is that i'm clearing out when setting $strip to null.

Last edited by I like pie : 01-26-2007 at 01:17 PM.
I like pie is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-26-2007, 01:26 PM   #4 (permalink)
Contributing Member
 
I like pie's Avatar
 
Join Date: 10-12-03
Location: California
Posts: 254
iTrader: 0 / 0%
Latest Blog:
None

I like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the rough
Send a message via ICQ to I like pie Send a message via AIM to I like pie Send a message via MSN to I like pie Send a message via Yahoo to I like pie
alright... this is making some sense now

i think what's going on is that the $strip is being preset as $_GET['strip']... so when i try to set $strip['anything'] to anything, it screws up because it already exists as a non-array variable.

that's my guess anyway. would explain why $strip_2['foo'] works fine.

but what it doesn't explain though, is why it works on one site but not on the other. they should have the exact same php configurations.
I like pie is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-26-2007, 01:33 PM   #5 (permalink)
Contributing Member
 
I like pie's Avatar
 
Join Date: 10-12-03
Location: California
Posts: 254
iTrader: 0 / 0%
Latest Blog:
None

I like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the rough
Send a message via ICQ to I like pie Send a message via AIM to I like pie Send a message via MSN to I like pie Send a message via Yahoo to I like pie
and i've found the problem...

dev.foohonpie.net: php 5.1.2
foohonpie.net: mod_php 4.4.2

i really should have checked that in the beginning haha. probably not good that my dev site is more up to date than the live one... i hope nothing breaks
I like pie is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-26-2007, 03:34 PM   #6 (permalink)
v7n Mentor
 
Taltos's Avatar
 
Join Date: 11-22-06
Location: Phoenix, AZ
Posts: 1,816
iTrader: 0 / 0%
Latest Blog:
None

Taltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web proTaltos is a highly respected web pro
I have to say I blew off different hosts or configurations. I saw the url and assumed one was a subdomain with all the same toys. Important part is you got it figured out! Bonus points for that
__________________
Experimenting
Taltos is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-26-2007, 06:36 PM   #7 (permalink)
Inactive
 
Join Date: 01-23-07
Location: Netherworld, under Buenos Aires.
Posts: 169
iTrader: 0 / 0%
Hades is liked by somebodyHades is liked by somebodyHades is liked by somebodyHades is liked by somebody
Send a message via MSN to Hades Send a message via Yahoo to Hades
Hi,

It is not about the version of PHP, but it should happen because one server has the REGISTER GLOBALS in ON, and in the other server it could be in OFF.

If you use global variables like $_GET, $_SESSION, and have the REGISTER_GLOBALS = ON, you should be careful with the names of the variables,

IE, if you set up a variable like this:
$_SESSION['name'] = "Jack Ryan";
or $_GET['name'] = "Jack Ryan";

then use a local variable:
$name = "Cathy Ryan";

the second variable will override the first one. That will not happen in a server with REGISTER_GLOBALS = OFF.

In your script you wrote:

PHP Code:
$strip['strip_id'] = $_GET['strip'];

foreach(
$strip as $key => $value) {
  echo 
"key is ".$key." and value is ".$value."\n";
}
die; 
You are overwriting the $_GET['strip'] variable with a new one called $strip and setting it up as an array which contains "strip_id", it makes the script messing all up.

Good Luck!
Hades is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-27-2007, 12:36 AM   #8 (permalink)
Contributing Member
 
I like pie's Avatar
 
Join Date: 10-12-03
Location: California
Posts: 254
iTrader: 0 / 0%
Latest Blog:
None

I like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the roughI like pie is a jewel in the rough
Send a message via ICQ to I like pie Send a message via AIM to I like pie Send a message via MSN to I like pie Send a message via Yahoo to I like pie
I do recall reading about register globals years ago. Never thought anything of it until now.

Thanks guys.
I like pie is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum

Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
imploding array keys I like pie Coding Forum 7 12-28-2006 05:55 PM
more weirdness... with adsense chillfire Contextual Networks 5 12-14-2006 05:37 AM
quick array question I like pie Coding Forum 1 12-02-2006 10:05 PM
Adding 1 to array? spl1nter Coding Forum 4 09-14-2004 08:22 PM


Sponsor Links
Webmaster Forum Get exposure! Find Scripts Web Hosting Directory Get exposure! SEO Blog


All times are GMT -7. The time now is 02:53 AM.
© Copyright 2008 V7 Inc