Author Topic: setcookie problem  (Read 72 times)

JohnT-FP

  • New Member
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
setcookie problem
« on: January 27, 2012, 12:23:35 PM »
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 <body> - have also tried this before <html> and <head>

PHP Code: [Select]
 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);
 }
?>


Page3 - before <html> and <head>

PHP Code: [Select]
<?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');
?>


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

technobizzmo

  • New Member
  • *
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: setcookie problem
« Reply #1 on: January 28, 2012, 03:51:17 PM »
Why not use $_SESSION instead?