Page 1 of 1

foreach behaving wierd on remote server :x

Posted: Fri Sep 16, 2005 3:46 am
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 :?

Posted: Fri Sep 16, 2005 5:37 am
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 )

Posted: Fri Sep 16, 2005 6:02 am
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???

Posted: Sat Sep 17, 2005 6:49 am
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... :?

Posted: Sat Sep 17, 2005 9:02 am
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)...

Posted: Mon Sep 19, 2005 3:28 am
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: