Jump to content

Recommended Posts

In my last posting someone suggested using session start() to pass a variable through multiple php pages using the $_SESSION['x']=$x;.  I don't quite understand how to do it.  Another individual suggested using

hidden fields in your form
which I'm not sure how to do either.  Any help with this would be really appreciated.

-Robb

Link to comment
https://forums.phpfreaks.com/topic/66013-solved-how-does-session_start-work/
Share on other sites

well what do you want to pass? If its something from ur database you do ur query, then like $_SESSION['whatever'] = $whatever;

 

So now in anypage where your session is started and you call the  $_SESSION['whatever'] variable it will give you $whatever

I'm trying to pass a variable from the first page (tells me what type of item they are going to enter [dvd,cd,book]) i'm writing through the second page (where they enter all the pertinent information [title author etc.]) into a third page where the items are submitted into the database.

 

I guess part of the question was, in the sticky posted above, they said header errors occured due to where something like session_start() was posted.  I'm just not clear on what they meant.

Thanks,

-Robb

Session variables allow you to capture user entered values for the duration of the users session.  At the top of all the pages in your app, make sure you include

 

<?php
session_start();
?>

 

This basically allows you to invoke the session array.  So if a user posts a value from a form you can assign it to $_SESSION['dvd'];

 

Then for the duration of the session, that variable will be available in that array.

No what the sticky said is output errors may be do to session start but thats not your problem. On your first page you start the session, then set the session thing like i told you to their choice, then all you do is start the session in all your other pages and you can call it when ever you want as long as your session is started.

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.