Dysan Posted November 21, 2007 Share Posted November 21, 2007 Hi, 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 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: <?php $array[] = $id; print_r($array); ?> Quote Link to comment https://forums.phpfreaks.com/topic/78283-remember-array-contents/ Share on other sites More sharing options...
Wes1890 Posted November 21, 2007 Share Posted November 21, 2007 ^ you'll need to use some kind of DB system to remember whats been accessed Quote Link to comment https://forums.phpfreaks.com/topic/78283-remember-array-contents/#findComment-396144 Share on other sites More sharing options...
BenInBlack Posted November 21, 2007 Share Posted November 21, 2007 you need to put session_start(); at the top of all your php files that will use $array and get and set the values using the $_SESSION var <?php session_start(); if (isset($_SESSION['array']) { $array = $_SESSION['array']; } $array[] = $id; $_SESSION['array'] = $array; print_r($array); ?> Quote Link to comment https://forums.phpfreaks.com/topic/78283-remember-array-contents/#findComment-396145 Share on other sites More sharing options...
Glyde Posted November 21, 2007 Share Posted November 21, 2007 <?php session_start(); if (!is_array($_SESSION['ids'])) { $_SESSION['ids'] = array(); } $_SESSION['ids'][] = $_GET['id']; ?> Are you accessing the id parameter from the url with $id? If so, PLEASE TURN register_globals OFF. It makes your code so much more vulnerable. Quote Link to comment https://forums.phpfreaks.com/topic/78283-remember-array-contents/#findComment-396146 Share on other sites More sharing options...
Dysan Posted November 21, 2007 Author Share Posted November 21, 2007 What does register_globals do? How do I turn it off? Quote Link to comment https://forums.phpfreaks.com/topic/78283-remember-array-contents/#findComment-396165 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.