/    Sign up×
Community /Pin to ProfileBookmark

start_session() problem

Hi all everytime i use the start_session(); statement i get this error:

Warning: Cannot send session cookie – headers already sent by (output started at /homes/cghe11/public_html/finalsite/php/validatelogin.php:13) in /homes/cghe11/public_html/finalsite/php/validatelogin.php on line 36

Warning: Cannot send session cache limiter – headers already sent (output started at /homes/cghe11/public_html/finalsite/php/validatelogin.php:13) in /homes/cghe11/public_html/finalsite/php/validatelogin.php on line 36

anyone know why this is happening?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@JickJun 26.2003 — Just a suggestion, but it would probably help if you posted your code from the file your getting the error from so we can see what might be causing the problem. :p
Copy linkTweet thisAlerts:
@ceanthauthorJun 26.2003 — ah i got it work but i might as well post the solution just in case anyone else gets this error.

I had

<?

session_start();

include 'db.php';

$result = mysql_query("SELECT * FROM staff ");

while ($r = mysql_fetch_array($result)) {

if ($r[1] == $uname) {

if ($r[2] == $pass) {

echo "we have a match";

}

}

else echo "error";

}

?>

and it gave me an error but then i put the session_start() at the top of the coding (as i had html coding b4 the <? ) and it worked.
Copy linkTweet thisAlerts:
@pyroJun 26.2003 — PHP sessions use HTTP headers (generally, you are using cookies) and thus must be set before any content is displayed on the page -- either echoed in PHP or written in with HTML.
×

Success!

Help @ceanth 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 5.20,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...