taps128 Posted May 29, 2006 Share Posted May 29, 2006 [code]<?session_start();if (!$_SESSION['hp']){$_SESSION['hp']=50;}if (!$_SESSION['ap']){$_SESSION['ap']=50;}if (!$_SESSION['cudoviste']){$_SESSION['cudoviste']=20;}if (!$_SESSION['fak']){$_SESSION['fak']=5;}$lokacija="http://majgame.awardspace.com";echo ("Trgovačka ulica");echo ("Prazna ulica. Sa svih strana zjape razbijeni izlozi. Sve što je bilo vrijedno u trgovinama već je odavno");echo ("opljačkano");echo $_SESSION['stanje'].("");$_SESSION['stanje']="";if ($_SESSION['cudoviste']>0) { echo ("Pred tobom se nalazi muškarac odjeven u staru pohabanu odjeću. Koža mu visi s tijela i jedno mu je oko ispalo."); echo ("Napadate ..."); }//napad cudovistaif (rand(1,100)<=60) { $_SESSION['hp']=$_SESSION['hp']-3; echo ("Cudoviste te pogadja za 3 hp-a. Sada imas ").$_SESSION['hp'].(" hp-a."); if ($_SESSION['hp']<=0){$mrtav="da";} }else {echo ("Cudoviste promasuje.");}echo ("Oprema : sjekira, ").$_SESSION['fak'].(" pribora za prvu pomoc").("");echo ("AP: ").$_SESSION['ap'].(" HP: ").$_SESSION['hp']; //da li je igrac mrtav. Ukida sve sessioneif ($mrtav=="da") {echo ("Mrtav si"); session_destroy();}//status//izbornik za napad ili healenjeelse{if (!$_POST['posalji']) { if($_SESSION['cudoviste']>0) { ?> <form action="<?=$_SERVER['PHP_SELF'];?>" method="POST"> <input type="hidden" value="napad" name="akcija"> <input type="submit" name="posalji" value="napad"> </form> <? } if($_SESSION['fak']>0) { ?> <form action="<?=$_SERVER['PHP_SELF'];?>" method="POST"> <input type="hidden" value="ljecenje" name="akcija"> <input type="submit" name="posalji" value="ljecenje"> </form> <? } }else { $_SESSION['ap']=$_SESSION['ap']-1; $akcija=$_POST['akcija']; if ($akcija=="napad") { if (rand(1,100)<=55) { $_SESSION['cudoviste']=$_SESSION['cudoviste']-5; $_SESSION['stanje']="Udaras cudoviste sa sjekirom za 5 stete, cudoviste ima sada ".$_SESSION['cudoviste'].(" hp-a"); if ($_SESSION['cudoviste']<=0){$_SESSION['cudoviste']=-1;} } else {$_SESSION['stanje']="Promasio si cudoviste";} } else { $_SESSION['hp']=$_SESSION['hp']+5; $_SESSION['fak']=$_SESSION['fak']-1; $_SESSION['stanje']="Ljecio si se za 5 hp-a"; if($_SESSION['fak']<=0){$_SESSION['fak']=-1;} } $_POST['posalji']=array(); header("Location: http://majgame.awardspace.com/index.php"); }}?>[/code]This is my game prototoype... and this is the error i get [code]Warning: Cannot modify header information - headers already sent by (output started at /home/www/majgame.awardspace.com/index.php:8) in /home/www/majgame.awardspace.com/index.php on line 86[/code]I looked arounf the net for solution , but nothing seems to work.. no white spaces etc...Anone has any sudggestions? Quote Link to comment https://forums.phpfreaks.com/topic/10702-solved-sessionheader-proble/ Share on other sites More sharing options...
toplay Posted May 29, 2006 Share Posted May 29, 2006 [!--quoteo(post=378063:date=May 29 2006, 06:34 AM:name=Nikola Stjelja)--][div class=\'quotetop\']QUOTE(Nikola Stjelja @ May 29 2006, 06:34 AM) [snapback]378063[/snapback][/div][div class=\'quotemain\'][!--quotec--][code]<?...echo ("Trgovačka ulica"); // <---- output done on line 8... else { $_SESSION['hp']=$_SESSION['hp']+5; $_SESSION['fak']=$_SESSION['fak']-1; $_SESSION['stanje']="Ljecio si se za 5 hp-a"; if($_SESSION['fak']<=0){$_SESSION['fak']=-1;} } $_POST['posalji']=array(); header("Location: http://majgame.awardspace.com/index.php"); //<--- line 86 }}?>[/code]This is my game prototoype...and this is the error i get[code]Warning: Cannot modify header information - headers already sent by (output started at /home/www/majgame.awardspace.com/index.php:8) in /home/www/majgame.awardspace.com/index.php on line 86[/code]I looked arounf the net for solution , but nothing seems to work.. no white spaces etc...Anone has any sudggestions?[/quote]The error is saying output is being sent on line 8, which is before the header() is executed at line 86.You can't send ANY output before commands/functions that send HTTP headers like setcookie(), session_start(), header(), and mail(). So, you need to change your logic so no output is sent before these types of functions, or use output buffering. You can put ob_start() at the top of your script (even before session_start). See:[a href=\"http://us2.php.net/manual/en/function.ob-start.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.ob-start.php[/a]FYI:Please note that the header() with location command does not redirect right there and then when it's executed. It actually redirects when your script ends or an exit/die is reached. So, to ensure no logic flow problems in your script, you should have an exit right after every header() with location to force redirection to occur immediately (if that's what you want/expect based on your code logic). Quote Link to comment https://forums.phpfreaks.com/topic/10702-solved-sessionheader-proble/#findComment-39949 Share on other sites More sharing options...
taps128 Posted May 29, 2006 Author Share Posted May 29, 2006 [!--quoteo(post=378080:date=May 29 2006, 02:53 PM:name=toplay)--][div class=\'quotetop\']QUOTE(toplay @ May 29 2006, 02:53 PM) [snapback]378080[/snapback][/div][div class=\'quotemain\'][!--quotec--]The error is saying output is being sent on line 8, which is before the header() is executed at line 86.You can't send ANY output before commands/functions that send HTTP headers like setcookie(), session_start(), header(), and mail(). So, you need to change your logic so no output is sent before these types of functions, or use output buffering. You can put ob_start() at the top of your script (even before session_start). See:[a href=\"http://us2.php.net/manual/en/function.ob-start.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.ob-start.php[/a]FYI:Please note that the header() with location command does not redirect right there and then when it's executed. It actually redirects when your script ends or an exit/die is reached. So, to ensure no logic flow problems in your script, you should have an exit right after every header() with location to force redirection to occur immediately (if that's what you want/expect based on your code logic).[/quote]Well, I used exit() at first and it didn't work. Then I used ob_start and exit toghether and it worked!! Thank you very much for your help. Quote Link to comment https://forums.phpfreaks.com/topic/10702-solved-sessionheader-proble/#findComment-39951 Share on other sites More sharing options...
toplay Posted May 29, 2006 Share Posted May 29, 2006 [!--quoteo(post=378082:date=May 29 2006, 08:00 AM:name=Nikola Stjelja)--][div class=\'quotetop\']QUOTE(Nikola Stjelja @ May 29 2006, 08:00 AM) [snapback]378082[/snapback][/div][div class=\'quotemain\'][!--quotec--]So I just write exit() after my header command?[/quote][code]<?ob_start(); // <--- Addsession_start();...$_POST['posalji']=array(); header("Location: http://majgame.awardspace.com/index.php"); exit; <--- Add }}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10702-solved-sessionheader-proble/#findComment-39953 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.