setcookie problem

I’m relatively new to PHP and having cookie trouble!

I have a simple checkout process:

Page1 - customer selects required products
Page2 - customer enters billing info
Page3 - customer confirms order
Page4 - order success/fail

I am trying to set a cookie so that if the customer returns to Page2 their billing info is automatically completed.

Relevant code:

Page2 - within the - have also tried this before and

[php] if(isset($_COOKIE[‘MyOrder’]))
{
$cookie_chunks = explode(’^’,$_COOKIE[‘MyOrder’]);
$title = $cookie_chunks(0);
$firstname = $cookie_chunks(1);
$lastname = $cookie_chunks(2);
$email = $cookie_chunks(3);
$telephone = $cookie_chunks(4);
$mobile = $cookie_chunks(5);
$address = $cookie_chunks(6);
$address2 = $cookie_chunks(7);
$town = $cookie_chunks(8);
$postcode = $cookie_chunks(9);
}
?>[/php]

Page3 - before and

[php]<?php
//this adds 365 days to the current time
$InOneYear = 60 * 60 * 24 * 365 + time();
$CustDetails = $_POST[‘title’].’^’.$_POST[‘firstname’].’^’.$_POST[‘lastname’].’^’.$_POST[‘email’].’^’.$_POST[‘telephone’].’^’.$_POST[‘mobile’].’^’.$_POST[‘address’].’^’.$_POST[‘address2’].’^’.$_POST[‘town’].’^’.$_POST[‘postcode’];
setcookie(‘MyOrder’, $CustDetails, $InOneYear,’/’,‘mydomain.co.uk’);
?>
[/php]

The cookie is not being created - I am testing in Firefox and IE.

Would appreciate someone pointing out the error of my ways!

Many thanks

John

Why not use $_SESSION instead?

Sponsor our Newsletter | Privacy Policy | Terms of Service