problem with overwritting php cookie

Posted on 2007-10-12
Medium Priority
Last Modified: 2013-12-13
I am having a problem with cookies using php.

I have pages that track what affiliate sent me traffic, and what the keyword for the add is.

ID is the affiliates ID


I have the code below on msyite.com/index.php, and mysite.com/someotherpage.php

When a user click thru to http://www.mysite.com/index.php?ID=100&wk=abc
, then goes to
that has the same code below,(the same code as mysite.com/index.php) the cookies are overwritten from ID=100&wk=abc to values of 0., and  I can't capture the id when it is uploaded into a database.

 $ID_club = $_GET['ID'];
 $keyword = $_GET['keyword'];
setcookie("club_id_refer", $ID_club);
setcookie("club_id_refer", $ID_club, time()+3600);  /* expire in 1 hour */
setcookie("keyword_refer", $keyword);
setcookie("keyword_refer", $keyword, time()+3600);  /* expire in 1 hour */

How can I make sure that this cookie is not overwritten from the page that the user first arrives at?

Thanks for the help!
Question by:derekstattin
1 Comment

Accepted Solution

karlwilbur earned 2000 total points
ID: 20069993
if (isset($_GET['ID']) && isset($_GET['keyword']) ) {
     $ID_club = $_GET['ID'];
     $keyword = $_GET['keyword'];
     setcookie("club_id_refer", $ID_club, time()+3600);  /* expire in 1 hour */
     setcookie("keyword_refer", $keyword, time()+3600);  /* expire in 1 hour */

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month15 days, 1 hour left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question