BoltZ Posted October 26, 2008 Share Posted October 26, 2008 Hello I currently have a system of using cookies to display the forms but if you go to www.devwebsites.com/forums/install/ you will see why. it sets the cookie then refreshes and it displays all fine but the problem is if that the user refreshes the page then they are royally screwed unless they know how to clear cookies, then they will have to do the entire setup again and i dont want that. instead i need help turning this stuff into sessions or rather like this. i saw on other forum software that they hvae it so that its like www.exammple.com/forum/install/index.php is step1 www.exammple.com/forum/install/index.php?step=2 is step 2 can anyone show me like an example of how to do that? this is not software it is php code you know. Please help. Link to comment https://forums.phpfreaks.com/topic/130180-using-sessions-for-forum-board-installation/ Share on other sites More sharing options...
dezkit Posted October 26, 2008 Share Posted October 26, 2008 <?php $step = $_GET["step"]; if($step == 1){ // step 1 page } elseif($step == 2){ // step 2 page } elseif($step == 3){ // step 3 page } ?> Is this what you are asking for? Link to comment https://forums.phpfreaks.com/topic/130180-using-sessions-for-forum-board-installation/#findComment-675084 Share on other sites More sharing options...
emehrkay Posted October 26, 2008 Share Posted October 26, 2008 Well, you could do $_SESSION['current_install_step'] = 2; and then check that against the $_GET super. But you'd only set the session var after everything is validated and the user is allowed access to step 2. Link to comment https://forums.phpfreaks.com/topic/130180-using-sessions-for-forum-board-installation/#findComment-675091 Share on other sites More sharing options...
dezkit Posted October 26, 2008 Share Posted October 26, 2008 Well, you could do $_SESSION['current_install_step'] = 2; and then check that against the $_GET super. But you'd only set the session var after everything is validated and the user is allowed access to step 2. My logic < Your logic Link to comment https://forums.phpfreaks.com/topic/130180-using-sessions-for-forum-board-installation/#findComment-675092 Share on other sites More sharing options...
BoltZ Posted October 26, 2008 Author Share Posted October 26, 2008 Could you show an example of that sir? Link to comment https://forums.phpfreaks.com/topic/130180-using-sessions-for-forum-board-installation/#findComment-675096 Share on other sites More sharing options...
emehrkay Posted October 26, 2008 Share Posted October 26, 2008 step=x defines which step the current install is on. Instead of outright trusting a url var, check it against what you stored in the session array (you do know how to use sessions right?). Only set that session var after step (x-1) is complete. I'm sorry if it seems like i just retyped what i did before, but I dont know how to further explain it Link to comment https://forums.phpfreaks.com/topic/130180-using-sessions-for-forum-board-installation/#findComment-675106 Share on other sites More sharing options...
BoltZ Posted October 26, 2008 Author Share Posted October 26, 2008 ok i got this in my index page <?php $step = $_GET["step"]; if($step == 1){ include('step1.php'); } elseif($step == 2){ include('step2.php'); } elseif($step == 3){ include('step3.php'); } else{ include('step1.php'); } ?> and in the step 1.php file is this for the form <form action="install.php" method="get"><div> <input type="submit" value="Next" name="step1" /></div> </form> and It gives me this link for the next step in installation http://www.devwebsites.com/forums/install/install.php?step1=Next its not showing step 2 when i click the button. it just goes to that link and a blank page. what am i donig wrong? Link to comment https://forums.phpfreaks.com/topic/130180-using-sessions-for-forum-board-installation/#findComment-675109 Share on other sites More sharing options...
dezkit Posted October 26, 2008 Share Posted October 26, 2008 nevermind Link to comment https://forums.phpfreaks.com/topic/130180-using-sessions-for-forum-board-installation/#findComment-675113 Share on other sites More sharing options...
emehrkay Posted October 26, 2008 Share Posted October 26, 2008 your logic should look more like this $step = $_GET['step']; if($step <= $_SESSION['current_step']){ swtich($step){ case 1: include 'step1.php'; break; case 2: include 'step2.php'; break; } }else{ include 'step1.php'; } Link to comment https://forums.phpfreaks.com/topic/130180-using-sessions-for-forum-board-installation/#findComment-675116 Share on other sites More sharing options...
BoltZ Posted October 26, 2008 Author Share Posted October 26, 2008 Ok I got this code showing the first page but then it doesn't show the next page when i click the next button heres the index page <?php session_start(); if($step == 0){ $step = 1; } if($step <= $_SESSION['current_step']){ switch($step){ case 1: include 'step1.php'; break; case 2: include 'step2.php'; break; } }else{ include 'step1.php'; } ?> and here is my install.php file which is meant to find the current step tthen add 1 then redirect back to the index.php file <?php $step = $_SESSION['step']; $step++; header('Location: http://www.devwebsites.com/forums/install/index.php'); ?> Any suggestions? Link to comment https://forums.phpfreaks.com/topic/130180-using-sessions-for-forum-board-installation/#findComment-675124 Share on other sites More sharing options...
emehrkay Posted October 26, 2008 Share Posted October 26, 2008 yeah, you should start the session <?php session_start(); //define the current step if(!isset($_SESSION['current_step'])) $_SESSION['current_step'] = 1; ?> you should take out incrementing the step in that one file and take care of it in your actual step.1(etc) files once the user completes that step. //step 1 if($completed){ //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} } Link to comment https://forums.phpfreaks.com/topic/130180-using-sessions-for-forum-board-installation/#findComment-675135 Share on other sites More sharing options...
BoltZ Posted October 26, 2008 Author Share Posted October 26, 2008 Can you post the updated index file? Sorry but that was alot to read and very confusing for me. I am a beginner at php and i don't understand how to implement that. Link to comment https://forums.phpfreaks.com/topic/130180-using-sessions-for-forum-board-installation/#findComment-675139 Share on other sites More sharing options...
emehrkay Posted October 26, 2008 Share Posted October 26, 2008 <?php //index.php session_start(); //define the current step 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']){ swtich($step){ case 1: include 'step1.php'; break; case 2: include 'step2.php'; break; } }else{ include 'step1.php'; } ?> <?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} } ?> Link to comment https://forums.phpfreaks.com/topic/130180-using-sessions-for-forum-board-installation/#findComment-675145 Share on other sites More sharing options...
BoltZ Posted October 26, 2008 Author Share Posted October 26, 2008 Ok thanks but the problem now is that the action for the form is still install.php file. should i change that to index.php file as the action? //edit ok i changed it to index.php as the action and it still keeps reloadin step 1 when i click the next button. to see the demo of this yourself click the link in my sig Link to comment https://forums.phpfreaks.com/topic/130180-using-sessions-for-forum-board-installation/#findComment-675148 Share on other sites More sharing options...
BoltZ Posted October 26, 2008 Author Share Posted October 26, 2008 Oh also i noticed you said this in the file you gave me //your link should look like index.php?step={$next_step} but it says this when i click the next button in the address bar. something in your code is wrong http://www.devwebsites.com/forums/install/index.php?step1=Next Link to comment https://forums.phpfreaks.com/topic/130180-using-sessions-for-forum-board-installation/#findComment-675154 Share on other sites More sharing options...
emehrkay Posted October 26, 2008 Share Posted October 26, 2008 http://www.devwebsites.com/forums/install/index.php?step=2 gets me to step two remove the session info for now, get the links working, then add that extra security measure back Link to comment https://forums.phpfreaks.com/topic/130180-using-sessions-for-forum-board-installation/#findComment-675158 Share on other sites More sharing options...
BoltZ Posted October 26, 2008 Author Share Posted October 26, 2008 What do you mean. the problem is that its redirecting to the wrong link wehn i click the button. its not the session i think Link to comment https://forums.phpfreaks.com/topic/130180-using-sessions-for-forum-board-installation/#findComment-675159 Share on other sites More sharing options...
BoltZ Posted October 27, 2008 Author Share Posted October 27, 2008 I asked a friend at school and he says the problem is that its not going to the correct link when i click the button. the logic is right he says but i need to change the link function or array or whatever that controls the url Link to comment https://forums.phpfreaks.com/topic/130180-using-sessions-for-forum-board-installation/#findComment-675881 Share on other sites More sharing options...
emehrkay Posted October 28, 2008 Share Posted October 28, 2008 If you're using the code that I wrote with the switch statements, try defining the next page in the actual switch statment like so case 1: $next_page = 2; include 'page1.php'; break; then use the next page variable in your link, or form action if you're using a form echo 'index.php?step='. $next_page; Link to comment https://forums.phpfreaks.com/topic/130180-using-sessions-for-forum-board-installation/#findComment-676615 Share on other sites More sharing options...
BoltZ Posted October 28, 2008 Author Share Posted October 28, 2008 Ok Im using this code for index.php <?php 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: $next_page = 2; include 'step1.php'; break; case 2: $next_page = 3; include 'step2.php'; break; } }else{ include 'step1.php'; } ?> <?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} } ?> and this for theh form of my step1.php file <?php echo "<form action=\"index.php?step='. $next_page';\" method=\"get\">"; ?> and the url for when i click the button is still this http://www.devwebsites.com/forums/install/index.php?step1=Next ugh Link to comment https://forums.phpfreaks.com/topic/130180-using-sessions-for-forum-board-installation/#findComment-677022 Share on other sites More sharing options...
aeonsky Posted October 28, 2008 Share Posted October 28, 2008 Never mind, sorry... Link to comment https://forums.phpfreaks.com/topic/130180-using-sessions-for-forum-board-installation/#findComment-677025 Share on other sites More sharing options...
BoltZ Posted October 29, 2008 Author Share Posted October 29, 2008 Yo people any help? Link to comment https://forums.phpfreaks.com/topic/130180-using-sessions-for-forum-board-installation/#findComment-677867 Share on other sites More sharing options...
BoltZ Posted October 29, 2008 Author 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/130180-using-sessions-for-forum-board-installation/#findComment-677925 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.