close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Processing a cookie with PHP

Thread began 1/29/2010 7:57 am by info58953 | Last modified 2/08/2010 2:13 pm by Jimmy Wu | 3295 views | 10 replies |

info58953

Processing a cookie with PHP

In an order form a cookie named "amount" is saved, later the order will be processed with PHP:

<?php
require_once('xyz.class.php');
$partner_id = '123456';
$amount = ***;
$description = 'Your order';
.....
.....
.....
?>

So I need to fill $amount in the code above with the cookie "amount". I've tried WA_CookieObj.getValue("amount") in several ways without any good result. Does anyone know how to do this

Sign in to reply to this post

Dani Chankhour

try

$amount = $_COOKIE["amount"];

Sign in to reply to this post

info58953

Thanks for your suggestion, but it does not work in this case because "$amount" is not filled with the cookie variable. Just tried two ways:

$amount = $_COOKIE["amount"];
and
$amount = $_COOKIE['amount'];

To be sure the the PHP-script is okay I've tried entering 5678:

<?php
require_once('xyz.class.php');
$partner_id = '123456';
$amount = '5678';
$description = 'Your order';
.....
?>

With above code the script seems okay. Do you have another suggestion entering the cookie value in $amount?

Sign in to reply to this post

info58953

Originally Said By: info58953
  Thanks for your suggestion, but it does not work in this case because "$amount" is not filled with the cookie variable. Just tried two ways:

$amount = $_COOKIE["amount"];
and
$amount = $_COOKIE['amount'];

To be sure the the PHP-script is okay I've tried entering 5678:

<?php
require_once('xyz.class.php');
$partner_id = '123456';
$amount = '5678';
$description = 'Your order';
.....
?>

With above code the script seems okay. Do you have another suggestion entering the cookie value in $amount?  



Nobody any suggestion to solve this?

Sign in to reply to this post

Jimmy Wu

Are you sure that the cookie is being saved and with that particular name? To get a cookie value in PHP, you would use the $_COOKIE call. How is the cookie being set?

Sign in to reply to this post

info58953

Yes, the cookie has been saved with the correct name. I've set the cookie in the first page (order form):

WA_setCookie(WA_CookieObj,'Amount',document.form1.Amount.value,true,0,30);

This works fine because I can display the cookie on the next page:

The total amount is:
<script name="WACookieDis">
document.write(WA_CookieObj.getValue("Amount"));
</script>

So this looks okay, Cookies Toolkit stores en displays the cookie named "Amount".

--------------------------------------------------------------------

After the orderform was submitted a next (second) page shows order details and forwards customer to the payment provider with several variables. One of them is the total amount value $amount, i.c. the cookie named "Amount". This is my code on the second page:

<?php
require_once('ideal.class.php');
$partner_id = '12345';
$amount = '1250'
...
<html>
<head>
<title>Second Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script src="WA_Cookies/Cookies.js"></script>
...
</head>
<body>
...
Here the cookie is shown:
<script name="WACookieDis">
document.write(WA_CookieObj.getValue("Amount"));
</script>
...
[parts of payment provider PHP code stays here]
...
</body>
</html>

When I use in this page:

$amount = $_COOKIE["Amount"];

the payment provider reports an error "amount not correct" without further comments. But when I use:

$amount ='1250';

the payment provider accepts the request, everything is okay. So i'm afraid "$amount" is not filled with the cookie "Amount" by using $amount = $_COOKIE["Amount"];

Sign in to reply to this post

Jimmy Wu

Are you able to display the cookie stored amount on that page without setting it into the variable?

Sign in to reply to this post

info58953

Originally Said By: Jimmy Wu
  Are you able to display the cookie stored amount on that page without setting it into the variable?  



Yes I can with:

<script name="WACookieDis">
document.write(WA_CookieObj.getValue("Amount"));
</script>

Sign in to reply to this post

Jimmy Wu

Cookies are stored as strings. Since the value of the amount is not supposed to be stored as a string, you will have to cast the string into a float before storing it into the $amount variable:
$amount = (float) WA_CookieObj.getValue("Amount");

or
$amount = (float) $_COOKIE["Amount"];

Those should both work.

Sign in to reply to this post

info58953

Thanks again for your reply. Finally I've found what went wrong, the code after A) doesn't work and B) solved my problem:

A) $amount = $_COOKIE["amount"];
B) $amount = $_COOKIE["AMOUNT"];

Although the cookie was set with Cookies Toolkit in lowercase, in PHP it was necessary to get it in UPPERCASE like all other cookies. This was shown with the next code:

<?php
print_r($_COOKIE);
?>

Strange, but it displays an array with all cookie names in uppercase. Anyway my problem was solved and my PHP-skills were trained ;-)

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...