如何将变量从一个PHP页面传递到另一个没有表单的页面?

如何将变量从一个PHP页面传递到另一个没有表单的页面?

问题描述:

我想知道如何在PHP中以任何形式将变量从一页传递到另一页.

I want to know how to pass a variable from one page to another in PHP without any form.

我想实现的是这样:

  1. 用户单击链接
  2. 传递了一个包含字符串的变量.
  3. 可以在另一页上访问该变量,以便我可以使用该变量运行mysql查询.

在URL中使用get方法.如果您希望将名为"phone"的变量传递为0001112222:

use the get method in the url. If you want to pass over a variable called 'phone' as 0001112222:

<a href='whatever.php?phone=0001112222'>click</a>

然后在下一页(whatever.php)上,您可以通过以下方式访问此变量:

then on the next page (whatever.php) you can access this var via:

$_GET['phone']