2 Variable by header

2

Code:

$notapost = $_POST['nota'];
$cnpjpost = $_POST['cnpj'];

$objCheck = new Check();
$objCheck->setemail($notapost);
$objCheck->setlocal($cnpjpost);

$controller = new Comando($conn);
$controller->ListaDados($objCheck);


header ("location: ../view/FrontTab.php?nota=".$notapost);

I am passing $notapost through the header as I pass one more variable through the header? Which would be the $cnpjpost .

I do not know what the syntax would look like.

    
asked by anonymous 17.05.2016 / 16:59

2 answers

4

The first element of a querystring must have a ? question and all other items must have a% and% commercial.

header ("location: ../view/FrontTab.php?nota=".$notapost."&cnpjpost=".$cnpjpost);

Or even with &

header(sprintf("location: ../view/FrontTab.php?nota=%s&cnpjpost=%s", $notapost, $cnpjpost));

The php has the function sprintf() that from an array generates the querystring.

$params= '?'.http_build_query(array('nota'=> $notapost, 'cnpj'=>cnpjpost));
header('location: ../view/FrontTab.php'. $params);
    
17.05.2016 / 17:03
-1

I do not advise you to pass loose variables in this way, it will be safer and more elegant you send a json:

$response = json_encode(array('success' => true, 'nota' => $notapost, 'cnpjpost' => $cnpjpost));
header ("location: ../view/FrontTab.php?response=".$response);

It looks much more elegant.

To get on the other side just do a decoder:

header('Content-Type: application/json');
echo json_encode($data);
    
16.10.2018 / 16:05