Jump to content

Archived

This topic is now archived and is closed to further replies.

snips

Newb Session question

Recommended Posts

Hi,

this is probably a very simple question. I have looked on the internet and i cannot seem to get a simple answer.

I am comming from ASP.

My question is : how do i use a registered session on another page?

I have done this on my login page, [code]session_register("DisplayName", "Password")[/code]

Now, how do i check there is something in the session on a completley different page?

In asp i would simple do

if session("username") <> "" - how can i reproduce this with the above registered sessions

Thanks for the help in advance

Share this post


Link to post
Share on other sites
you can use this to check if the value has been set or not

[code]if(isset($_SESSION['username'])){
the rest of your code....
}[/code]

Share this post


Link to post
Share on other sites
Do not use "session_register()".

In all scripts where you intend to use sessions, put "session_start()" at the beginning of each script.

When you want to store a variable in a session variable use
[code]<?php $_SESSION['var'] = $var; ?>[/code]
to use it
[code]<?php $var = $_SESSION['var'];
echo $_SESSION['var']; ?>[/code]
to test if a session variable exists
[code]<?php if(isset($_SESSION['var'])) ?>[/code]

Ken

Share this post


Link to post
Share on other sites
Hi,

Thanks for the help and suggestions.

Can i ask though, what's wrong with using session_register? The stuff i read said that most proffessionals use session_register.

Hi, you said that all scripts where intend to use sessions, need to put session.start.

Does this mean, even if i am just picking the session up i need to put session.start? Just for clarification sake.

Share this post


Link to post
Share on other sites
Please read the section on [a href=\"http://www.php.net/session\" target=\"_blank\"]sessions[/a] in the manual.

There are problems with session_register() when register_globals is disabled (as it should be).

Yes you need to use the session_start() function whenever you use sessions, reading or writing

Ken

Share this post


Link to post
Share on other sites

×

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.