steannan Posted October 26, 2011 Share Posted October 26, 2011 Hi wondering if anybody here could help me work out some code... What I'm trying to do is save a value from a URL to populate a field on a form, but then I also want the value to be saved to the users cache so that is available to other pages on the site. Then once returning to the page with the form the field will repopulate with the data from the cache. I hope that makes sense. example of link: www.awebsite.com/pagename?id=1234 I know I can use $_GET["id"]; to read the value in the URL and populate the field on the form. What I don't know how to do is save the value to the cache and then load it from cache automatically if the page doesn't have the value in the link. Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/249816-php-help-needed-saving-a-value-in-the-url-to-the-cahce-and-populating-a-field/ Share on other sites More sharing options...
xtopolis Posted October 26, 2011 Share Posted October 26, 2011 to implement a "cache" use cookies or sessions. Quote Link to comment https://forums.phpfreaks.com/topic/249816-php-help-needed-saving-a-value-in-the-url-to-the-cahce-and-populating-a-field/#findComment-1282270 Share on other sites More sharing options...
steannan Posted October 26, 2011 Author Share Posted October 26, 2011 Thanks, I looked it up and have come up with this: to run on page to get id from link and save to cache: <?php $id = $_GET["id"]; setcookie(referrer, $id, 6400); ?> To put in form field: <?php if(isset($_COOKIE['referrer'])) { $last = $_COOKIE['referrer']; print $last; } else { print $_GET["id"]; } ?> Does this look correct or is there a better way? Quote Link to comment https://forums.phpfreaks.com/topic/249816-php-help-needed-saving-a-value-in-the-url-to-the-cahce-and-populating-a-field/#findComment-1282276 Share on other sites More sharing options...
xtopolis Posted October 26, 2011 Share Posted October 26, 2011 ! try it and find out. it seems ok for me, but I don't have time to test it. Quote Link to comment https://forums.phpfreaks.com/topic/249816-php-help-needed-saving-a-value-in-the-url-to-the-cahce-and-populating-a-field/#findComment-1282279 Share on other sites More sharing options...
steannan Posted October 26, 2011 Author Share Posted October 26, 2011 thanks for your help, worked it out in the end. had the page load with this in the site wide header: if(isset($_COOKIE["Referrer"])) { } else { $refer = $_GET['id']; setcookie("Referrer", $refer, time()+3600); and this value in the field on the form: if(isset($_COOKIE["Referrer"])) { $val= $_COOKIE["Referrer"]; } else { $val = $_GET["id"]; } return $val; Quote Link to comment https://forums.phpfreaks.com/topic/249816-php-help-needed-saving-a-value-in-the-url-to-the-cahce-and-populating-a-field/#findComment-1282292 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.