Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session problems 1

Status
Not open for further replies.

oohoohoohooh

Programmer
Apr 30, 2005
55
GB
Hi, I'm trying to setup my own amazon web service shopping cart. To do this I need some way of storing some of the information related to the cart and the user so I figured I would use sessions. In my file I put:

Code:
session_start();
$xml = simplexml_load_file('[URL unfurl="true"]http://webservices.amazon'[/URL] . get_tld($locale_id) . '/onca/xml?Service=AWSECommerceService&SubscriptionId=' . $subscription_id
 . '&AssociateTag=' . $associate_id . '&Operation=CartCreate&Item.1.ASIN=' . $iid . '&Item.1.Quantity=1');
$_SESSION['cart_id'] = $xml->Cart->CartId;
$_SESSION['hmac'] = $xml->Cart->HMAC;
$_SESSION['purchase_url'] = $xml->Cart->PurchaseURL;

This creates a file in the tmp directory with the following contents:

Code:
cart_id|O:16:"SimpleXMLElement":1:{i:0;s:19:"103-3188198-4511023";}
hmac|O:16:"SimpleXMLElement":1:{i:0;s:28:"9FrJnwmBFuekmBzRzauXonTb6KM=";}
purchase_url|O:16:"SimpleXMLElement":1:{i:0;s:194:"[URL unfurl="true"]https://www.amazon.com/[/URL]
gp/cart/aws-merge.html?cart-id=103-3188198-4511023%26associate-id=
punkcentre-20%26hmac=9FrJnwmBFuekmBzRzauXonTb6KM=%26SubscriptionId=
1M0SJ059ZJVGYB9B0Z82%26MergeCart=False";}

So it seems to me all is working now but when you go to another page you get the results:

Code:
PHP Warning: session_start() [function.session-start]: Node no longer exists in C:\[URL unfurl="true"]wwwroot\star[/URL] buyer\common.php on line 58 PHP Warning: session_start() [function.session-start]: Node no longer exists in C:\[URL unfurl="true"]wwwroot\star[/URL] buyer\common.php on line 58 PHP Warning: session_start() [function.session-start]: Node no longer exists in C:\[URL unfurl="true"]wwwroot\star[/URL] buyer\common.php on line 58 PHP Warning: Unknown: Node no longer exists in Unknown on line 0 PHP Warning: Unknown: Node no longer exists in Unknown on line 0 PHP Warning: Unknown: Node no longer exists in Unknown on line 0

I'd appreciate if you could help. Thanks
 
This sounds like PHP is having a problem reinstantiating the object. The "node no longer exists" sounds like nest class constructors firing off and not being able to do their jobs.

What happens when you store all of $xml in a session variable?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Hi when I did that I got loads more errors

Code:
PHP Warning: session_start() [function.session-start]: Node no longer exists in C:\[URL unfurl="true"]wwwroot\star[/URL] buyer\common.php on line 58 PHP Warning: session_start() [function.session-start]: Node no longer exists in C:\[URL unfurl="true"]wwwroot\star[/URL] buyer\common.php on line 58 PHP Warning: session_start() [function.session-start]: Node no longer exists in C:\[URL unfurl="true"]wwwroot\star[/URL] buyer\common.php on line 58 PHP Warning: session_start() [function.session-start]: Node no longer exists in C:\[URL unfurl="true"]wwwroot\star[/URL] buyer\common.php on line 58 PHP Warning: session_start() [function.session-start]: Node no longer exists in C:\[URL unfurl="true"]wwwroot\star[/URL] buyer\common.php on line 58 PHP Warning: session_start() [function.session-start]: Node no longer exists in C:\[URL unfurl="true"]wwwroot\star[/URL] buyer\common.php on line 58 PHP Warning: session_start() [function.session-start]: Node no longer exists in C:\[URL unfurl="true"]wwwroot\star[/URL] buyer\common.php on line 58 PHP Warning: session_start() [function.session-start]: Node no longer exists in C:\[URL unfurl="true"]wwwroot\star[/URL] buyer\common.php on line 58 PHP Warning: session_start() [function.session-start]: Node no longer exists in C:\[URL unfurl="true"]wwwroot\star[/URL] buyer\common.php on line 58 PHP Warning: session_start() [function.session-start]: Node no longer exists in C:\[URL unfurl="true"]wwwroot\star[/URL] buyer\common.php on line 58 PHP Warning: session_start() [function.session-start]: Node no longer exists in C:\[URL unfurl="true"]wwwroot\star[/URL] buyer\common.php on line 58 PHP Warning: session_start() [function.session-start]: Node no longer exists in C:\[URL unfurl="true"]wwwroot\star[/URL] buyer\common.php on line 58 PHP Warning: session_start() [function.session-start]: Node no longer exists in C:\[URL unfurl="true"]wwwroot\star[/URL] buyer\common.php on line 58 PHP Warning: session_start() [function.session-start]: Node no longer exists in C:\[URL unfurl="true"]wwwroot\star[/URL] buyer\common.php on line 58 PHP Warning: session_start() [function.session-start]: Node no longer exists in C:\[URL unfurl="true"]wwwroot\star[/URL] buyer\common.php on line 58 PHP Warning: session_start() [function.session-start]: Node no longer exists in C:\[URL unfurl="true"]wwwroot\star[/URL] buyer\common.php on line 58 PHP Warning: session_start() [function.session-start]: Node no longer exists in C:\[URL unfurl="true"]wwwroot\star[/URL] buyer\common.php on line 58 PHP Warning: session_start() [function.session-start]: Node no longer exists in C:\[URL unfurl="true"]wwwroot\star[/URL] buyer\common.php on line 58 PHP Warning: session_start() [function.session-start]: Node no longer exists in C:\[URL unfurl="true"]wwwroot\star[/URL] buyer\common.php on line 58 PHP Warning: session_start() [function.session-start]: Node no longer exists in C:\[URL unfurl="true"]wwwroot\star[/URL] buyer\common.php on line 58 PHP Warning: session_start() [function.session-start]: Node no longer exists in C:\[URL unfurl="true"]wwwroot\star[/URL] buyer\common.php on line 58 PHP Warning: session_start() [function.session-start]: Node no longer exists in C:\[URL unfurl="true"]wwwroot\star[/URL] buyer\common.php on line 58 PHP Warning: Unknown: Node no longer exists in Unknown on line 0
 
It's still something to do with that class. When PHP instantiates the class from the session store, it's probably trying to run some kind of constructor which does not have the information needed.

Does $xml->Cart->CartId contain the actual value of the cart_id? Or is there some interior structure you have to access to get the string-type card id? If you do:

print_r ( $xml->Cart->CartId);

what do you get?

What I'm trying to get at is to store the string of the cart ID's value, not the object. Or would that be useful to you?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Hmm it outputs:

SimpleXMLElement Object ( [0] => 104-9375040-9923111 )

I tried:

print_r ( $xml->Cart[0]->CartId);

but it did the same. I'd assume this is the problem. I tried echo $xml->Cart->CartId and that returned the value as I would expect. Cheers
 
If your script runs the line:

print_r ( $xml->Cart->CartId);

and returns:

SimpleXMLElement Object ( [0] => 104-9375040-9923111 )

Then treating $xml->Cart as an array won't work because it's $xml->Cart->CartID that might be the array, not $xml->Cart. As it is, PHP is saying it's an object, not an array. So try:

print_r ($xml->Cart->CartID->0);

if that outputs a string, you should be able to store that in a session variable without a warning.

But will that string value be of any use to your script?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Hi I tried as you said but it returned:

PHP Parse error: syntax error, unexpected T_LNUMBER, expecting T_STRING or T_VARIABLE or '{' or '$' in C:\Inetpub\ buyer\shopping_cart.php on line 40

I then tried print_r($xml) (so you can see what we're dealing with) and I got:

Code:
SimpleXMLElement Object
(
    [OperationRequest] => SimpleXMLElement Object
        (
            [HTTPHeaders] => SimpleXMLElement Object
                (
                    [Header] => SimpleXMLElement Object
                        (
                        )

                )

            [RequestId] => 0H90KSXWGCE252XH8R5D
            [Arguments] => SimpleXMLElement Object
                (
                    [Argument] => Array
                        (
                            [0] => SimpleXMLElement Object
                                (
                                )

                            [1] => SimpleXMLElement Object
                                (
                                )

                            [2] => SimpleXMLElement Object
                                (
                                )

                            [3] => SimpleXMLElement Object
                                (
                                )

                            [4] => SimpleXMLElement Object
                                (
                                )

                            [5] => SimpleXMLElement Object
                                (
                                )

                        )

                )

            [RequestProcessingTime] => 0.0946681499481201
        )

    [Cart] => SimpleXMLElement Object
        (
            [Request] => SimpleXMLElement Object
                (
                    [IsValid] => True
                    [CartCreateRequest] => SimpleXMLElement Object
                        (
                            [Items] => SimpleXMLElement Object
                                (
                                    [Item] => SimpleXMLElement Object
                                        (
                                            [ASIN] => B000067DNF
                                            [Quantity] => 1
                                        )

                                )

                        )

                )

            [CartId] => 104-8442158-7467953
            [HMAC] => 5TX54N5y6eQmU6rtomGeGqerUWU=
            [URLEncodedHMAC] => 5TX54N5y6eQmU6rtomGeGqerUWU=
            [PurchaseURL] => [URL unfurl="true"]https://www.amazon.com/gp/cart/aws-merge.html?cart-id=104-8442158-7467953%26associate-id=punkcentre-20%26hmac=5TX54N5y6eQmU6rtomGeGqerUWU=%26SubscriptionId=1M0SJ059ZJVGYB9B0Z82%26MergeCart=False[/URL]
            [SubTotal] => SimpleXMLElement Object
                (
                    [Amount] => 2939
                    [CurrencyCode] => USD
                    [FormattedPrice] => $29.39
                )

            [CartItems] => SimpleXMLElement Object
                (
                    [SubTotal] => SimpleXMLElement Object
                        (
                            [Amount] => 2939
                            [CurrencyCode] => USD
                            [FormattedPrice] => $29.39
                        )

                    [CartItem] => SimpleXMLElement Object
                        (
                            [CartItemId] => U2CQDN0F5LVC4F
                            [ASIN] => B000067DNF
                            [MerchantId] => ATVPDKIKX0DER
                            [SellerId] => A2R2RITDJNW1Q6
                            [SellerNickname] => Amazon.com, LLC
                            [Quantity] => 1
                            [Title] => The Lord of the Rings - The Fellowship of the Ring (Platinum Series Special Extended Edition)
                            [ProductGroup] => DVD
                            [Price] => SimpleXMLElement Object
                                (
                                    [Amount] => 2939
                                    [CurrencyCode] => USD
                                    [FormattedPrice] => $29.39
                                )

                            [ItemTotal] => SimpleXMLElement Object
                                (
                                    [Amount] => 2939
                                    [CurrencyCode] => USD
                                    [FormattedPrice] => $29.39
                                )

                        )

                )

        )

)
 
That's weird.

$xml->Cart->CardID should be a string. Why did it give you:

SimpleXMLElement Object ( [0] => 104-9375040-9923111 )

earlier?

If you do:

print gettype($xml->Cart->CartID);

what do you get?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Hi, cheers for your help so far much appreciated. When I try what you said it gives object.
 
Hi sorry thought you'd given up on me. When i tried what you said it returned:

Array
(
)
 
Okay. Here's what I did...

I used your print_r($xml) output to duplicate your script. I'm probably abusing some ID of yours at Amazon, but I allowed me to more quickly see what was going on.

There is no way I know of to store the objects in the sessions without the "Node no longer exists" error.

However, the script can store the string values of the cart ID, the HMAC and the purchase URL in session variables. This also makes the errors go away.

Try this version of your originally-posted script excerpt:

Code:
session_start();
$xml = simplexml_load_file('[URL unfurl="true"]http://webservices.amazon'[/URL] . get_tld($locale_id) . '/onca/xml?Service=AWSECommerceService&SubscriptionId=' . $subscription_id . '&AssociateTag=' . $associate_id . '&Operation=CartCreate&Item.1.ASIN=' . $iid . '&Item.1.Quantity=1');
$_SESSION['cart_id'] = [red](string)[/red]$xml->Cart->CartId;
$_SESSION['hmac'] = [red](string)[/red]$xml->Cart->HMAC;
$_SESSION['purchase_url'] = [red](string)[/red]$xml->Cart->PurchaseURL;


BTW: I am going to redflag your post in this thread which has the entire output of $xml with a comment that the post be either deleted or be edited to remove any information you don't want permanently posted.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top