Forum Moderators: coopster

Message Too Old, No Replies

Variable keeps clearing bewteen pages

         

bigglejones

2:24 am on Jul 10, 2005 (gmt 0)

10+ Year Member



I am trying to set up a simple cookie where webmasters can input their affiliate ids (CCBill ID, on top of page), and have it displayed instead of the default XXXXXX embeded in the text link: http://example.com/cgi-bin/clicks.cgi?CA=927022 &PA=XXXXXX&HTML=http://www.example2.com

Although I finally have this working fine, when they navigate to another page:
[example2.com...] (the only other fuctional page)...the cookie that had been entered into the textbox is now cleared and defaults back to the XXXXXX

Here is the cookie code that I am using (I know it is not secure, but there is no information being sent):

<?
$ccbillid = "".$_POST['ccbillinput']."";
$cookie_life = time() + 31536000;
setcookie('ccbillid', $ccbillid, $cookie_life, '/', '.example2.com');
$_COOKIE["ccbillid"] = $ccbillid;

if (!$_COOKIE["ccbillid"]){$ccbilloutput = "XXXXXX"; }
else {$ccbilloutput = $_COOKIE["ccbillid"]; }
?>

And when the variable is being called:

<? print $ccbilloutput;?>

...Any help would be great. Thanks in advance.

[edited by: ergophobe at 2:47 am (utc) on July 10, 2005]
[edit reason] no personal URLs please - see site Usage Agreement [/edit]

bigglejones

2:25 am on Jul 10, 2005 (gmt 0)

10+ Year Member



...also....would it be better to place the cookie code in the individual pages or in a file all its own?

coopster

5:06 pm on Jul 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Are you trying to read the same cookie from two different domains here?

bigglejones

7:35 pm on Jul 10, 2005 (gmt 0)

10+ Year Member



same cookie....just one domain

bigglejones

1:32 am on Jul 12, 2005 (gmt 0)

10+ Year Member



...bump

dcrombie

11:32 am on Jul 12, 2005 (gmt 0)



Your main problem is that you are always overwriting the value with '' after the first POST. Try this (untested):

if(isset($_COOKIE['ccbillinput']) $ccbillid = $_COOKIE['ccbillinput']; 
if(isset($_POST['ccbillinput']) $ccbillid = $_POST['ccbillinput'];

;)

bigglejones

8:33 pm on Jul 12, 2005 (gmt 0)

10+ Year Member



hey dcrombie, thanks for the suggestion. I added your code in, and now i get: 'Parse error: parse error, unexpected T_VARIABLE' for your section of the code.

coopster

10:30 am on Jul 13, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The if statement is missing a closing parenthesis.