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
2010-10-26 07:19:44
<?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';
2010-10-26 07:29:02
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
2010-10-26 07:36:05
//session_start(); when i uncomment this line than page does not load
2010-10-26 07:37:49
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
2010-10-26 07:39:52
try adding error_reporting(E_ALL | E_STRICT); on the first line and lets see where is the problem
mistrfu
2010-10-26 07:41:50
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
2010-10-26 07:42:42
I did.But when i click on the link (that has reference to the above page) it just hangs and page keeps on loading...
2010-10-26 07:46:19
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
2010-10-26 07:50:05
No, whnen i remove session_start the page loads
2010-10-26 07:52:13
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
2010-10-26 07:54:41
Because of error reporting the page only shows notices for undefined variables
2010-10-26 07:56:37
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
2010-10-26 08:00:10
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;
2010-10-26 08:04:02
Hmm, so no loops anywhere?
mistrfu
2010-10-26 08:07:17
Could you possibly post your whole code here and send me the link back? http://codepad.org/0FTmW4Ty
mistrfu
2010-10-26 08:07:40
yes you can see the code above
2010-10-26 09:05:42
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
2010-10-26 10:10:33
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
2010-10-26 11:15:21
+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
2010-10-26 07:33:41