Jump to content

Passing session varaible through url


BoltZ

Recommended Posts

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
https://forums.phpfreaks.com/topic/130649-passing-session-varaible-through-url/
Share on other sites

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']);

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

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 &#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;

//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 &#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;




Header('Location: index.php?step=' . $_SESSION['current_step']);
?>

 

Sorry if its alot. Feel free to edit this post to delete everything thats not necessary

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.