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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.