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); } Link to comment https://forums.phpfreaks.com/topic/44568-help-with-cookies/ 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); Link to comment https://forums.phpfreaks.com/topic/44568-help-with-cookies/#findComment-216467 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? Link to comment https://forums.phpfreaks.com/topic/44568-help-with-cookies/#findComment-216473 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? Link to comment https://forums.phpfreaks.com/topic/44568-help-with-cookies/#findComment-216485 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']."\" />"; ?> Link to comment https://forums.phpfreaks.com/topic/44568-help-with-cookies/#findComment-216496 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.