Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Session error

session

  • Please log in to reply
23 replies to this topic

#1 Vswe

Vswe

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1989 posts
  • Programming Language:Java, C#, PHP, Python, JavaScript, PL/SQL, Visual Basic .NET, Lua, ActionScript

Posted 25 August 2009 - 02:15 PM

I'm trying to create a session in PHP by using:

session_start();

but then I get this error:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/vswecod/public_html/ccGame/Login.php:5) in /home/vswecod/public_html/ccGame/Login.php on line 24

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/vswecod/public_html/ccGame/Login.php:5) in /home/vswecod/public_html/ccGame/Login.php on line 24

Line 24 is this one:

session_start();


Do I have to do anything first or am I doing this completely wrong? :confused:
  • 0

#2 BlaineSch

BlaineSch

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1559 posts

Posted 25 August 2009 - 02:33 PM

Nothing can be sent before you start a session, no html, text, whitespace, nothing.

If you do and try to set headers, cookies, sessions, and any other things, you will mess up :D
  • 0

#3 Vswe

Vswe

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1989 posts
  • Programming Language:Java, C#, PHP, Python, JavaScript, PL/SQL, Visual Basic .NET, Lua, ActionScript

Posted 25 August 2009 - 02:35 PM

So where should I put it? Before the <html> tag? Like this?:

<?php
session_start();
?>
<html>
....

  • 0

#4 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 25 August 2009 - 02:39 PM

yes
  • 0

#5 Vswe

Vswe

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1989 posts
  • Programming Language:Java, C#, PHP, Python, JavaScript, PL/SQL, Visual Basic .NET, Lua, ActionScript

Posted 25 August 2009 - 02:45 PM

OK, thanks both of you :)
  • 0

#6 Vswe

Vswe

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1989 posts
  • Programming Language:Java, C#, PHP, Python, JavaScript, PL/SQL, Visual Basic .NET, Lua, ActionScript

Posted 25 August 2009 - 02:51 PM

I tried it but It didn't help :confused:
  • 0

#7 amrosama

amrosama

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 2765 posts

Posted 25 August 2009 - 03:06 PM

leaving a blank line before it will also throw a warning
make sure its in the beginning of the page before any content
  • 0
yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
www.amrosama.com | the unholy methods of javascript

#8 Vswe

Vswe

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1989 posts
  • Programming Language:Java, C#, PHP, Python, JavaScript, PL/SQL, Visual Basic .NET, Lua, ActionScript

Posted 25 August 2009 - 03:08 PM

Nothing is before it, but I just looked at the htmlcode it printed out in the browser:

<br /> 
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent by (output started at /home/vswecod/public_html/ccGame/index.php:1) in <b>/home/vswecod/public_html/ccGame/index.php</b> on line <b>2</b><br /> 
<br /> 
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/vswecod/public_html/ccGame/index.php:1) in <b>/home/vswecod/public_html/ccGame/index.php</b> on line <b>2</b><br />

A <br /> tag is at the start, could that be the problem? I don't know where it come from though.
  • 0

#9 amrosama

amrosama

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 2765 posts

Posted 25 August 2009 - 03:10 PM

yes the <br /> tag is the problem
oh wait thats outputted with the warning
try this:
if(!isset($_SESSION))session_start();
sometimes sessions are started automatically
  • 0
yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
www.amrosama.com | the unholy methods of javascript

#10 Vswe

Vswe

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1989 posts
  • Programming Language:Java, C#, PHP, Python, JavaScript, PL/SQL, Visual Basic .NET, Lua, ActionScript

Posted 25 August 2009 - 03:12 PM

But I don't know where it comes from. This is the start of my PHP page:

<?php
session_start();

I've also tried this to remove the newline:

<?php session_start();

but nothing works...
  • 0

#11 amrosama

amrosama

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 2765 posts

Posted 25 August 2009 - 03:13 PM

did you see the post above? i edited it
  • 0
yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
www.amrosama.com | the unholy methods of javascript

#12 Vswe

Vswe

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1989 posts
  • Programming Language:Java, C#, PHP, Python, JavaScript, PL/SQL, Visual Basic .NET, Lua, ActionScript

Posted 25 August 2009 - 03:14 PM

It still doesn't work. I don't see why, it's nothing before it.
  • 0





Also tagged with one or more of these keywords: session

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download