Pass php variable as page details in a header:location call

This is probably very simple, but it is driving me crazy!

I create the variable to be used in the header statement containing page and variable to be passed, based on a couple of PHP variables

if ($var === "A"){
  $backto = "page1.php?va=".$rbooktype; 
} else if ($var === "B"){
  $backto = "page2.php?va=".$rbooktype; 
}  else {
  $backto = "page3.php?va=".$rbooktype; 

($rbooktype is declared earlier in the script)

My question is how to use the $backto variable in a header(location:…) statement?

Many thanks

The header(…) parameter is a string. You can either use a double-quoted string and put the php variable inside the string or you can concatenate the php variable onto the end of a literal string.

However, the only redirect you should have in your code is upon successful completion of post method form processing and it should be to the exact same url of the current page to cause a get request for that page. This will prevent the browser from trying to resubmit the form data should someone reload that page or navigate away from and back to that page (where you can see what the submitted form data is using the browser’s developer tools, network, payload tab.)

Sponsor our Newsletter | Privacy Policy | Terms of Service