Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Problems with Sessions

session

  • Please log in to reply
3 replies to this topic

#1 chili5

chili5

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3038 posts
  • Programming Language:Java, C#, PHP, JavaScript, Ruby, Transact-SQL
  • Learning:C, Java, C++, C#, PHP, JavaScript, Ruby, Transact-SQL, Assembly, Scheme, Haskell, Others

Posted 04 September 2009 - 04:44 PM

I have this page where I am loading a PHP via java script into a div when a user clicks a link. On my computer running PHP 5.3.0.
I start the session at the top of my index.php which looks like this:

<?php
  require "header.php";
  require "sidebar.php";
  require "body.php";
  require "footer.php";
  ?>
Then sidebar.php contains a bunch of javascript functions that loads a PHP page into a div with id links. Now on the code call server, I have to check in links.php which is dynamically is loaded if the session is started and if not I have to start it. However on my computer, I just start the session.

So why does this code below crash with a headers already sent method on the CC server but it runs fine on my computer?

<div id="links">
<?php
conn();
if (!isset($_GET["id"]) || $_GET["id"] == -1) {
		session_start();
	} else {
		session_start();
		
		
	}
?>
</div>

  • 0

#2 amrosama

amrosama

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 2765 posts

Posted 04 September 2009 - 04:48 PM

i think cc server auto-starts the session.
try checking if the session was already started by doing this:

if(!isset($_SESSION)) session_start();

  • 1
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

#3 chili5

chili5

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3038 posts
  • Programming Language:Java, C#, PHP, JavaScript, Ruby, Transact-SQL
  • Learning:C, Java, C++, C#, PHP, JavaScript, Ruby, Transact-SQL, Assembly, Scheme, Haskell, Others

Posted 05 September 2009 - 06:46 AM

Thanks that works wonders. :)
  • 0

#4 amrosama

amrosama

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 2765 posts

Posted 06 September 2009 - 02:50 PM

glad it helped :)
  • 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





Also tagged with one or more of these keywords: session

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