【发布时间】:2011-03-26 03:29:56
【问题描述】:
我想使用 URL 传递一些 PHP 变量。
我尝试了以下代码:
链接.php
<html>
<body>
<?php
$a='Link1';
$b='Link2';
echo '<a href="pass.php?link=$a">Link 1</a>';
echo '<br/>';
echo '<a href="pass.php?link=$b">Link 2</a>';
?></body></html>`</pre></code>
pass.php
<pre><code>`<html>
<body>
<?php
if ($_GET['link']==$a)
{
echo "Link 1 Clicked";
} else {
echo "Link 2 Clicked";
}
?></body></html>
单击链接 Link1 和 Link2 时,我得到“链接 2 已单击”。为什么?
【问题讨论】:
-
看看pass.php页面上的url,有什么发现吗??
-
是的,变量丢失(未显示在 url 中)....修复了问题
-
你可以这样做:``` ```跨度>