muze Posted July 21, 2010 Share Posted July 21, 2010 I'm trying to code the following situation, where there is a sort of choose your own adventure game for the user. I want some of the choices (designated as links into series of pages) to have variables attached to be called later (like if the "story" returns to a common page). I don't want to use a database or a form. I'm hoping I can do this with an array. I am able to successfully pass variables using $_SESSION. Here's the (bad) code I'm working on: <? $choice[one]="<p><a href='page1.php'>Do this</a></p>"; $choice[two]="<p><a href='page2.php'>Do that</a></p>"; foreach ($choice as $value) { echo $value; $_SESSION['value']=$value; //probably not necessary or useful but I need to somehow pass these values to the next page to check for them. } $_SESSION['choice']=$choice; ?> I have <? session_start(); ?> at the tops of the pages Then on page1.php I have if ($_SESSION['choice'] = "one") { echo "one;} else{ echo "two";} ?> So I'm sure it's a mess. If anyone can help, please respond. Quote Link to comment Share on other sites More sharing options...
Wolphie Posted July 21, 2010 Share Posted July 21, 2010 This isn't possible using variables alone in a PHP script. Sessions/cookies/databases etc.. are required to store information about a particular transaction so that it can be retrieved and re-used at a later date. Quote Link to comment Share on other sites More sharing options...
muze Posted July 21, 2010 Author Share Posted July 21, 2010 What's not possible? The variable is passed onto other PHP pages using a session. I just need to check for the variable (which choice chosen) in subsequent pages and I'm trying to figure out the best way to do that. Quote Link to comment Share on other sites More sharing options...
muze Posted July 22, 2010 Author Share Posted July 22, 2010 Actually I am able to accomplish what I want now with MUCH simpler code. I just set a session variable on a page and reference it later to put it very simply. Anyways it's working as I intended so I'm out. 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.