jwmstudios Posted April 22, 2010 Share Posted April 22, 2010 Ok after a few weeks of frustration i figured out how to get my variables to go back and forth pages without using register_globals = on ok here is some test code: First create a file called testpost.php copy and paste this data: <?php session_start(); echo "<a href=\" get.php \" >Click here </a><br />"; // looking for a returned value named Joe if ($_SESSION['name'] == "Joe") { echo "Well What do you know i am".$_SESSION['name']."<br />"; // output on screen } // Well if i didn't find it, just call it mary. $_SESSION['name'] = "mary"; ?> fine then create another file in the same directory called get.php copy and paste this into it: <?php // Start Your Session each time save this file as get.php session_start(); $name = $_SESSION['name']; // this is the original variable data that you want to store echo "my name is ".$name; // output on screen $_SESSION['name'] = ""; // resetting my session variable if($_SESSION['name'] == "") { $_SESSION['name'] = "Joe"; // reassign session variable to joe } echo "<br /><a href=\"testpost.php\" >go back</a>"; ?> ok give it a test and then modify as you like, you don't have to send your variables across your web browser dudes, enjoy! Quote Link to comment Share on other sites More sharing options...
monkeytooth Posted April 22, 2010 Share Posted April 22, 2010 Firstly use unset() to unset your session. as doing $_SESSION['name'] = ""; may cause a false positive as its technically set with nothing. Or if thats the only session handle use session_destroy(). Secondly try something to the effect of $session_start(); if(!isset($_SESSION['name'])){echo "I couldnt find the sessions, setting it now"; $_SESSION['name'] = "Mary"; elseif(empty($_SESSION['name'])){ echo "I found the session, but it contained only whitespace or was blank, setting it now"; $_SESSION['name'] = "Mary"; }elseif($_SESSION['name'] == "monkeytooth"){ echo "Hi <strong>".$_SESSION['name']."</strong> I don't like you! Go away"; session_destroy(); }else{ echo "Hi <strong>".$_SESSION['name']."</strong> how are you today?"; } After the session is set you usually have to refresh your page to know it. Quote Link to comment Share on other sites More sharing options...
jwmstudios Posted April 22, 2010 Author Share Posted April 22, 2010 cool. thanks gonna try. Quote Link to comment Share on other sites More sharing options...
jwmstudios Posted April 22, 2010 Author Share Posted April 22, 2010 Ok i modified the get page using unset as suggested, it worked! <?php // Start Your Session each time save this file as get.php session_start(); $name = $_SESSION['name']; // this is the original variable data that you want to store echo "my name is ".$name; // output on screen unset($_SESSION['name']); // resetting my session variable using unset function if(!isset($_SESSION['name'])) { $_SESSION['name'] = "Joe"; // reassign session variable to joe } echo "<br /><a href=\"testpost.php\" >go back</a>"; ?> 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.