Jump to content

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.

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.