2017-02-21 113 views
0

我想通过可变跨页变量传递页面

例:第1页

$x = 'name' ; 
<form action='page 2' method='get'> 
    <input type='submit' name='y' value='go' /> 
</form>` 
$y = $x ; 
echo $y ; 

我想页面,当你按下提交。它会传递变量和它的值到第2页。谢谢!

回答

1

请务必尝试使用'post'方法提交数据,因为它比'get'方法更安全。所以,我在更新的代码中使用'post'方法。

请在下面找到更新的代码:

<?php $x = "name" ; ?> 

<form action="page 2" method="post" name="form1"> 
    <input type="hidden" name="x" value="<?php echo $x; ?>" /> 
    <input type="submit" name="y" value="go" /> 
</form> 

在第2页,使用超级 '$ _ POST' 收到的价值,就像这样:

<?php $y = $_POST['x']; 
echo $y; ?> 

我希望,这可能对你有帮助。