flusho Posted May 11, 2007 Share Posted May 11, 2007 Is it possible to send an array from one page to another using sessions. If not is there a better way? without it being a global. thanks, flusho Quote Link to comment https://forums.phpfreaks.com/topic/50977-solved-passing-arrays-through-sessions/ Share on other sites More sharing options...
chigley Posted May 11, 2007 Share Posted May 11, 2007 <?php session_start(); $array = array("foo", "bar"); $_SESSION['array'] = $array; header("Location: page2.php"); ?> <?php session_start(); $array = $_SESSION['array']; ?> Tested, works fine! Quote Link to comment https://forums.phpfreaks.com/topic/50977-solved-passing-arrays-through-sessions/#findComment-250796 Share on other sites More sharing options...
per1os Posted May 11, 2007 Share Posted May 11, 2007 Have you tried it? It should be possible as long as session_start() is used. However, if it does not work right you may want to look into www.php.net/serialize and www.php.net/unserialize But try it first and see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/50977-solved-passing-arrays-through-sessions/#findComment-250798 Share on other sites More sharing options...
chronister Posted May 11, 2007 Share Posted May 11, 2007 Yes, you can send arrays through sessions. I created a shopping list for my wife and when she checks the items she wants to print, it creates an array and sets to a session. On the print page I take the session and break up the session into 3 arrays to make 3 colums on the page. Here is where I grab the $_POST data, and set it as a session <?php $list_items= $_POST['list_items']; if ($_POST['printit']){ session_start(); //start the session $_SESSION['list_items']= $list_items; // set the session to the $_POST var above echo'<meta http-equiv="refresh" content="0;URL='.$root.'shopping_list/printing.php" target="_blank" >'; }; ?> Here is where I take the entire list and break it up into 3 columns containing 45 items each <?php session_start(); $list=array_slice($_SESSION['list_items'],0,45); $list2=array_slice($_SESSION['list_items'],46,45); $list3=array_slice($_SESSION['list_items'],91,45); // more code below here...... ?> Just remember to start_session() before you try to set the session vars. Also you are creating a multi-dimensional array here as $_SESSION is an array as well Nate Quote Link to comment https://forums.phpfreaks.com/topic/50977-solved-passing-arrays-through-sessions/#findComment-250835 Share on other sites More sharing options...
flusho Posted May 11, 2007 Author Share Posted May 11, 2007 Thanks guys. I think that does the trick. have a great weekend. flusho. Quote Link to comment https://forums.phpfreaks.com/topic/50977-solved-passing-arrays-through-sessions/#findComment-250859 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.