Kryllster Posted August 26, 2008 Share Posted August 26, 2008 Im trying to do my own home grown or put together version of wamp everything is ok except I get this error now: Notice: A session had already been started - ignoring session_start() I have a couple of ideas but not sure where to check for this error ?? Link to comment https://forums.phpfreaks.com/topic/121348-solved-problems-with-sessions/ Share on other sites More sharing options...
redarrow Posted August 26, 2008 Share Posted August 26, 2008 You can use the following logic to only start a session if it has not already been started - <?php if(!isset($_SESSION)) { session_start(); } ?> Link to comment https://forums.phpfreaks.com/topic/121348-solved-problems-with-sessions/#findComment-625647 Share on other sites More sharing options...
Kryllster Posted August 26, 2008 Author Share Posted August 26, 2008 Thanks I haven't tried that yet. I had display errors set to on and then turned em off now everything is running smoothly. Will the above code work with display errors on? Just curious because if it will then Ill have to edit just about every file in my game?? Just wanna learn! Link to comment https://forums.phpfreaks.com/topic/121348-solved-problems-with-sessions/#findComment-625653 Share on other sites More sharing options...
redarrow Posted August 26, 2008 Share Posted August 26, 2008 SHOULD DO TRY IT......... Link to comment https://forums.phpfreaks.com/topic/121348-solved-problems-with-sessions/#findComment-625663 Share on other sites More sharing options...
PFMaBiSmAd Posted August 26, 2008 Share Posted August 26, 2008 Get your logic under control. You should only be putting one session_start() at the beginning of your main script. Setting display_errors off or setting the error_reporting level so that the error is not reported simply stops the last step in the error handling code (the display or reporting of the error), but your code still is generating the error. Php must still go through all the error handling code, which takes 10 to 20 times longer than if the error does not exist, every time your script generates that error. If you want your code to execute the quickest, make it error free, which will be important if this is a game script and you expect the number of players to grow. Link to comment https://forums.phpfreaks.com/topic/121348-solved-problems-with-sessions/#findComment-625874 Share on other sites More sharing options...
Kryllster Posted August 26, 2008 Author Share Posted August 26, 2008 I have a session start and register in my login script and also 3 controller files with this code at the top of each one <?php session_start(); $username = $_SESSION['username']; Then everything works fine except on the fighting scripts and this is just one example of one script! <?php session_start(); $username = $_SESSION['username']; session_start(); // start our session if(!isset($_SESSION['loot_chance_run'])) { // if $_SESSION['loot_chance_run not set, proceed and run it $_SESSION['loot_chance_run'] = true; // set the session var now // initialize outcome of fight and loot chances $outcome = mt_rand(1,100); $level_advance = 1; $gold = mt_rand(1000,4000); $diamonds = mt_rand(3,; $rubies = mt_rand(3,7); // Level Array $tolevel = array(10,30,90,180,300,500,700,900,1000,1200,1400,1600,1800,2000,2200,2400,2600,2800,3000,3200,3400,3600,4000,4200,6800); // Connect to Database include ('includes/db_config.php'); // Check for advancement requirements $sql = "SELECT * FROM $tbl_name WHERE username='$username'"; $result = mysql_query($sql); $row = mysql_fetch_array( $result ); // Assign player Var include('includes/player_config.php'); // Foreach loop to get level if(in_array($row['advance'],$tolevel)) { // Update Database $sql="UPDATE $tbl_name SET level = level + 1, onhand = onhand + 5000, diamond = diamond + 20, rubie = rubie + 20, hitpoints = hitpoints + 15, advance = advance + 1 WHERE username='$username'"; mysql_query($sql) or die (mysql_error()."<p>$sql</p>"); header("Location:mainview.php?show=congratulations"); } // Take To Fight Failure if($outcome > 65){ include('header.php'); include('dungeon1/fight_failure.php'); include('footer.php'); } else{ // Update database $sql="UPDATE $tbl_name SET onhand = onhand + $gold, diamond = diamond + $diamonds, rubie = rubie + $rubies, advance = advance + $level_advance WHERE username='$username'"; mysql_query($sql) or die (mysql_error()."<p>$sql</p>"); // Take to Fight Success include('header.php'); include('dungeon1/fight_success1.php'); include('footer.php'); } } // Check For Cheating else { // give an error message and call them a cheater echo 'Sorry, this operation cannot be completed again cheater'; } ?> I tried the suggestion above and it did not work when I set the error reporting to On. My error level is E_All. I also thought since the header file is the same all around that if I put the session there all variables would be available but that doesn't seem to be working. So I'm not sure what I'm doing wrong. Do I put the user information in the session when I start it in my login script and assign the variables there or is there something I'm missing? Thanks for the reply! Link to comment https://forums.phpfreaks.com/topic/121348-solved-problems-with-sessions/#findComment-626132 Share on other sites More sharing options...
revraz Posted August 26, 2008 Share Posted August 26, 2008 Remove your 2nd session start session_start(); $username = $_SESSION['username']; session_start(); // start our session <-------------------- Link to comment https://forums.phpfreaks.com/topic/121348-solved-problems-with-sessions/#findComment-626137 Share on other sites More sharing options...
Kryllster Posted August 26, 2008 Author Share Posted August 26, 2008 Ok I apologize to redarrow and revraz they were both right. I have made adjustments and now no errors so far in any of the scripts. I removed the second session start and kept the check to see if that session had been set and everything is working fine. My error level is E_ALL and display errors on I learned a lot once again here I thought I was doing ok but I need to work like you said on my logic!! Thanks again for your help! Link to comment https://forums.phpfreaks.com/topic/121348-solved-problems-with-sessions/#findComment-626204 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.