Jump to content


Photo

Newb Session question


  • Please log in to reply
4 replies to this topic

#1 snips

snips
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 29 April 2006 - 09:10 AM

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,
session_register("DisplayName", "Password")

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

#2 OOP

OOP
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts
  • LocationSaudi Arabia

Posted 29 April 2006 - 11:19 AM

you can use this to check if the value has been set or not

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

<?php echo'The man who makes no mistakes does not usually make anything'; ?>

#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 29 April 2006 - 11:19 AM

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
<?php $_SESSION['var'] = $var; ?>
to use it
<?php $var = $_SESSION['var'];
echo $_SESSION['var']; ?>
to test if a session variable exists
<?php if(isset($_SESSION['var'])) ?>

Ken

#4 snips

snips
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 29 April 2006 - 11:34 AM

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.

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 29 April 2006 - 12:09 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users