foreach behaving wierd on remote server :x

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

foreach behaving wierd on remote server :x

Post by n00b Saibot »

Code: Select all

if(isset($_SESSION['prod']) && count($_SESSION['prod']) > 0):
echo "SESSION ".nl2br(print_r($_SESSION, TRUE));
$Products = array();
$db = new DB();
if($db === FALSE) catchErr("Could Not Connect to Database!");

foreach ($_SESSION['prod'] as $prodID=>$prod)
{
 echo "prodID ".nl2br(print_r($prodID, TRUE))."<br />";
 echo "prod ".nl2br(print_r($prod, TRUE));
 $Link = $db->query("SELECT prod_name AS Name, prod_price AS Price, prod_method AS ShipMethod, prod_shipping AS Shipping FROM products WHERE prod_id = $prodID");
 if($Link === FALSE) catchErr("Product Selection Failed! ProdID: $prodID.");
 $Products[$prodID] = $db->fetchArray($Link);
 $Products[$prodID]['Qty'] = $prod['qty'];
 $Products[$prodID]['Method'] = $prod['method'];
 $Products[$prodID]['Shipping'] = explode('|', $Products[$prodID]['Shipping']);
}
echo "SESSION ".nl2br(print_r($_SESSION, TRUE));
endif;
This on Local Server prints

Code: Select all

SESSION Array
(
    [prod] => Array
        (
            [4] => Array
                (
                  [qty] => 100
                  [method] => 2
                )

        )

)

prodID 4
prod Array
(
 [qty] => 100
 [method] => 2
)

SESSION Array
(
    [prod] => Array
        (
            [4] => Array
                (
                    [qty] => 100
                    [method] => 2
                )

        )

)
But on the remote server, the output mysteriously changes to

Code: Select all

SESSION Array
(
[prod] => Array
(
[4] => Array
(
)

)

)
prodID 4
prod Array
(
[qty] => 100
[method] => 2
)
prodID qty
prod 100 

SESSION Array
(
    [prod] => 100
    [ERRORS] => Array
        (
        )
)
:x :?
Last edited by n00b Saibot on Fri Sep 16, 2005 5:54 am, edited 1 time in total.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

I've had a similar problem.. And after a while we found that ionCube was the one to blame for ;)

All sites showed as expected:

Code: Select all

Array ( [name] => row1 [value] => 1 )
Array ( [name] => row2 [value] => 3 )
Array ( [name] => row3 [value] => 2 )
The site with ionCube showed:

Code: Select all

Array ( [0] => Array ( [name] => row1 [value] => 1 ) [1] => 0 )
Array ( [0] => Array ( [name] => row2 [value] => 3 ) [1] => 1 )
Array ( [0] => Array ( [name] => row3 [value] => 2 ) [1] => 2 )
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

ionCube - what is this used for :?
the site is hosted @ yahoo and was working before I changed the code to add one more level of depth in the $_SESSION array. what could have possibly triggered this off???
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

Root of My Problem :arrow: register_globals = On grrrr.... :evil: :x
Boss told me since the site was hosted @ yahoo and was working perfectly before, either it was a php-version prob or my own fault. I too was baffled at this. After a little tweaking I noticed it was due my variable being of same name as in the session array which was getting mashed up.

But Yahoo doesn't allow me to upload .htaccess file :( A temporary solution would be to change the conflicting variable but what about the security, since it has a payment integration too... :?
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

The best suggestion that I can make is to get the hell away from yahoo hosting, and stay away...

If the site is for a business, i'm sure they can justify the costs involved in a legitimate hosting company... 1and1 offers hosting with php4/5 and mysql for as little as $9.99 a month (not an advertisement)...
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

nickvd wrote:The best suggestion that I can make is to get the hell away from yahoo hosting, and stay away...
Thanks, but its not me... the person who got this site made, feels comfortable there and since his site was working there and he was quite satisfied, he is not ready to listen.. :x

I'm gonna dash him off a email bomb :lol:
Post Reply