BoltZ Posted October 29, 2008 Share Posted October 29, 2008 I decided to simplify things. <?php /** * BBoardX 1.0 BETA * Copyright © 2008 BBoardX, All Rights Reserved * * Website: http://www.bboardx.com * License: http://www.bboardx.com/license * */ session_start(); if(!isset($_SESSION['current_step'])) $_SESSION['current_step'] = 1; else if(isset($_SESSION['current_step']) == 1) $_SESSION['current_step'] = 2; else if(isset($_SESSION['current_step']) == 2) $_SESSION['current_step'] = 3; else if(isset($_SESSION['current_step']) == 3) $_SESSION['current_step'] = 4; else $_SESSION['current_step'] = 1; Header('Location: http://www.devwebsites.com/forums/install/index.php?$_SESSION[\'current_step\']'); ?> and when i click the next button i get this in my url bar. http://www.devwebsites.com/forums/install/index.php?$_SESSION[%27current_step%27] how do i fix this? i thought i was doin this right.. Link to comment https://forums.phpfreaks.com/topic/130649-passing-session-varaible-through-url/ Share on other sites More sharing options...
trq Posted October 29, 2008 Share Posted October 29, 2008 Why would you want to pass a session variable through the url? You can retrieve the value on the next page regardless, thats the entire point of sessions. Anyway.... variables are not interpolcated within single quotes. Header('Location: http://www.devwebsites.com/forums/install/index.php?sess=' . $_SESSION['current_step']); Link to comment https://forums.phpfreaks.com/topic/130649-passing-session-varaible-through-url/#findComment-677932 Share on other sites More sharing options...
BoltZ Posted October 29, 2008 Author Share Posted October 29, 2008 Well I posted in another thhread about this. I believe its still on the first page. anyway this is for forum installation and each time they click the next button i want to add one to the variable step which would display the next echo in the case switch. View the other thread from the start for more information about this. http://www.phpfreaks.com/forums/index.php/topic,223393.0.html Link to comment https://forums.phpfreaks.com/topic/130649-passing-session-varaible-through-url/#findComment-677940 Share on other sites More sharing options...
trq Posted October 30, 2008 Share Posted October 30, 2008 Do you understand what sessions are? Link to comment https://forums.phpfreaks.com/topic/130649-passing-session-varaible-through-url/#findComment-678359 Share on other sites More sharing options...
BoltZ Posted October 30, 2008 Author Share Posted October 30, 2008 Sort of. But I am having trouble with my code. I am trying to get it when the person clicks the button it will be like index.php?step=2 then 3 and then 4 and then all the way to 9 where i finish setup. But I don't want the user to be able to just manually type in the steps without something being set. Here is my code so far. I click on next and it goes to step 2 then it keeps going to step 2. <?php /** * BBoardX 1.0 BETA * Copyright © 2008 BBoardX, All Rights Reserved * * Website: http://www.bboardx.com * License: http://www.bboardx.com/license * */ session_start(); if(!isset($_SESSION['current_step'])) $_SESSION['current_step'] = 1; //lets check to see if step in in the url using isset. If it isnt, default step to one $step = isset($_GET['step']) ? $_GET['step'] : 1; if($step <= $_SESSION['current_step']){ switch($step){ case 1: $_SESSION['current_step'] == 2; ?> //bunch of code i edited <form action="install.php" method="post"> <div> <input type="image" src="images/next_button.gif" alt="Submit button" value="Next" name="step1" /> </div> </form> //end of code i edited <?php break; case 2: $next_page = 3; ?> <form action="install.php" method="post"> <div> <input type="image" src="images/next_button.gif" alt="Submit button" value="Next" name="step1" /></div> </form <?php break; case 3: $next_page = 4; ?> <form action="install.php" method="post"> <div><input type="image" src="images/next_button.gif" alt="Submit button" value="Next" name="step1" /></div> </form><?php break; case 4: $next_page = 5; include 'step4.php'; break; } } ?> <?php //step 1.php //your process logic, saving data etc. $errors = false; //chage this if the user does not pass your step 1 requirements if(!$errors){ //rewrite the session current step var $next_step = 2; if($_SESSION['current_step'] < $next_step) $_SESSION['current_step'] = $next_step; //your link should look like index.php?step={$next_step} } ?> A url for this is in my signature and it goes to install.php which is this <?php /** * BBoardX 1.0 BETA * Copyright © 2008 BBoardX, All Rights Reserved * * Website: http://www.bboardx.com * License: http://www.bboardx.com/license * */ session_start(); if(!isset($_SESSION['current_step'])) $_SESSION['current_step'] = 1; else if(isset($_SESSION['current_step']) == 1) $_SESSION['current_step'] = 2; else if(isset($_SESSION['current_step']) == 2) $_SESSION['current_step'] = 3; Header('Location: index.php?step=' . $_SESSION['current_step']); ?> Sorry if its alot. Feel free to edit this post to delete everything thats not necessary Link to comment https://forums.phpfreaks.com/topic/130649-passing-session-varaible-through-url/#findComment-678401 Share on other sites More sharing options...
kenrbnsn Posted October 30, 2008 Share Posted October 30, 2008 Session variables do not need to be passed through the URL. The following code does something similar to what you described: <?php session_start(); if (isset($_GET['clr']) && isset($_SESSION['step'])) unset ($_SESSION['current_step']); if (!isset($_SESSION['current_step'])) $_SESSION['current_step'] = 1; switch (true) { case ($_SESSION['current_step'] > 0 && $_SESSION['current_step'] < 10): echo '<h1>Step ' . $_SESSION['current_step'] . '</h1>'; break; default: echo 'oops ... ' . $_SESSION['current_step']; $_SESSION['current_step'] = 0; } $_SESSION['current_step']++; echo '<br><a href="?x">Go to step ' . $_SESSION['current_step'] . '</a>'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/130649-passing-session-varaible-through-url/#findComment-678423 Share on other sites More sharing options...
BoltZ Posted October 30, 2008 Author Share Posted October 30, 2008 Is this all for one file? Or is this the install.php page which is the action for the form...i am very confused Link to comment https://forums.phpfreaks.com/topic/130649-passing-session-varaible-through-url/#findComment-678436 Share on other sites More sharing options...
kenrbnsn Posted October 30, 2008 Share Posted October 30, 2008 My example is one file. You can put the form in the same file as the action. Ken Link to comment https://forums.phpfreaks.com/topic/130649-passing-session-varaible-through-url/#findComment-678441 Share on other sites More sharing options...
BoltZ Posted October 30, 2008 Author Share Posted October 30, 2008 Can you show me an example of how to do that? sorry but im not the greatest back-end developer in the world.. like do i need a form action? and do i even need the install.php file? Link to comment https://forums.phpfreaks.com/topic/130649-passing-session-varaible-through-url/#findComment-678454 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.