berry05 Posted November 19, 2009 Share Posted November 19, 2009 Hello, Is there a way I can start a game and stay on the same page which would be index.php by using the GET function? I wanted the player to click the start button then the page has all the users stats ...this game is only going to be by session so there will be no logging in necessary. Thank You! Quote Link to comment https://forums.phpfreaks.com/topic/182162-solved-how-to-start-a-game-but-stay-on-the-same-page-by-using-function-get/ Share on other sites More sharing options...
JonnoTheDev Posted November 19, 2009 Share Posted November 19, 2009 index.php?game=start Quote Link to comment https://forums.phpfreaks.com/topic/182162-solved-how-to-start-a-game-but-stay-on-the-same-page-by-using-function-get/#findComment-961090 Share on other sites More sharing options...
berry05 Posted November 19, 2009 Author Share Posted November 19, 2009 erghh i got something like that... BETA GAME <form action="<?=$_SERVER["PHP_SELF"]?>" method="get"> <input type="submit" value="start" name="start" /> <?php session_start(); $health = $_SESSION['health']; $gold = $_SESSION['gold']; $seeds = $_SESSION['seeds']; if ($_GET["start"]) echo $health; ?> Quote Link to comment https://forums.phpfreaks.com/topic/182162-solved-how-to-start-a-game-but-stay-on-the-same-page-by-using-function-get/#findComment-961094 Share on other sites More sharing options...
JonnoTheDev Posted November 19, 2009 Share Posted November 19, 2009 You cannot start a session after output has been commited to the screen session_start() must be at the beginning of the script. Along the lines of: <?php session_start(); if($_GET['start'] == 'start') { echo $_SESSION['health']; } else { ?> <form action="" method="get"> <input type="submit" value="start" name="start" /> </form> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/182162-solved-how-to-start-a-game-but-stay-on-the-same-page-by-using-function-get/#findComment-961098 Share on other sites More sharing options...
berry05 Posted November 19, 2009 Author Share Posted November 19, 2009 wow thanks! Quote Link to comment https://forums.phpfreaks.com/topic/182162-solved-how-to-start-a-game-but-stay-on-the-same-page-by-using-function-get/#findComment-961100 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.