jimmyp3016 Posted March 28, 2007 Share Posted March 28, 2007 Hey Guys, I need some help with cookies. What im trying to do is store an refferer id so if someone comes back to my webpage, the person who reffered them will get the credit. Here is what I have but it does not store the cookie. Any help ASAP would be much appreciated. $ref = $_REQUEST['referer']; if ( !$ref ) $ref = -1; if(isset($_COOKIE['mysite'])) { echo ""; } else { $Month = 2592000 + time(); setcookie(mysite, $ref, $Month); } Quote Link to comment Share on other sites More sharing options...
trq Posted March 28, 2007 Share Posted March 28, 2007 Unless you have defined the constant mysite somewhere this will not work.... setcookie(mysite, $ref, $Month); Try.... setcookie('mysite', $ref, $Month); Quote Link to comment Share on other sites More sharing options...
jimmyp3016 Posted March 28, 2007 Author Share Posted March 28, 2007 Thanks for the quick response. I dont think its pulling the cookie once its set because I have a hidden value in my form <?php if ($_REQUEST['ref']) echo "<input type=\"hidden\" name=\"referer\" value=\"".$_REQUEST['ref']."\" />"; ?> If I hit mysite.com?ref=4 That hidden value shows 4 and should store a cookie But if i then go to mysite.com it should pull the cookie and show the hidden value of 4 but it doesnt. Any thoughts? Quote Link to comment Share on other sites More sharing options...
jimmyp3016 Posted March 28, 2007 Author Share Posted March 28, 2007 Ok, disreguard my last post by doing a print_r($_COOKIE); It DOES display my stored cookie and the ref value. My only question is how can I get that value to populate my hidden form value of <?php if ($_REQUEST['ref']) echo "<input type=\"hidden\" name=\"referer\" value=\"".$_REQUEST['ref']."\" />"; ?> Do i request the cookie instead? Quote Link to comment Share on other sites More sharing options...
MadTechie Posted March 28, 2007 Share Posted March 28, 2007 Try <?php if ($_GET['ref']) echo "<input type=\"hidden\" name=\"referer\" value=\"".$_COOKIE['mysite']."\" />"; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.