tags:

views:

58

answers:

2

I m working on site which does not allow me to initialize session i-e whenever i write session_start(); the page does not load ?????

+1  A: 

Hi, could you perhaps post a part of your code?

Also, session_start() has to be called before you send anything back to the user. Which normally means it should be on first line of your code.

<?php session_start(); ?>

Let's see what does the $_SESSION array store after we uncomment session_start() line:

<?php
error_reporting(-1);  // Will report everything, comment out when not needed
ini_set('session.use_trans_sid', false);
session_start();
var_dump($_SESSION);
mistrfu
<?php//session_start();ini_set('session.use_trans_sid', '0');// Include the random string filerequire 'rand.php';// Set the session contents$_SESSION['captcha_id'] = $str;require 'inc/config.php';require 'inc/dbcon.php';require 'ref/header.php';
Is it commented out on purpose? What will following code produce?<?phpini_set('session.use_trans_sid', false);session_start();var_dump($_SESSION);// Include the random string file require 'rand.php';// Set the session contents $_SESSION['captcha_id'] = $str;I will edit my answer so I can highlight the code.
mistrfu
//session_start(); when i uncomment this line than page does not load
The above code is for using captcha in the site but its not the issue the only problematic line is session_start();And that is on the top of the page
try adding error_reporting(E_ALL | E_STRICT); on the first line and lets see where is the problem
mistrfu
that should in theory make PHP print out errors, also you did check source html code, right? not just looked at a seemingly blank page?
mistrfu
I did.But when i click on the link (that has reference to the above page) it just hangs and page keeps on loading...
Are you sure you don't have any infinite loops in your code? Are you able to see html set back by php? If it is still loading it does mean that it is still waiting for data from server, which usually happens only when you have some really bad loops, or timers or play with huge data.
mistrfu
No, whnen i remove session_start the page loads
So when you remove it it loads, with errors at least? Are you using you session variable somewhere in your code? If you later don't check for isset($_SESSION['something']) and instead just work with it, it might not even show errors. Could you show me the part of code where you are using you $_SESSION array?
mistrfu
Because of error reporting the page only shows notices for undefined variables
Sorry I started editing my comments and it mught get confusing, could you please privide the part of your code where you are using your session variables?
mistrfu
session_start();ini_set('session.use_trans_sid', '0');// Include the random string filerequire 'rand.php';// Begin the session// Set the session contents$_SESSION['captcha_id'] = $str;
Hmm, so no loops anywhere?
mistrfu
Could you possibly post your whole code here and send me the link back? http://codepad.org/0FTmW4Ty
mistrfu
yes you can see the code above
Can you tell me what this error is ??? Warning: ini_set() [function.ini-set]: A session is active. You cannot change the session module's ini settings at this time in /home/content/g/o/t/gotbeatz/html/sign-up.php on line 3
I think this means that you started session, somewhere before this file. Is the script we are discussing here the index.php file? Or does it get imported ("required") somewhere elseč? Because in that case, the problem would be, taht you have started session somewhere else already. Also try to comment out session_start() but leave there var_dump($_SESSION); Lets see if you started session somewhere earlier.
mistrfu
+1  A: 

Maybe you need to put session_start after __autoload so that objects in $_SESSION are instantiated correctly (ie. not as stdclass.)

David Norris