snips Posted April 29, 2006 Share Posted April 29, 2006 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 doif session("username") <> "" - how can i reproduce this with the above registered sessionsThanks for the help in advance Quote Link to comment Share on other sites More sharing options...
OOP Posted April 29, 2006 Share Posted April 29, 2006 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] Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 29, 2006 Share Posted April 29, 2006 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 Quote Link to comment Share on other sites More sharing options...
snips Posted April 29, 2006 Author Share Posted April 29, 2006 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. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 29, 2006 Share Posted April 29, 2006 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 writingKen Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.