Jump to content

PHP help needed - Saving a value in the url to the cahce and populating a field


steannan

Recommended Posts

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.

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?

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;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.