JJohnsenDK Posted December 27, 2006 Share Posted December 27, 2006 HeyIm trying to use the function session_start() but it doesnt seems to work. I get these Warnings:Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Programmer\xampp\xampp\htdocs\test\count.php:9) in C:\Programmer\xampp\xampp\htdocs\test\count.php on line 10Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Programmer\xampp\xampp\htdocs\test\count.php:9) in C:\Programmer\xampp\xampp\htdocs\test\count.php on line 10Du har besøgt denne side 1 gange.Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0I run the script at a PHP 5 server. Anyone who can tell me whats wrong? Quote Link to comment Share on other sites More sharing options...
obsidian Posted December 27, 2006 Share Posted December 27, 2006 Typically, session_start() is going to be one of the very first things on the page. You [b]cannot[/b] call that function after any header information is output by the script, whether that be actual HTML or other information. This is one of the things your errors are pointing out. Quote Link to comment Share on other sites More sharing options...
JJohnsenDK Posted December 27, 2006 Author Share Posted December 27, 2006 Allright, i got the first fixed, thanks for that obsidian, but i still have problems with the last warning:Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0Anyone who can help me out with this? Quote Link to comment Share on other sites More sharing options...
obsidian Posted December 27, 2006 Share Posted December 27, 2006 That means that there is reason to believe your script relies on the register_globals setting to be on, which is not considered good practice at all. That's why it's giving you the warning about it. Quote Link to comment Share on other sites More sharing options...
JJohnsenDK Posted December 27, 2006 Author Share Posted December 27, 2006 Okay thanks... I think i have problems with my server setup cause i cant get sessions to work propperly.I got these to script where track_prefs1.php should pass on the sessions to track_prefs2:[i]track_prefs1.php[/i][code]<?session_start();session_register("first");session_register("last");session_register("email");session_register("news_prefs");?><head><title>Velkommen</title></head><style type="text/css"> p, ul, h3 {font-family:Verdana, Arial, Helvetica, sans-serif;} .enabled {font-weight: bold; color: green;} .disabled {font-weight: bold; color: red;}</style></head><body><?function load_user_data(){ global $first, $last, $email, $news_prefs; $first = "Karen"; $last = "Hansen"; $email = "karen@hansen.dk"; $news_prefs = array( "Politik" => 0, "Familie" => 1, "Børn" => 1, "Tegneserier" => 0, );}load_user_data();?><h3>Velkommen</h3><p>Velkommen tilbage <b><?= $first ?></b></p><p>Dine indstillinger er indstillet.</p><p><a href=track_prefs2.php>Se oversigt over dine valg</a></p></body></html>[/code][i]track_prefs2.php[/i][code]<?session_start()?><html><head><title>Indstillinger</title><style type="text/css"> p, ul, h3 {font-family:Verdana, Arial, Helvetica, sans-serif;} .ja {font-weight: bold; color: green;} .nej {font-weight: bold; color: red;}</style></head><body><h3>Indstillinger</h3><p>Hej <b><?=$first?> <?=$last?></b></p><p>Email: <?=$email?></p><p>Dine valg:<ul> <? while(list($key, $value) = each($news_prefs)){ if($value){ $value = "Ja"; }else{ $value = "Nej"; } print ("<li class=$value>$key: $value</li>"); } ?> </ul></p></body></html>[/code]When i click the link i get this error insted of the array list:[i]Warning: Variable passed to each() is not an array or object in C:\Programmer\xampp\xampp\htdocs\test\track_prefs2.php on line 19[/i]Because it says that the variable isnt a array i assume that the variable from track_prefs1.php isnt passed on to track_prefs2.php or am i wrong? Quote Link to comment Share on other sites More sharing options...
bljepp69 Posted December 27, 2006 Share Posted December 27, 2006 You've made the variables in the first script 'global'. They are still only available in the first script. To make a variable part of a session, you would need to define it like this:$_SESSion['first']$_SESSION['news_prefs']etc.Session variables are, by definition, super globals so you don't need to specify global when you define them this way. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.