Jump to content

[SOLVED] echo the session id without erasing session data?


Recommended Posts

Im doing a form that posts to itself then stores the form data in a session and When i echo the session id below the session array it erases the array or leaves the previous data stored in it set.

 

 

<?php
session_name("wtf");
session_start(); 

$error="0";
$step ="one";

if(isset($_SESSION['submitform']))
    unset($_SESSION['submitform']);	

if (isset ($_POST['submit'])){ ///if submit

$var1 = $_POST["var1"];
$var2 = $_POST["var2"];
$var3 = $_POST["var3"];

if (empty($var1)){$error="1";}
if (empty($var2)){$error="1";}
if (empty($var3)){$error="1";}


if($error=="0" ){
$submit_array=array($var1, $var2, $var3, 'extra');
// put the array in a session variable
$_SESSION['submitform']=$submit_array;

$step ="two"; //proceed

}else{ 
$step ="one"; //errors found
echo "errors found";
}//end check 

}//end sumbit

?>
<?php if($step=="one"){  ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<label for="var1">Var 1:</label> 
<input id="var1" name="var1" value="">
<label for="var2">Var 2:</label> 
<input id="var2" name="var2" value="">
<label for="var3">Var 3:</label> 
<input id="var3" name="var3" value="">
<input type="submit" value="submit" name="submit" class="button" />
<input value="reset" class="resetbutton" type="reset">
</form>
<?php }  ?>

<?php if($step=="two"){?>
<h2>Step 2 </h2>
  
<?php  echo session_id('main');
}  ?>

<?php print_r($_SESSION['submitform']); ?>


<a href="sessioncheck.php">Check session</a>



 

 

sessioncheck.php

 

<?php
session_name("wtf");
session_start();

print_r($_SESSION['submitform']); 
?>

 

 

 

 

 

 

 

 

 

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.