Jump to content

Using sessions for forum board installation


BoltZ

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

<?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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

I decided to simplify things.

 

<?php
/**
* BBoardX 1.0 BETA
* Copyright &#169; 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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.