View Full Version : Remember Array Contents

11-21-2007, 06:17 PM

I have the following code, that inserts the ID value of a link into an array, upon the link being clicked. See example link below:

www.somthing.co.uk/functions.php?id=23 (www.somthing.co.uk/functions.php?id=23)

How do I get the array to remember its contents, so if the browsers back button is used, and another link is clicked, this link should append/add it's id to whats already inside the array?

What do I need to change in the following code in order for the array to remember its contents:


$array[] = $id;


11-21-2007, 06:32 PM
Use sessions:


$_SESSION['ids'][] = $id;
$array = & $_SESSION['ids'];

/* ... */

print_r( $array );


11-21-2007, 06:50 PM
The above code doesn't work, when I press the "Back" button on my browser, and select a link with a diffrent ID (or even the same ID) all I get is the following: - Wheres the data?

Array ( [0] => [1] => [2] => [3] => [4] => )

11-21-2007, 07:13 PM
Try using $_GET['id'] instead of $id. I don't think kbluhm intended for you to take that code literally, but more as an example.

11-21-2007, 07:54 PM
How do I check is the array already contains a particular id, and if so display the following message "Already Exists", if not, then add it?

11-21-2007, 09:04 PM

11-22-2007, 02:10 PM
I'd use a cookie to store the data

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum