Forum Moderators: coopster

Message Too Old, No Replies

help with SESSIONS

         

someone

3:31 pm on Oct 19, 2004 (gmt 0)

10+ Year Member



I am working on a site and I need to make a SESSIONS to be carried from page to page throughout the site. My question is the site i am working on doesn't require login or anything so how I can register the SESSIONS as? Thank You.

kumarsena

3:57 pm on Oct 19, 2004 (gmt 0)

10+ Year Member



well setting sessions doesn't have much to do with login features, u use seesions to make login.

anyways, to pass some data from one page to another this is how u proceed.

1. set session first

<?php

/*first you start the session. in all the pages where u
want the session data to be used u need to sstart the
session with the line below */

session_start();

// Register session with a key with the value 'test'
$_SESSION['skin'] = 'test';
?>

2. get session value

/*Now when u want to use the session in another page, do as follows. on top of the page use */

session_start();

/*then save session value in varable ()dont have to,
but makes life easier. if u have several session values they are all in the $_SESSION, which is a global array, so to get ur desired session value, use the name like this

$data = $_SESSION['test'];

//then u do whatever u want to do
//like

echo $data;

hope it helps,

k

kumarsena

4:00 pm on Oct 19, 2004 (gmt 0)

10+ Year Member



let me correct myself...

well setting sessions doesn't have much to do with login features, u use seesions to make login.

well, sessions do have something to do with login, but u dont need a logon to use sessions, that was my point...

someone

4:07 pm on Oct 19, 2004 (gmt 0)

10+ Year Member



kumarsena,

thanks for your reply, but i got some questions, please bare w/me as I am kinda a php newbie.

So if my site has 10 pages, I would have to put session_start() in all 10 pages? Or do I just start the session on the first page and then get the session value for those other pages?

// Register session with a key with the value 'test'
$_SESSION['skin'] = 'test';

I don't understand what the above means, what's 'skin' for or represent?

Thank You.

kumarsena

4:54 pm on Oct 19, 2004 (gmt 0)

10+ Year Member



oh sorry, it is not meant to be 'skin' but 'test'...i cut and pasted from another script and should have changed that.

in order to to retrieve the session variable, in our case 'test', you would have to first start the session. and yes you will have to do that induvidually on each page. this way the session data will be available to that particular page.

hope this helps...

ps. dont worry, i was new once as well, besides you just found the best forum on the net :). dont take my word for it, stay and find out..

kumar

StupidScript

11:46 pm on Oct 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use session_start() on every page, because you never know where the visit will begin, and session_start() will only start a new session if one is not already in progress.