Here's my code;
if(!session_id())
{
session_set_cookie_params(2592000, "/", ".domain.com", false);
session_name("VALCODE");
session_start();
} else {
echo "Testing 123";
}
What I had in mind was to see see if session_id() and thus a session was already set, if not, set start a session, if so, echo Testing 123.
What happens is that it sets a session when first loaded, however when reloaded it doesn't echo "Testing 123", so as far as I know it does nothing.
Could someone please point me in the right direction for running checks to see if there's already an active session, or comment on my code and such?
Any comments开发者_如何转开发, info or advice will be greatly appreciated!
You need to write:
session_start()
before anything. if you want to see whether ant session is set or not then you should simply write:
if(count($_SESSION)>0){}
and if you want to check for particular session then ..
if($_SESSION['session_name']!='' && isset($_SESSION['session_name'])){}
these are alternatives that you can use ...
精彩评论