PDA

View Full Version : Sessions



Rockonmetal
12-07-2007, 01:51 AM
I am trying to understand how Sessions possibly work and what makes them work.
I am trying to make a control panel, but I have one problem. When I go from the index to the account options, the information doesn't send over.

I have 5 pages in my user control panel.
1. Index
2. Account Options
3a. Upload File Form
3b. Upload File Actions
4. Video Options.

I don't get how sessions work... I know they can store variables throughout multiple pages...
I have already done the following tutorials...
w3schools
tengiz *or whatever it is*
php.net
and phpfreaks

I am trying to have it so that a logged in user on index.php can click on upload video link and then it would carry either the username or the user id in a variable.
Thanks

thetestingsite
12-07-2007, 02:30 AM
Do you have session_start() at the top of every page? If so, how are you assigning and then calling the session variables? (post a code snippet or something). Those are the only things I can think of.

Hope this helps.

Rockonmetal
12-07-2007, 02:43 AM
well, the thing is, I know that i need session_start() at the top... I just don't know how to get it so that I don't have to receive the variables all the time... Or do i just place session_start() at the top and all the variables carry over???

thetestingsite
12-07-2007, 03:46 AM
well, you have to have session_start at the top of the pages so that the session variables get carried over. Then to use that variable, you have to call it like so:



<?php
session_start();
echo $_SESSION['variable'];
?>


hope this helps.

Rockonmetal
12-07-2007, 03:53 AM
Ok i have this...

<?php
session_start();
$variable = "Var";
$_SESSION['variable'];
?>
<html>
<body>
<?php
echo $variable;
echo "<a href='end.php'>Next</a>";

?>
</body>

Then on the next page I have this...

<html>
<body>
<?php
echo $variable;
?>
</body>
</html>
It doesn't seem to be working...

thetestingsite
12-07-2007, 04:16 AM
This:



$variable = "Var";
$_SESSION['variable'];


is assigning the variable $variable the value of "Var" and assigning a blank value to the session variable "variable". What you need to do is the following:



<?php
session_start();
$_SESSION['variable'] = 'Var';
?>
<html>
<body>
<?php
echo $_SESSION['variable'];
echo "<a href='end.php'>Next</a>";

?>
</body>


Then, call the same thing (the echo $_SESSION... part) on the next page.

Hope this helps.

djr33
12-07-2007, 05:11 AM
$_SESSION is just like $_GET and $_POST and $_COOKIE (except that you can store values to it as well). It will do absolutely nothing to standard variables, and the aray itself will be available. Actually use $_SESSION['specificitem'] every time you want to use it, for storing, and for retrieving.

Rockonmetal
12-08-2007, 12:54 AM
Thanks a lot testingsite... That clears up and is exactly what I am trying todo! Thanks!