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. Link to comment https://forums.phpfreaks.com/topic/208391-passing-variables-based-on-user-choice/ 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. Link to comment https://forums.phpfreaks.com/topic/208391-passing-variables-based-on-user-choice/#findComment-1089024 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. Link to comment https://forums.phpfreaks.com/topic/208391-passing-variables-based-on-user-choice/#findComment-1089155 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. Link to comment https://forums.phpfreaks.com/topic/208391-passing-variables-based-on-user-choice/#findComment-1089418 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.