PDA

View Full Version : PHP cookie retention


aceman7766
08-21-2006, 11:45 PM
I have been designing a website that requires registration for a course (NO shopping cart). The logic goes like this:
1. course list (select) -- i have <inputs hidden> for each part (i.e. course id, name, cost, etc...)
2. --> cookie.php -- pg that stores the course list info then redirects to
3. registration form (submit) -- so you put all information (non pmt)
4. --> cookie.php -- pg that stores the form information then redirects to
5. mailpg.php -- pg that now pulls all the $_cookie[] information and submits the formmail then redirects to
6. paypalpg.php -- pg that now pulls all the $_cookie[] information and submits to the Paypal.com pg so the info is pulled up by Paypal
7. Successful redirect to a thank you pg on the website OR.
8. Cancel redirect to course list page.

-- My problem is that it seems to store all the information, HOWEVER, it loses ONLY the item_name & item_number EVERYTIME i get to step #5. But if it is a cookie and im storing it -- why would it NOT hold JUST those 2? Obviously it would just not store any correct?

I have NO clue where my issue is.

setcookie("item_number", $_POST['item_number'], time()+3600);
-- i am calling it on step 5 as:
<input type="hidden" name="item_number" value="<?= $HTTP_COOKIE_VARS['item_number']; ?>" />
-- and if i use a sub page just to echo all my stored cookies (which ALL work, except the item_name & item_number).

Please help as all the searches have led me NO WHERE.

Anthony

erisco
08-21-2006, 11:50 PM
I would check for typos of cookie names myself, also make sure they are being echoed again correctly.

aceman7766
08-22-2006, 12:31 AM
Well I have done typo checks and they are clean. If I use my testpg.php which ONLY echos all the cookies it fails after the step 3. But i have noticed that its random cookies that are not being retained.
www.aceitce.com/FEG/
that will show you if you follow through the example as what is not being retained using cookies -- but what you are missing is the cookies.php

<?php

// Gets the Current Server Time
$time = time();
$pagename = $_POST['pagename'];

if ($pagename == "course_selection") {
setcookie("item_name", "", time()-3600);
setcookie("item_number", "", time()-3600);
setcookie("date", "", time()-3600);
setcookie("time", "", time()-3600);
setcookie("cpehours", "", time()-3600);
setcookie("location1", "", time()-3600);
setcookie("location2", "", time()-3600);
setcookie("location3", "", time()-3600);
setcookie("amount", "", time()-3600);

setcookie("item_name", $_POST['item_name'], time()+3600);
setcookie("item_number", $_POST['item_number'], time()+3600);
setcookie("date", $_POST['date'], time()+3600);
setcookie("time", $_POST['time'], time()+3600);
setcookie("cpehours", $_POST['cpehours'], time()+3600);
setcookie("location1", $_POST['location1'], time()+3600);
setcookie("location2", $_POST['location2'], time()+3600);
setcookie("location3", $_POST['location3'], time()+3600);
setcookie("amount", $_POST['amount'], time()+3600);
$pagename = "";

// header('Location: testpg4.php');
header('Location: registerForm_test.php');
exit();
}

elseif ($pagename == "registration_selection") {
if ($_POST['address2'] != "") {
setcookie("address2", "", time()-3600);
setcookie("address2", $_POST['address2'], time()+3600);
}
if ($_POST['company'] != "") {
setcookie("company", "", time()-3600);
setcookie("company", $_POST['company'], time()+3600);
}
if ($_POST['company_title'] != "") {
setcookie("company_title", "", time()-3600);
setcookie("company_title", $_POST['company_title'], time()+3600);
}

$paypal_track = true;
// Set a cookie storing the firstname
setcookie("first_name", "", time()-3600);
setcookie("last_name", "", time()-3600);
setcookie("address1", "", time()-3600);
setcookie("city", "", time()-3600);
setcookie("state", "", time()-3600);
setcookie("zip", "", time()-3600);
setcookie("day_phone_a", "", time()-3600);
setcookie("day_phone_b", "", time()-3600);
setcookie("day_phone_c", "", time()-3600);
setcookie("paypal_track", "", time()-3600);

setcookie("first_name", $_POST['first_name'], time()+3600);
setcookie("last_name", $_POST['last_name'], time()+3600);
setcookie("address1", $_POST['address1'], time()+3600);
setcookie("city", $_POST['city'], time()+3600);
setcookie("state", $_POST['state'], time()+3600);
setcookie("zip", $_POST['zip'], time()+3600);
setcookie("email", $_POST['email'], time()+3600);
setcookie("day_phone_a", $_POST['day_phone_a'], time()+3600);
setcookie("day_phone_b", $_POST['day_phone_b'], time()+3600);
setcookie("day_phone_c", $_POST['day_phone_c'], time()+3600);
setcookie("paypal_track", $paypal_track, time()+3600);
$pagename = "";

header('Location: testpg4.php');
// header('Location: mail_sender.php');
exit();
}
?>