1

I have never worked with sessions before so just need a bit of guidance. Some data from a form needs to be held whilst someone logs in. So I have got this far.

<?php
$_SESSION['tmp']['booking-form'] = array(
    'GT_title' => $SEStitle,
    'GT_actual_duration' => $SESactualduration,
    'SEScalstartdate' => $calstartdate,
    'GT_picture' => $picture,
    'GT_total_duration' => $SEStotalduration,
    'GT_total_dives' => $SEStotaldives,
    'GT_total_price' => $SEStotalprice,
    'GT_total_duration' => $SEStotalduration,
    'GT_specifications' => $SESspecifications
);
?>

Three questions.

  1. Where do I put this code as all the named fields in the array exist in a form towards the bottom of the page before the log in process begins.

  2. Is that all the code I need or do I need to put something else somewhere else.

  3. What do I do to call this session when the client has finished logging in and has been redirected to the booking area where I want this data to be called back up.

2 Answers 2

2

Check http://www.w3schools.com/php/php_sessions.asp and http://php.net/manual/en/ref.session.php . Hope this will help you.

Edit:

Your code should something like :

session_start();
$_SESSION['temp'] = array('GT_title' => $SEStitle, 'GT_actual_duration' => $SESactualduration, 'SEScalstartdate' => $calstartdate, 'GT_picture' => $picture, 'GT_total_duration' => $SEStotalduration, 'GT_total_dives' => $SEStotaldives, 'GT_total_price' => $SEStotalprice, 'GT_total_duration' => $SEStotalduration, 'GT_specifications' => $SESspecifications);


echo $_SESSION['temp']['GT_title'];//the value of $SEStitle will be here...

It might give you an idea what is going on behind the scene. Also REMEMBER that you have to call session_start() function in the top of the page where you want to use $_SESSION[]

Sign up to request clarification or add additional context in comments.

4 Comments

@armonge i didn't find any useful information about SESSION at w3fools.com .
I was talking about suggesting w3schools to someone
@armong: Wow, someone really found sufficient time, money and indignation to put up an anti-w3cschools site?
@RobertHarvey: It's been up for some time actually, and I'd say its PHP tutorials are error free (not 100% sure), so stop posting w3fools on it please. They are doing a fine job. +1 :P
0

Wherever you want to use the session data, call session_start() at the top of any page before any output.

You set the $_SESSION[] wherever you have the data.

You can get the data after login using the same $_SESSION[] array. It will be populated as soon as session_start() has been called.

1 Comment

Right so on the page where I collected data from a form I collected it in an array with <?php $_SESSION['tmp'] = array('GT_title' => $SEStitle, 'GT_actual_duration' => .... etc. Then on the page I want to call it back up I put <?php session_start() ?> at the very top and the call the date with <?php $_SESSION['tmp']?> Then how do I get the fields out of the session. Do I then put <?php echo $_POST["GT_title"];?> where I want the title etc... ???

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.