Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 6th, 2005, 07:09 PM
Authorized User
 
Join Date: Dec 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Cookie and Session

I have some code to set a cookie, it seems to be working fine, although I can't delete the cookie. Even after the next page runs the code to expire the cookie. Not sure what I'm doing wrong. Any help would be appreciated.

Heres the code to set the cookie:

if(isset($_COOKIE["CartID"]))
{
return $_COOKIE["CartID"];
}
else
{
// There is no cookie set. We will set the cookie
// and return the value of the users session ID

session_start();
setcookie("CartID", session_id(), time() + ((3600 * 24) * 30));
return session_id();
}

Here is one of the many ways that I have tried to expire the cookie:

//remove the cookie from the users machine
setcookie("CartID", "session_id()", mktime(12,0,0,1, 1, 1990));
session_start();
$_SESSION = array();
session_destroy();

I have also tried this to destroy the information in the session:

<?php //remove the cookie from the users machine
setcookie("CartID");
session_unregister('PHPSESSID');
unset($_SESSION['PHPSESSID']);
?>

and many other attempts. I have read as much as I can find from google and I have tried pretty much everything that I have read.

I need the session and the cookie information to clear. I have been trying for over 2 days now with about 8-10 hours a day. I'm a little lost and getting frustrated. the set cookie code is on a different page. When a user finishes and clicks to "submit" they are rediredted to a page that only contains the code to remove the cookie and clear the session, they are then redirected once again to the home page. I would like the home page to load as if it were their first visit.


Thanks






Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP session cookie ajit Beginning PHP 0 October 23rd, 2007 11:56 PM
Encrypting session cookie krisXp Classic ASP Databases 1 November 9th, 2006 10:21 AM
session and cookie problem (empty session file) msincan BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 February 27th, 2005 05:31 PM
Session and Cookie authentification dsunmedia PHP How-To 2 August 30th, 2004 06:52 PM
Session cookie problem rogierio Classic ASP Professional 0 October 15th, 2003 09:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.