Jump to content

Newb Session question


snips

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
Link to comment
https://forums.phpfreaks.com/topic/8697-newb-session-question/
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
Link to comment
https://forums.phpfreaks.com/topic/8697-newb-session-question/#findComment-31922
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.
Link to comment
https://forums.phpfreaks.com/topic/8697-newb-session-question/#findComment-31927
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
Link to comment
https://forums.phpfreaks.com/topic/8697-newb-session-question/#findComment-31931
Share on other sites

Archived

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

×
×
  • 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.