/    Sign up×
Community /Pin to ProfileBookmark

what is message for "Notice: A session had already been started…."

hi, I got this line on top of the main page after user login:

[QUOTE]

Notice: A session had already been started – ignoring session_start() in ….. in line 119

[/QUOTE]

the code from line 115 to 127 is:

[code=php]function checkValidUser()
{
session_start();
if (session_is_registered(‘valid_user’))
{
return true;
}
else {
unset($_SESSION);
session_destroy();
return false;
}
}[/code]

plz help

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@welshApr 14.2006 — means that somewhere else you already have session_start();
Copy linkTweet thisAlerts:
@felgallApr 14.2006 — A session_start() is only valid on line 2. It has to come before everything else on the page except the <?php at the very top.
Copy linkTweet thisAlerts:
@bokehApr 14.2006 — A session_start() is only valid on line 2. It has to come before everything else on the page except the <?php at the very top.[/QUOTE]That is just not true. Coming before all echoed output is the only restriction.
Copy linkTweet thisAlerts:
@ssffccauthorApr 14.2006 — means that somewhere else you already have session_start();[/QUOTE]

did u mean by other pages or the same page? I am new to php. thx
Copy linkTweet thisAlerts:
@bokehApr 14.2006 — session_is_registered('valid_user')[/QUOTE]Forget using that archaic function and start using the $_SESSION super global.
Copy linkTweet thisAlerts:
@ssffccauthorApr 19.2006 — is there a way to check whether the session is already started, if not then start session?

I tried the code below, didnt work plz help
[CODE]if (!session_start())
{
session_start();
}[/CODE]
Copy linkTweet thisAlerts:
@bokehApr 19.2006 — [code=php]<?php

session_id() or session_start();

?>[/code]
The above will check if a session is presently running and if not one will be started.
Copy linkTweet thisAlerts:
@ssffccauthorApr 20.2006 — thx bokeh, it solved my problem
Copy linkTweet thisAlerts:
@SheldonApr 20.2006 — [code=php]<?php

session_id() or session_start();

?>[/code]
The above will check if a session is presently running and if not one will be started.[/QUOTE]



Wow thats fancy i use this where a session maybe have been started, but not being a php god like you i guess it is the same sort of thing.
[code=php]
if(!session_id())
{
session_start();
}
//continue with page
[/code]


And Felgall, what do they teach you in aussie bucause you are always coming up with some funny theroy's.
×

Success!

Help @ssffcc spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...