Jump to content

Remember Array Contents


Dysan

Recommended Posts

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);

?>

Link to comment
https://forums.phpfreaks.com/topic/78283-remember-array-contents/
Share on other sites

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);

?>

<?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.

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.