-1

我知道我可以像这样传递一个常量参数:

header('位置:page.php?parameter=9999');

但是我怎么能用变量来做呢?像这样:

header('位置:page.php?parameter=$variable'); ???

4

3 回答 3

2

That is correct or you can use session variables

<?php
sesion_start();
//set variable
$_SESSION['juanita'] = 'some value';
?>



<?php
session_start();
//get variable
$newVar = $_SESSION['juanita']; //'some value'
?>

http://www.php.net/manual/en/book.session.php

Just a note, when using variables inside strings use double quotes

header("Location: page.php?parameter=$variable");

It might be better concatenate like SeanWM answer

$variable = 9999;
header('Location: page.php?parameter=' . $variable);
于 2013-04-08T15:49:01.240 回答
1
$variable = 9999;
header('Location: page.php?parameter=' . $variable);
于 2013-04-08T15:48:22.760 回答
1

Just like you are doing, just set the variable before sending any headers:

<?php
  $variable = "Something";
  header("Location:page.php?paramter=" . $variable);
?>
于 2013-04-08T15:48:40.477 回答