Solved

PHP passing variables between pages using sessions

Posted on 2011-09-02
3
210 Views
Last Modified: 2012-05-12
I know I'm being thick but passing variables between pages in PHP seems awkward, or I'm sure I make it more complex that it needs be...

I have some variables I want to pass to another page, say a small array as a single variable.

$Car[1]="Ford";
$Car[2]="General Motors";
$Car[3]="VW";
$CarColor="Blue";

To begin the process I issue a session_start(): command.
What I don't understand is how I tell the script to stop remembering the variables I wish to add to the session and then regurgitate them on the next page?





0
Comment
Question by:edhasted
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
boon86 earned 500 total points
ID: 36475074
Page 1:

<?php

session_start();
$Car[1]="Ford";
$Car[2]="General Motors";
$Car[3]="VW";
$CarColor="Blue";


$_SESSION['car1'] = $Car[1];
$_SESSION['car2'] = $Car[2];
$_SESSION['car3'] = $Car[3];
$_SESSION['carColor'] = $CarColor;
?>

Open in new window


Page 2:

<?php
session_start();

echo $_SESSION['car1'];
echo $_SESSION['car2'];
echo $_SESSION['car3'];
echo $_SESSION['carColor'];
session_destroy();

?>

Open in new window


hope that help
0
 

Author Comment

by:edhasted
ID: 36475168
Brilliant - that's it. I did try something similar but I clearly mucked up my syntax.
0
 

Author Closing Comment

by:edhasted
ID: 36475182
Many thanks for such as fast and easy to understand solution.

I had trawled several pages on the net and they were nowhere near as understandable or concise.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question