PHP Losing session variables upon going back to previous page -


the home page on website has form 2 fields: make of car (carmake) , car model (carmodel). upon submit, takes user 2nd page displays information specific make , model user has input on homepage.

i using post-method pass variables 2nd page, start new session 2 variables:

    <?php         session_start();         $_session['carmake']=$_post['carmake'];        $_session['carmodel']=$_post['carmodel'];     ?> 

this works fine. on 2nd page, have link 3rd page uses same 2 session variables. on 3rd page, start page session function , session variables available use. no problem far.

there 2 problems experiencing point onwards:

problem 1: have button on 3rd page links 2nd page. when use button go 2rd page, 2nd page not echo session variables. however, if use browser 'back' button go 2nd page, asked "confirm resubmission" , 2nd page correctly echoes session variables.

my question 1: how can design navigation visited pages without losing session variables?

question 2: there way avoid having "confirm resubmission" (when using browser button) on visited page uses session variables?

(i newbie here , apologize in advance long post may simple question.)

question 1 solution:

change code

<?php         session_start();         $_session['carmake']=$_post['carmake'];        $_session['carmodel']=$_post['carmodel']; 

to

<?php         session_start();          if(isset($_post['carmake']))             $_session['carmake']=$_post['carmake'];         if(isset($_post['carmodel']))             $_session['carmodel']=$_post['carmodel']; 

it set session value if form submit (which submit form1), when click button, not set blank values , keep last session value remains)

question 2 solution:

<?php         session_start();          if(isset($_post['carmake']))            $_session['carmake']=$_post['carmake'];         if(isset($_post['carmodel']))            $_session['carmodel']=$_post['carmodel'];         if(isset($_post['carmake']) || isset($_post['carmodel'])){             # redirect on same page when submitting form             # not ask form submission when click on browser page             header("location: page2.php")             exit;         } 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -