2013-04-08 173 views
-1

我知道我可以傳遞像這樣的常量參數:在url地址中傳遞php變量

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

但是我怎樣才能做到這一點與變量?像這樣:

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

+0

你能舉個例子嗎?你爲什麼要這樣做? – rodripf 2013-04-08 15:47:12

+0

請閱讀[PHP中的字符串](http://www.php.net/manual/en/language.types.string.php)。 – 2013-04-08 15:48:26

+0

使用雙引號'「' – Antony 2013-04-08 15:49:35

回答

1
$variable = 9999; 
header('Location: page.php?parameter=' . $variable); 
1

就像你正在做的,只是在發送任何頭前設置變量:

<?php 
    $variable = "Something"; 
    header("Location:page.php?paramter=" . $variable); 
?> 
2

這是正確的,或者您可以使用會話變量

<?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

請注意,在字符串中使用變量時,請使用雙引號

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

它可能會像SeanWM更好地串連回答

$variable = 9999; 
header('Location: page.php?parameter=' . $variable); 
+0

非常感謝!我的問題已用雙引號解決:) – 2013-04-08 16:26:18

+0

不要忘記標記一些答案已解決。 – chepe263 2013-04-08 16:29:05