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
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
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
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
Share on other sites

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.